Skip to content

Allow update-ldcache hook to work when pivot-root is not supported #1174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

elezar
Copy link
Member

@elezar elezar commented Jul 2, 2025

The changes made to run the update-ldcache hook in an isolated namespace were implemented using a pivot_root. This is, however, not supported in all use cases -- most notably in kata-containers where runc is typically invoked with the --no-pivot option.

This change attempts to detect when pivot_root is not supported and use the same move mount operation as implemented by runc in this case.

@elezar elezar self-assigned this Jul 2, 2025
@coveralls
Copy link

coveralls commented Jul 2, 2025

Pull Request Test Coverage Report for Build 16070359030

Details

  • 0 of 128 (0.0%) changed or added relevant lines in 4 files are covered.
  • 3 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.2%) to 32.903%

Changes Missing Coverage Covered Lines Changed/Added Lines %
cmd/nvidia-cdi-hook/create-soname-symlinks/soname-symlinks.go 0 2 0.0%
cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go 0 2 0.0%
internal/ldconfig/ldconfig.go 0 57 0.0%
internal/ldconfig/ldconfig_linux.go 0 67 0.0%
Files with Coverage Reduction New Missed Lines %
cmd/nvidia-cdi-hook/create-soname-symlinks/soname-symlinks.go 1 0.0%
cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go 1 0.0%
internal/ldconfig/ldconfig.go 1 0.0%
Totals Coverage Status
Change from base Build 16054869452: -0.2%
Covered Lines: 4381
Relevant Lines: 13315

💛 - Coveralls

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for containers using --no-pivot by detecting when pivot_root is unavailable and falling back to a move-mount (msMoveRoot) strategy; it also refactors argument parsing and the root mount logic.

  • Implement msMoveRoot in ldconfig_linux.go and stub it on non-Linux platforms.
  • Introduce a --no-pivot flag, noPivotRoot detection, and switch in the pivot logic.
  • Refactor mountProc to use SecureJoin and utils.MkdirAllInRoot, and streamline handler argument parsing.

Reviewed Changes

Copilot reviewed 6 out of 104 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/ldconfig/ldconfig_other.go Add msMoveRoot stub for non-Linux builds
internal/ldconfig/ldconfig_linux.go Implement msMoveRoot, add mount masking, chroot helper, and noPivotRoot logic; refactor mountProc
internal/ldconfig/ldconfig.go Add --no-pivot flag in runner, new NewFromArgs constructor, and use l.directories fields
go.mod Add dependencies: github.com/moby/sys/mountinfo, github.com/prometheus/procfs
cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go Replace manual args unpacking with NewFromArgs and simplified call
cmd/nvidia-cdi-hook/create-soname-symlinks/soname-symlinks.go Replace manual args unpacking with NewFromArgs and simplified call
Comments suppressed due to low confidence (3)

internal/ldconfig/ldconfig_linux.go:104

  • [nitpick] The doc comment for msMoveRoot is incomplete. Consider expanding it to explain what the function does (e.g. "msMoveRoot moves the root filesystem in place when pivot_root isn't available").
// msMoveRoot is used

internal/ldconfig/ldconfig_linux.go:255

  • [nitpick] The new noPivotRoot detection logic and msMoveRoot fallback are not covered by tests. Consider adding unit tests for different rootfs types and the fallback path to ensure behavior across environments.
	if err := utils.MkdirAllInRoot(newroot, target, 0755); err != nil {

internal/ldconfig/ldconfig_linux.go:145

  • The code references unix.Mount, unix.Unmount, and errors.Is without importing golang.org/x/sys/unix and errors. Add the missing imports to ensure compilation.
		if err := unix.Mount("", p, "", unix.MS_SLAVE|unix.MS_REC, ""); err != nil {


if err := os.MkdirAll(target, 0755); err != nil {
return fmt.Errorf("error creating directory: %w", err)
target, err := securejoin.SecureJoin(newroot, "/proc")
Copy link
Preview

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

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

Using an absolute path ("/proc") with SecureJoin will discard newroot. Use a relative subpath like "proc" to ensure the directory is created under newroot.

Suggested change
target, err := securejoin.SecureJoin(newroot, "/proc")
target, err := securejoin.SecureJoin(newroot, "proc")

Copilot uses AI. Check for mistakes.

l := &Ldconfig{
ldconfigPath: ldconfigPath,
inRoot: inRoot,
// NewFromRunnerArgs creates an Ldconfig struct from the args passed to the Cmd
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// NewFromRunnerArgs creates an Ldconfig struct from the args passed to the Cmd
// NewFromArgs creates an Ldconfig struct from the args passed to the cmd

Or edit func name

elezar added 4 commits July 4, 2025 11:13
This change updates the proc mount when updating ldconfig to
use secure join to align with the other functions.

Signed-off-by: Evan Lezar <[email protected]>
This change updates the update-ldcache logic to use an alternative to
pivot-root when this is not supported. This includes cases where the
root filesystem is in a ramfs (e.g. when running from the kata-agent).

Signed-off-by: Evan Lezar <[email protected]>
Signed-off-by: Evan Lezar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants