Merge pull request #5537 from kolyshkin/kir/host-mntns-prop

libct: don't change host mounts propagation
This commit is contained in:
Sebastiaan van Stijn authored and GitHub committed 2026-10-26 13:39:41 +00:00
commit ba833d9ad7
3 files changed
+41 -1

No files matched your search

+5
View File
@@ -28,6 +28,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
mount namespace, and without one, container mounts (such as `/proc`) were
mounted on top of the host ones. (#5535)
### Fixed ###
- Running a container which does not have its own mount namespace no longer
changes the propagation of host's `/` and of the parent mount of the
container rootfs (they were made private or slave). (#5537)
## [1.6.0-rc.1] - 2026-10-06
> Lo bueno, si breve, dos veces bueno.
+17 -1
View File
@@ -169,7 +169,11 @@ func setupAndMountToRootfs(pipe *syncSocket, config *configs.Config, mountConfig
// finalizeRootfs after this function to finish setting up the rootfs.
func prepareRootfs(pipe *syncSocket, iConfig *initConfig) (err error) {
config := iConfig.Config
if err := prepareRoot(config); err != nil {
prepare := prepareRoot
if !config.Namespaces.Contains(configs.NEWNS) {
prepare = prepareRootInHostMountNS
}
if err := prepare(config); err != nil {
return fmt.Errorf("error preparing rootfs: %w", err)
}
@@ -1109,6 +1113,18 @@ func prepareRoot(config *configs.Config) error {
return mount(config.Rootfs, config.Rootfs, "bind", unix.MS_BIND|unix.MS_REC, "")
}
// prepareRootInHostMountNS is like prepareRoot, but for a container that
// runs in the host mount namespace. The propagation of existing mounts
// must not be changed, as this would affect the host.
func prepareRootInHostMountNS(config *configs.Config) error {
if err := mount(config.Rootfs, config.Rootfs, "bind", unix.MS_BIND|unix.MS_REC, ""); err != nil {
return err
}
// Make the new rootfs mount a slave, so that container mounts
// do not propagate to the host (and other mount namespaces).
return mount("", config.Rootfs, "", unix.MS_SLAVE|unix.MS_REC, "")
}
func setReadonly() error {
flags := uintptr(unix.MS_BIND | unix.MS_REMOUNT | unix.MS_RDONLY)
+19
View File
@@ -17,6 +17,25 @@ function teardown() {
teardown_bundle
}
# This test goes first, since without the fix, any test which runs
# a container in the host mount namespace changes the host mounts
# propagation, so the bug would go unnoticed.
@test "runc run [host mount ns] must not change host mounts propagation" {
update_config ' .process.args = ["true"]
| .linux.namespaces -= [{"type": "mount"}]
| .linux.maskedPaths = []
| .linux.readonlyPaths = []
| .root.readonly = false'
# Check / and the mount the container bundle resides on.
before=$(findmnt -n -o TARGET,PROPAGATION / && findmnt -n -o TARGET,PROPAGATION -T "$ROOT/bundle")
run -0 runc run test_host_mntns
after=$(findmnt -n -o TARGET,PROPAGATION / && findmnt -n -o TARGET,PROPAGATION -T "$ROOT/bundle")
echo "before: $before"
echo "after: $after"
[ "$before" = "$after" ]
}
@test "runc run [host mount ns + hooks]" {
update_config ' .process.args = ["/bin/echo", "Hello World"]
| .hooks |= . + {"createRuntime": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", "touch createRuntimeHook.$$"]}]}