Repository navigation
mnt: mark staging tmpfs MS_UNBINDABLE before processing config mounts - #415
Merged
robertswiecki merged 1 commit intoDec 5, 2026
Merged
Conversation
matepad007
force-pushed
the
fix-staging-mount-unbindable
branch
from
December 5, 2026 03:33
f72dc12 to
c406a68
Compare
matepad007
force-pushed
the
fix-staging-mount-unbindable
branch
from
December 5, 2026 03:37
c406a68 to
2f187b7
Compare
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.
Summary
Both mount backends create a staging tmpfs at
destdir(the future jail root) with unrestricted mount propagation, and only lock its submounts down to the configured ro/nosuid/nodev/noexec flags in a later pass, after every config-supplied mount has already been attached under it.If a config mount recursively binds a host directory that is an ancestor of
destdir(e.g.-B /tmp:/tmpwhen the staging root happens to land under/tmp), that bind'scopy_tree/open_tree(AT_RECURSIVE)snapshot includesdestdir's own staging submounts as they exist at that instant, still carrying their pre-lockdown flags.remountPt's mountinfo walk does reach the cloned copy, but it applies the ancestor bind's own flags to it rather than the original mount's intended flags, so a writable ancestor bind re-flags the leaked clone writable.Because a bind mount of tmpfs shares the same superblock/dentries as the original (standard VFS behavior, not kernel-version-dependent), a write through the leaked clone lands in the same filesystem instance as the jail's own root, defeating
is_root_rw=falsewith no additional host-side permission needed in the base case.This needs a config that recursively binds a whole ancestor of the staging path — none of the project's own example configs do this; they bind narrow sibling paths instead (e.g.
/run/user/$UID/wayland-0,/tmp/.X11-unix). It is a real but non-default-config-dependent gap, not a default-exposure issue.Fix
Mark the staging tmpfs
MS_UNBINDABLEimmediately after creation, before any config mount is processed, in both backends. PerDocumentation/filesystems/sharedsubtree.rst, an unbindable mount is pruned from any later recursive bind'scopy_tree, which removes the leak at the root instead of trying to teach the remount pass to distinguish "genuinely nested under my own staging tree" from "a different bind dragged my staging tree in."The new-API backend additionally reused
destdir's own fd (via dup) as the clone source for dynamic-content (src_content) staging. Markingdestdirunbindable while that dup is still in use would breaksrc_contentmounts, which several existing test configs exercise (tests/connect.cfg,tests/socks5.cfg,tests/nstun.cfg, others). Dynamic-content staging now gets its own dedicated detached tmpfs instead, sodestdircan stay unbindable throughout without regressing that path.tmpdir(the second scratch tmpfs, used as a bind source for dynamic content in the legacy backend) is deliberately left bindable — marking it unbindable would block binding files out of it, which is a real use, not just its own mountpoint.Test
Added
tests/mount_staging_unbindable_test.c, matching the style of the existingtests/mount_source_anchor_test.c(plain C,geteuid()/unshare(CLONE_NEWNS)gated, skips when not root or no userns). It reproduces the staging setup and the ancestor-bind leak directly withmount(2): shows a marker written into the staging tmpfs is visible through a recursive ancestor bind before the fix, and not visible afterMS_UNBINDABLEis applied. Wired into the Makefile the same way as the existing test.Validation
make -j2: not run on this machine (macOS, no Linux mount API available in this environment).mount_source_anchor_test.cboth fail to even syntax-check here for the same reason (nolinux/mount.h,MS_*,CLONE_NEWNSon macOS) — confirmed this is an environment limitation, not specific to the new code.mount()/open_tree()call site in both backends againstDocumentation/filesystems/sharedsubtree.rst's unbindable-mount semantics to confirm thesrc_contentregression before writing the fix, not after.make testis not run by this repo's CI (dockerpush.ymlonly runsmake), so I was not able to confirm./tests/mount_staging_unbindable_testplus thesrc_content-exercising config 8000 s pass on a real kernel. A review/run on real Linux would be good before merge.