Skip to content

[release-1.39] chroot createPlatformContainer: use MS_REMOUNT #6003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}