Skip to content

fix: update all CDI hooks to fail for invalid container root paths - #2031

Closed
cdesiniotis wants to merge 1 commit into
NVIDIA:mainfrom
cdesiniotis:cdi-hooks-invalid-container-root
Closed

fix: update all CDI hooks to fail for invalid container root paths#2031
cdesiniotis wants to merge 1 commit into
NVIDIA:mainfrom
cdesiniotis:cdi-hooks-invalid-container-root

Conversation

@cdesiniotis

Copy link
Copy Markdown
Contributor

No description provided.

Signed-off-by: Christopher Desiniotis <cdesiniotis@nvidia.com>
@cdesiniotis
cdesiniotis requested a review from henry118 August 28, 2026 00:05
@cdesiniotis cdesiniotis self-assigned this Aug 28, 2026
@cdesiniotis

Copy link
Copy Markdown
Contributor Author

/cherry-pick release-1.20

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 33128543976

Coverage decreased (-0.05%) to 43.585%

Details

  • Coverage decreased (-0.05%) from the base build.
  • Patch coverage: 18 uncovered changes across 6 files (0 of 18 lines covered, 0.0%).
  • 1 coverage regression across 1 file.

Uncovered Changes

File Changed Covered %
cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go 4 0 0.0%
cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go 3 0 0.0%
cmd/nvidia-cdi-hook/cudacompat/cudacompat.go 3 0 0.0%
cmd/nvidia-cdi-hook/disable-device-node-modification/disable-device-node-modification.go 3 0 0.0%
cmd/nvidia-cdi-hook/update-application-profile/update-application-profile.go 3 0 0.0%
cmd/nvidia-cdi-hook/chmod/chmod.go 2 0 0.0%

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
cmd/nvidia-cdi-hook/chmod/chmod.go 1 0.0%

Coverage Stats

Coverage Status
Relevant Lines: 13445
Covered Lines: 5860
Line Coverage: 43.58%
Coverage Strength: 0.44 hits per line

💛 - Coveralls

@henry118 henry118 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the following?

  1. "//", "/.", "/foo/.."
  2. /container/root -> / (link)
  3. mount --bind / /container/root (bind mount)

also runc validates the rootfs too, but it does not fail on root though.
https://github.com/opencontainers/runc/blob/cb470207c6f48904e11418a8fef3c37aeb7e482e/libcontainer/configs/validate/validator.go#L55-L72

@cdesiniotis

cdesiniotis commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

What about the following?

  1. "//", "/.", "/foo/.."
  2. /container/root -> / (link)
  3. mount --bind / /container/root (bind mount)

also runc validates the rootfs too, but it does not fail on root though. https://github.com/opencontainers/runc/blob/cb470207c6f48904e11418a8fef3c37aeb7e482e/libcontainer/configs/validate/validator.go#L55-L72

Fair point. If runc does not fail on / then one could make the argument we shouldn't either. If anything, we should update

func (s *State) GetContainerRoot() (string, error) {
containerRoot, err := s.getRoot()
if err != nil {
return "", err
}
if filepath.IsAbs(containerRoot) {
return containerRoot, nil
}
return filepath.Join(s.Bundle, containerRoot), nil
}
// loadMinimalSpec loads a reduced OCI spec associated with the container state.
to check for symlinks (like runc does in https://github.com/opencontainers/runc/blob/cb470207c6f48904e11418a8fef3c37aeb7e482e/libcontainer/configs/validate/validator.go#L55-L72. WDYT?

The "" case we already handle when checking for an absolute vs relative path.

@henry118

Copy link
Copy Markdown
Member

runc performs the validation when a container is created, before invoking oci hooks.

but i am not against the extra validation either, esp if we don't want to depend on runtime's implementation details.

@henry118

Copy link
Copy Markdown
Member

If runc does not fail on / then one could make the argument we shouldn't either.

Agreed

@cdesiniotis

Copy link
Copy Markdown
Contributor Author

Closing as no longer planned. May open a follow up based on the discussion here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants