Skip to content

cherry-pick the fix from release/2.2#183

Merged
ComixHe merged 1 commit into
OpenAtom-Linyaps:masterfrom
ComixHe:master
Jun 25, 2026
Merged

cherry-pick the fix from release/2.2#183
ComixHe merged 1 commit into
OpenAtom-Linyaps:masterfrom
ComixHe:master

Conversation

@ComixHe

@ComixHe ComixHe commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

In do_pivot_root, the post-pivot call
do_propagation_mount(old_root, MS_REC | MS_PRIVATE)
used old_root.current_path() (a readlink of /proc/self/fd/<old_root>) as the mount target. old_root is opened on the host root mount before pivot_root(".", "."); after the pivot that readlink resolves to "/" (i.e. the new root X), not to the old root. The recursive MS_PRIVATE therefore landed on X and its entire subtree, clobbering the propagation type that /run/media, /sys, etc. had just inherited from their host sources during do_mounts.

Root cause: pivot_root(".", ".") makes the new rootfs X the namespace root and parks the old root at the cwd. A subsequent readlink of the pre-pivot old_root fd returns "/" because the detached old root mount is reported through the new root, so the MS_REC|MS_PRIVATE recursively re-privatized X's subtree instead of the old root's.

Fix: drop the fd-based target and use the cwd literal "." — fchdir(old_root) has just set cwd to the old root, so "." unambiguously refers to it. The recursive private now only touches the old root's subtree (host-side mounts), leaving the new root
and its inherited-slave submounts untouched.

Also open new_root with O_PATH instead of O_RDONLY: fchdir accepts O_PATH descriptors since Linux 3.5 and pivot_root(".", ".") operates on the cwd, so a read-write descriptor is unnecessary.

In do_pivot_root, the post-pivot call
  do_propagation_mount(old_root, MS_REC | MS_PRIVATE)
used old_root.current_path() (a readlink of /proc/self/fd/<old_root>) as
the mount target. old_root is opened on the host root mount *before*
pivot_root(".", "."); after the pivot that readlink resolves to "/"
(i.e. the *new* root X), not to the old root. The recursive MS_PRIVATE
therefore landed on X and its entire subtree, clobbering the propagation
type that /run/media, /sys, etc. had just inherited from their host
sources during do_mounts.

Root cause: pivot_root(".", ".") makes the new rootfs X the namespace
root and parks the old root at the cwd. A subsequent readlink of the
pre-pivot old_root fd returns "/" because the detached old root mount is
reported through the new root, so the MS_REC|MS_PRIVATE recursively
re-privatized X's subtree instead of the old root's.

Fix: drop the fd-based target and use the cwd literal "." —
fchdir(old_root) has just set cwd to the old root, so "." unambiguously
refers to it. The recursive private now only touches the old root's
subtree (host-side mounts), leaving the new root
and its inherited-slave submounts untouched.

Also open new_root with O_PATH instead of O_RDONLY: fchdir accepts
O_PATH descriptors since Linux 3.5 and pivot_root(".", ".") operates on
the cwd, so a read-write descriptor is unnecessary.

Signed-off-by: Yuming He <ComixHe1895@outlook.com>
@ComixHe ComixHe changed the title fix(container): preserve submount propagation across pivot_root cherry-pick the fix from release/2.2 Jun 25, 2026
@ComixHe ComixHe merged commit df624a5 into OpenAtom-Linyaps:master Jun 25, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant