Skip to content

Commit 214c16f

Browse files
authored
Merge pull request #3510 from kolyshkin/fix-mntns-userns
libct: fix mounting via wrong proc fd
2 parents 8b9452f + d370e3c commit 214c16f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

libcontainer/rootfs_linux.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ func prepareRootfs(pipe io.ReadWriter, iConfig *initConfig, mountFds []int) (err
7373
// Therefore, we can access mountFds[i] without any concerns.
7474
if mountFds != nil && mountFds[i] != -1 {
7575
mountConfig.fd = &mountFds[i]
76+
} else {
77+
mountConfig.fd = nil
7678
}
7779

7880
if err := mountToRootfs(m, mountConfig); err != nil {

tests/integration/userns.bats

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,22 @@ function teardown() {
6464
runc exec test_busybox stat /tmp/mount-1/foo.txt /tmp/mount-2/foo.txt
6565
[ "$status" -eq 0 ]
6666
}
67+
68+
# Issue fixed by https://github.com/opencontainers/runc/pull/3510.
69+
@test "userns with bind mount before a cgroupfs mount" {
70+
# This can only be reproduced on cgroup v1 (and no cgroupns) due to the
71+
# way it is mounted in such case (a bunch of of bind mounts).
72+
requires cgroups_v1
73+
74+
# Add a bind mount right before the /sys/fs/cgroup mount,
75+
# and make sure cgroupns is not enabled.
76+
update_config ' .mounts |= map(if .destination == "/sys/fs/cgroup" then ({"source": "source-accessible/dir", "destination": "/tmp/mount-1", "options": ["bind"]}, .) else . end)
77+
| .linux.namespaces -= [{"type": "cgroup"}]'
78+
79+
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
80+
[ "$status" -eq 0 ]
81+
82+
# Make sure this is real cgroupfs.
83+
runc exec test_busybox cat /sys/fs/cgroup/{pids,memory}/tasks
84+
[ "$status" -eq 0 ]
85+
}

0 commit comments

Comments
 (0)