Skip to content

fix rootfs propagation mode to shared / unbindable #4724

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

Merged
merged 1 commit into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions libcontainer/rootfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ func prepareRootfs(pipe *syncSocket, iConfig *initConfig) (err error) {
return fmt.Errorf("error jailing process inside rootfs: %w", err)
}

// Apply root mount propagation flags.
// This must be done after pivot_root/chroot because the mount propagation flag is applied
// to the current root ("/"), and not to the old rootfs before it becomes "/". Applying the
// flag in prepareRoot would affect the host mount namespace if the container's
// root mount is shared.
// MS_PRIVATE is skipped as rootfsParentMountPrivate() is already called.
if config.RootPropagation != 0 && config.RootPropagation&unix.MS_PRIVATE == 0 {
if err := mount("", "/", "", uintptr(config.RootPropagation), ""); err != nil {
return fmt.Errorf("unable to apply root propagation flags: %w", err)
}
}

if setupDev {
if err := reOpenDevNull(); err != nil {
return fmt.Errorf("error reopening /dev/null inside container: %w", err)
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/mounts_propagation.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bats

load helpers

function setup() {
requires root
setup_debian
}

function teardown() {
teardown_bundle
}

@test "runc run [rootfsPropagation shared]" {
update_config ' .linux.rootfsPropagation = "shared" '

update_config ' .process.args = ["findmnt", "--noheadings", "-o", "PROPAGATION", "/"] '

runc run test_shared_rootfs
[ "$status" -eq 0 ]
[ "$output" = "shared" ]
}