Skip to content

Commit fe460bc

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 5868f44 commit fe460bc

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
@@ -1015,3 +1015,23 @@ _EOF
10151015
CONTAINERS_CONF=${TEST_SCRATCH_DIR}/containers.conf run_buildah run "$(cat ${TEST_SCRATCH_DIR}/cid)" hostname
10161016
expect_output "$sanitizedname"
10171017
}
1018+
1019+
@test "root fs only mounted once" {
1020+
if test `uname` != Linux ; then
1021+
skip "not meaningful except on Linux"
1022+
fi
1023+
_prefetch busybox
1024+
run_buildah from --pull=never --quiet busybox
1025+
cid="$output"
1026+
run_buildah run $cid cat /proc/self/mountinfo
1027+
echo "$output" > ${TEST_SCRATCH_DIR}/mountinfo1
1028+
echo "# mountinfo unfiltered:"
1029+
cat ${TEST_SCRATCH_DIR}/mountinfo1
1030+
grep ' / rw,' ${TEST_SCRATCH_DIR}/mountinfo1 > ${TEST_SCRATCH_DIR}/mountinfo2
1031+
echo "# mountinfo grepped:"
1032+
cat ${TEST_SCRATCH_DIR}/mountinfo2
1033+
wc -l < ${TEST_SCRATCH_DIR}/mountinfo2 > ${TEST_SCRATCH_DIR}/mountinfo3
1034+
echo "# mountinfo count:"
1035+
cat ${TEST_SCRATCH_DIR}/mountinfo3
1036+
assert $(cat ${TEST_SCRATCH_DIR}/mountinfo3) -eq 1
1037+
}

0 commit comments

Comments
 (0)