cherry-pick the fix from release/2.2#183
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.