Skip to content

Commit

Permalink
chroot createPlatformContainer: use MS_REMOUNT
Browse files Browse the repository at this point in the history
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 <nalin@redhat.com>
  • Loading branch information
nalind committed Feb 18, 2025
1 parent 5dc3c23 commit 12de83d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chroot/run_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func createPlatformContainer(options runUsingChrootExecSubprocOptions) error {
return fmt.Errorf("changing to host root directory: %w", err)
}
// make sure we only unmount things under this tree
if err := unix.Mount(".", ".", "bind", unix.MS_BIND|unix.MS_SLAVE|unix.MS_REC, ""); err != nil {
if err := unix.Mount(".", ".", "bind", unix.MS_REMOUNT|unix.MS_BIND|unix.MS_SLAVE|unix.MS_REC, ""); err != nil {
return fmt.Errorf("tweaking mount flags on host root directory before unmounting from mount namespace: %w", err)
}
// detach this (unnamed?) old directory
Expand Down
20 changes: 20 additions & 0 deletions tests/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -997,3 +997,23 @@ _EOF
run_buildah ? bud --pull=false --layers .
expect_output --substring -- "-c requires an argument"
}

@test "root fs only mounted once" {
if test `uname` != Linux ; then
skip "not meaningful except on Linux"
fi
_prefetch busybox
run_buildah from --pull=never --quiet busybox
cid="$output"
run_buildah run $cid cat /proc/self/mountinfo
echo "$output" > ${TEST_SCRATCH_DIR}/mountinfo1
echo "# mountinfo unfiltered:"
cat ${TEST_SCRATCH_DIR}/mountinfo1
grep ' / rw,' ${TEST_SCRATCH_DIR}/mountinfo1 > ${TEST_SCRATCH_DIR}/mountinfo2
echo "# mountinfo grepped:"
cat ${TEST_SCRATCH_DIR}/mountinfo2
wc -l < ${TEST_SCRATCH_DIR}/mountinfo2 > ${TEST_SCRATCH_DIR}/mountinfo3
echo "# mountinfo count:"
cat ${TEST_SCRATCH_DIR}/mountinfo3
assert $(cat ${TEST_SCRATCH_DIR}/mountinfo3) -eq 1
}

0 comments on commit 12de83d

Please sign in to comment.