Linux: pin ancestor directories of deny binds against rename - #485
Open
ant-kurt wants to merge 2 commits into
Open
Linux: pin ancestor directories of deny binds against rename#485ant-kurt wants to merge 2 commits into
ant-kurt wants to merge 2 commits into
Conversation
Each denyWrite bind or read-deny file mask makes only its destination a mountpoint; the directories between it and the covering allowed write root could be renamed, carrying the bind along and leaving the path recreatable unprotected. Emit a self --bind for each such directory so rename/rmdir on it fail EBUSY, seeded from both deny binds and file masks, skipping allowed write roots, deny dests and any directory that contains a read-deny tmpfs. Pins ride the existing emission filter and tmpfs/mask re-application passes, which now compare recorded and canonical spellings, replay the read section's actual restores instead of re-deriving them, and refuse restores that would bury an earlier read-deny mount. Only ENOENT/ENOTDIR count as absence in the pin walk; an unverifiable component aborts the wrap.
computeAncestorPins is a pure, exported walk with injected probes and direct unit tests. The unverifiable-component abort now names the path and the remedy. The nested-repo behavioral test keeps the repo within the default scan depth, quotes its rename paths correctly, and a new case pins the depth rule. README documents pinned-directory behavior.
This was referenced Sep 2, 2026
Contributor
|
Rebased this onto current main with your two commits kept as-is and opened it as #514 so it can move while you're out, with three commits on top: the Linux CI failures here (root- |
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
On Linux a deny bind (or read-deny file mask) makes only its destination a mountpoint. The directories between it and the covering allowed-write root carried no mount, so a sandboxed command could rename one of them, have the bind travel with it, and recreate the path unprotected. Each such intermediate directory now gets a self
--bind, sorename/rmdir/RENAME_EXCHANGEon it failEBUSY; reads, writes and creation inside it are unchanged. Pins are seeded from both deny binds and file masks, skip allowed-write roots, deny destinations, and any directory containing a read-deny tmpfs, and go through the existing emission filter and tmpfs/mask re-application passes.Behavior changes inside the sandbox:
mv app app2fails withEBUSYfor any nested repository the mandatory scan finds, and for.git/.claudein the project root;rm -rfof a nested repository leaves an empty husk (as.git/hooksalready did).EXDEVfor callers without a copy fallback (fs.rename,os.rename);mvfalls back to copy+unlink.EACCESonlstat) fails the command with an error naming the path.Test plan
Tests under
test/sandbox/(linux-ancestor-pin*.test.ts,linux-mount-plan-record.test.ts): unit tests for the pin plan (exclusions at/below deny destinations and at/above a read-deny tmpfs, absent directories, nested write roots, ordering), bwrap arg assertions, the rename-aside bypass failing withEBUSY, ancestor-of-credential-mask pinning, errno discrimination, no pin above an implicit tmpfs, and a nested repository within scan depth whose ancestors are pinned — hostgit init, sandboxedgit add/git commitsucceed, a staging rename inside the corridor succeeds, a straddling rename failsEXDEV; a repository beyond the scan depth gets no pins. Existing suite unchanged.