mount-util/sysext: Clone sub mounts as private to preserve nested ones
When nested mounts appear under a sysext hierarchy like this: mkdir -p /opt/trigger/ mount -t tmpfs tmpfs /opt/trigger mkdir -p /opt/trigger/inner mount -t tmpfs tmpfs /opt/trigger/inner Then systemd-sysext merge will lose the inner mount because it uses a regular bind mount with propagation and then unmounts the source, unmounting all children with it which propagates (as found out in https://github.com/flatcar/Flatcar/issues/2111). To solve this, clone the sub mount with MS_PRIVATE to decouple sub mounts from the original mount. Then attach the cloned mount instead of doing regular bind mounts. For old kernels we still attach the cloned mount but we fallback to cloning without MS_PRIVATE. This change also affects mount_private_apivfs which is used for private /proc, /sys, and cgroupfs but I think it makes sense there, too, instead of only doing mount_setattr for sysext alone because, e.g., a container and the host should not be leaking mount actions into each other for these mounts.
This commit is contained in:
@@ -1863,6 +1863,57 @@ if systemctl --quiet is-active "$ext_unit"; then
|
||||
fi
|
||||
)
|
||||
|
||||
( init_trap
|
||||
: "Nested tmpfs submounts under the hierarchy survive merge/refresh/unmerge round-trip"
|
||||
fake_root=${roots_dir:+"$roots_dir/nested-submounts"}
|
||||
hierarchy=/opt
|
||||
|
||||
# Don't run the test if the inner mount won't be preserved due to an old kernel
|
||||
if ! systemd-analyze compare-versions "$(uname -r)" ge 5.12; then
|
||||
echo >&2 "Kernel too old for mount_setattr (need >= 5.12), skipping nested submount test"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
prepare_root "$fake_root" "$hierarchy"
|
||||
prepare_extension_image "$fake_root" "$hierarchy"
|
||||
prepare_hierarchy "$fake_root" "$hierarchy"
|
||||
|
||||
# Two tmpfs mounts, one nested in the hierarchy under the other. Reproduces the nested mount layout from
|
||||
# https://github.com/flatcar/Flatcar/issues/2111 and verifies that we preserve nested mounts across merge,
|
||||
# refresh, and unmerge.
|
||||
outer_mp="$fake_root$hierarchy/outer"
|
||||
inner_mp="$outer_mp/inner"
|
||||
mkdir -p "$outer_mp"
|
||||
mount -t tmpfs tmpfs "$outer_mp"
|
||||
prepend_trap "umount -l ${outer_mp@Q} 2>/dev/null || true"
|
||||
mkdir -p "$inner_mp"
|
||||
mount -t tmpfs tmpfs "$inner_mp"
|
||||
prepend_trap "umount -l ${inner_mp@Q} 2>/dev/null || true"
|
||||
touch "$outer_mp/outer-marker"
|
||||
touch "$inner_mp/inner-marker"
|
||||
|
||||
run_systemd_sysext "$fake_root" merge
|
||||
extension_verify_after_merge "$fake_root" "$hierarchy" -e -h
|
||||
mountpoint "$outer_mp"
|
||||
mountpoint "$inner_mp"
|
||||
test -f "$outer_mp/outer-marker"
|
||||
test -f "$inner_mp/inner-marker"
|
||||
|
||||
run_systemd_sysext "$fake_root" refresh --always-refresh=yes
|
||||
extension_verify_after_merge "$fake_root" "$hierarchy" -e -h
|
||||
mountpoint "$outer_mp"
|
||||
mountpoint "$inner_mp"
|
||||
test -f "$outer_mp/outer-marker"
|
||||
test -f "$inner_mp/inner-marker"
|
||||
|
||||
run_systemd_sysext "$fake_root" unmerge
|
||||
extension_verify_after_unmerge "$fake_root" "$hierarchy" -h
|
||||
mountpoint "$outer_mp"
|
||||
mountpoint "$inner_mp"
|
||||
test -f "$outer_mp/outer-marker"
|
||||
test -f "$inner_mp/inner-marker"
|
||||
)
|
||||
|
||||
} # End of run_sysext_tests
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user