Commit b2e16f8
committed
fix(container): preserve submount propagation across pivot_root
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>1 parent 27f6e97 commit b2e16f8
1 file changed
Lines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1467 | 1467 | | |
1468 | 1468 | | |
1469 | 1469 | | |
1470 | | - | |
| 1470 | + | |
1471 | 1471 | | |
1472 | 1472 | | |
1473 | 1473 | | |
| |||
1492 | 1492 | | |
1493 | 1493 | | |
1494 | 1494 | | |
1495 | | - | |
1496 | | - | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
1497 | 1501 | | |
1498 | 1502 | | |
1499 | 1503 | | |
| |||
0 commit comments