Skip to content

Commit ced3139

Browse files
authored
Merge pull request #4724 from saku3/fix-rootfspropagation
fix rootfs propagation mode to shared / unbindable
2 parents 17c8e80 + 04be81b commit ced3139

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

libcontainer/rootfs_linux.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@ func prepareRootfs(pipe *syncSocket, iConfig *initConfig) (err error) {
215215
return fmt.Errorf("error jailing process inside rootfs: %w", err)
216216
}
217217

218+
// Apply root mount propagation flags.
219+
// This must be done after pivot_root/chroot because the mount propagation flag is applied
220+
// to the current root ("/"), and not to the old rootfs before it becomes "/". Applying the
221+
// flag in prepareRoot would affect the host mount namespace if the container's
222+
// root mount is shared.
223+
// MS_PRIVATE is skipped as rootfsParentMountPrivate() is already called.
224+
if config.RootPropagation != 0 && config.RootPropagation&unix.MS_PRIVATE == 0 {
225+
if err := mount("", "/", "", uintptr(config.RootPropagation), ""); err != nil {
226+
return fmt.Errorf("unable to apply root propagation flags: %w", err)
227+
}
228+
}
229+
218230
if setupDev {
219231
if err := reOpenDevNull(); err != nil {
220232
return fmt.Errorf("error reopening /dev/null inside container: %w", err)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bats
2+
3+
load helpers
4+
5+
function setup() {
6+
requires root
7+
setup_debian
8+
}
9+
10+
function teardown() {
11+
teardown_bundle
12+
}
13+
14+
@test "runc run [rootfsPropagation shared]" {
15+
update_config ' .linux.rootfsPropagation = "shared" '
16+
17+
update_config ' .process.args = ["findmnt", "--noheadings", "-o", "PROPAGATION", "/"] '
18+
19+
runc run test_shared_rootfs
20+
[ "$status" -eq 0 ]
21+
[ "$output" = "shared" ]
22+
}

0 commit comments

Comments
 (0)