Skip to content

Commit 4c0c3f0

Browse files
committed
chroot createPlatformContainer: use MS_REMOUNT
When setting mount propagation on the root mount before unmounting it, use MS_REBIND, since we know it's already a bind mount, and we actually want to affect the extant bind mount instead of creating another right over it. Otherwise, we might as well have not bothered. Signed-off-by: Nalin Dahyabhai <[email protected]>
1 parent c15ab10 commit 4c0c3f0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

chroot/run_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func createPlatformContainer(options runUsingChrootExecSubprocOptions) error {
263263
return fmt.Errorf("changing to host root directory: %w", err)
264264
}
265265
// make sure we only unmount things under this tree
266-
if err := unix.Mount(".", ".", "bind", unix.MS_BIND|unix.MS_SLAVE|unix.MS_REC, ""); err != nil {
266+
if err := unix.Mount(".", ".", "bind", unix.MS_REMOUNT|unix.MS_BIND|unix.MS_SLAVE|unix.MS_REC, ""); err != nil {
267267
return fmt.Errorf("tweaking mount flags on host root directory before unmounting from mount namespace: %w", err)
268268
}
269269
// detach this (unnamed?) old directory

tests/run.bats

+20
Original file line numberDiff line numberDiff line change
@@ -997,3 +997,23 @@ _EOF
997997
run_buildah ? bud --pull=false --layers .
998998
expect_output --substring -- "-c requires an argument"
999999
}
1000+
1001+
@test "root fs only mounted once" {
1002+
if test `uname` != Linux ; then
1003+
skip "not meaningful except on Linux"
1004+
fi
1005+
_prefetch busybox
1006+
run_buildah from --pull=never --quiet busybox
1007+
cid="$output"
1008+
run_buildah run $cid cat /proc/self/mountinfo
1009+
echo "$output" > ${TEST_SCRATCH_DIR}/mountinfo1
1010+
echo "# mountinfo unfiltered:"
1011+
cat ${TEST_SCRATCH_DIR}/mountinfo1
1012+
grep ' / rw,' ${TEST_SCRATCH_DIR}/mountinfo1 > ${TEST_SCRATCH_DIR}/mountinfo2
1013+
echo "# mountinfo grepped:"
1014+
cat ${TEST_SCRATCH_DIR}/mountinfo2
1015+
wc -l < ${TEST_SCRATCH_DIR}/mountinfo2 > ${TEST_SCRATCH_DIR}/mountinfo3
1016+
echo "# mountinfo count:"
1017+
cat ${TEST_SCRATCH_DIR}/mountinfo3
1018+
assert $(cat ${TEST_SCRATCH_DIR}/mountinfo3) -eq 1
1019+
}

0 commit comments

Comments
 (0)