Repository navigation
fix(sandbox): bind each launcher mask to the object its own check inspected - #13715
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify the namespace/e2e lanes are green on this revision: the no-exceptions inode comparison already refused one measured ordinary recreation ( [DESIGN-REVIEWED] 03ee5cd Description read[DESCRIPTION-READ] 4fe1d3f433ca38fd4b559f3b9b8b1ab0fdf8c6d6e1d2184b6486f57dff0cd9c4 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify the no-exception inode refusal cannot fire on the gateway's own atomic rewrites of observed crew leaves mid-spawn — What this change shipsInventory (10 items) — 10 justifiedIntent: FIX — a launcher hiding-mount classified one object and bound whatever the name reached later, so a race could leave a masked credential path readable; TOCTOU is an OS-level constraint and the racing writer (a sandboxed process in the writable data home) is a named boundary.
Residual siblings are counted, not implied: 99 of 409 masked targets carry identities, the 310 others and the [FIRST-PRINCIPLES-REVIEWED] 03ee5cd Description read[DESCRIPTION-READ] 460bf536aa159707f197630e523455e1f8aa80fb0e6420f1fc78224df58c9e14 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5 Review — ✅ no blocking findingsReviewed Review detailsNothing blocks — one advisory: the new unconditional inode comparison turns the gateway's own periodic republish of a masked leaf into a refused spawn. FINDING — src/kiro_crew/sandbox.py:8737 — [OPUS-REVIEWED] 03ee5cd Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
8b23a38 to
a5f47f3
Compare
a5f47f3 to
21b329b
Compare
21b329b to
aa45e26
Compare
9414e98 to
df48402
Compare
df48402 to
735a7e2
Compare
UX Review (Fable 5) — ⏭️ skippedRevision |
Handover: this PR is parked for a design decision, not abandonedSix successive blocking review findings landed on this branch, all of one class: a decision in the Work stopped here deliberately. What remains is a threat-model choice, not a patch. This comment is Head at park: 1. Complete enumeration of the masking pathThree columns as asked: where the stand-in is staged, whether an identity is carried into the 1a. Target side -- the protected name being coveredAll six mask sites converge on one function,
This half converged. A mask site added tomorrow arrives covered, because the pin looks the It converged with a measured boundary. A strict spawn masks 409 targets. A pre-spawn pass Closing the 310 by observing them in the gateway is not available: that is a filesystem probe per 1b. Source side -- the stand-in that gets mounted over the name
The staging root is This half is not pinned anywhere. Rounds one through five all hardened the target half. 1c. Builder side -- the decision that removes a target from the list
This is the sixth finding, and it is a third kind of site. It is not a follow and not a stand-in: it The subtraction is lexical on purpose -- asking the filesystem here would re-break the no-probe 2. The six findings: fixed, or open"Addressed" and "fixed" are not the same, so each row says which.
On 6721: the fix was written -- pin each stand-in On 6689: the strict comparison is in place and no exceptions accompany it, because which recreations 3. Is the masking path pinnable point by point?Partly, and the split is the useful answer. The target side is pinnable, and is now pinned. One seam, consulted by the pin itself, covers The source side is not pinnable by checking harder. A stand-in that lives at a name in a shared The builder side is a different question again. It can only carry an identity for targets some Underneath all six sits one undecidable thing. At a single instant, "an attacker replaced the My read: the target-side seam is worth keeping as it stands. The source side wants the structural 4. What the strict
|
| Change at a protected name | Ordinary cause | Now |
|---|---|---|
| real object recreated | a staging directory rebuilt while a spawn is in flight | refused |
| real object atomically rewritten | any atomic publish: os.replace renames a new file onto the destination, so the inode always changes (atomic_write.py:392, :1163) |
refused |
| symlink recreated | a dotfile manager re-linking during a restow | refused |
| symlink replaced by real object | a dotfile manager unlinking | refused |
| real object replaced by symlink | the substitution the guard exists to catch | refused, correctly |
The second row is the widest and the least obvious. The protected read-only ceiling documents are
precisely the files published that way -- security_policy.json, computer_use.json,
denied_commands.json, decisions_consent.json, agent_model_state.json -- each written by
modules outside the sandbox. An atomic publish concurrent with a spawn now refuses that spawn.
This was already measured once, not predicted: before the comparison was narrowed, a staging
directory legitimately recreated mid-flight turned a required test lane red with
cannot pin ... a different object holds that name than the one this mask was built for. Narrowing
to link-ness cleared it. The strict comparison reinstates that failure by design, and no exception
exists to spare it.
What the branch holds
The target-side class fix and its seam, the identity recorded by passes that already lstat
(zero extra syscalls for the 49 crew leaves, one named lstat for the key directory), the
serialization bug that a populated map exposed (json.dumps spells a bool true, which is not
Python, and the child died before mounting anything) with two pins against its class, the two
review items from the second reviewer, and the over-strict-recreation regression fixed and pinned.
Both residuals are disclosed in the PR body rather than implied: the 310 unobservable targets, and
the stand-in staging model with its five-site table and the measured reason it is out of scope.
An external policy source for this security surface was unreachable from the working session, so
this repository's own anchored-descent primitive was used as the standard rather than inventing
policy.
iamwhatever
left a comment
There was a problem hiding this comment.
Holding approval: minor. No confinement is weakened, but a few host shapes now stop the spawn.
Pinning each hide/seal target with O_PATH and mounting through /proc/self/fd/N closes the name-swap window, and a symlink is still followed once, so stow/chezmoi layouts keep working. The new failure paths:
~/.sshin strict mode. The guard changed fromos.path.isdir(SSH_DIR)toos.path.lexistswithrequire=TrueandS_ISDIR. A dangling~/.sshlink, or one that points at a file, used to be skipped; now the spawn stops.- Identity drift. Identities recorded in the gateway (
_mask_occupants) are re-checked in the child. If a tool atomically renames a checked leaf between the two, the spawn fails with "a DIFFERENT object holds that name". Rare, and it fails closed. /procdependency. Every mask now needs/proc/self/fdinside the launcher.
Suggested fix: keep skipping a ~/.ssh that is not a directory (log it) instead of refusing the spawn.
Note: this PR and #13273 rewrite the same launcher loops with opposite symlink rules (this one follows once, #13273 refuses). Whichever lands second needs that rule settled by hand.
|
Rebased onto main (
All 39 |
Problem / Motivation
Goal: bind every launcher hiding-mount to the exact object its own pre-spawn check inspected, so a masked credential path cannot be left readable by a name that changes between classification and mount.
Every hiding mount in the Linux namespace launcher asked its target NAME twice.
Once to classify it --
os.path.isdir,os.path.isfile,os.path.exists-- andagain as the
mount(2)target path. Two lookups of one name are two differentresolutions, so anything that changes the name in between is unchecked: the pass
judged one object and the launcher bound another. A protected name can then stay
writable while the mask attaches to a swapped referent, and the bytes the mask
exists to cover sit at a name nothing masks.
The pre-spawn passes in
namespace_argvmake this worse rather than better. Theyrun in the gateway process, well before the launcher starts, and their return
values are discarded at the call site -- so the name a pass materialised or
refused is re-derived by the script builder and then resolved again, twice,
inside the launcher child.
_refuse_aliased_masked_leavesis the sharpest case:it refuses a symlinked masked leaf by
os.lstat, and the launcher's own guardsthen follow symlinks, so its decision was not enforced at the moment of use.
The crew data home is writable by an already-running sandboxed process, so the
racing writer is ordinary rather than exotic.
A name can change its OCCUPANT and not only its referent, and resolving once is
not enough for that. A directory replaced by a symlink while the launcher runs
is masked at the link's target, while the real directory -- renamed aside -- stays
readable. The post-mount name check cannot see it: it re-resolves the same name
through the same link, so it agrees with the pin and reports success. Refusing
every link instead would charge an ordinary
stoworchezmoidotfile layout afailed spawn, so neither resolving once nor refusing links is the answer on its
own.
Why it matters
Each of these passes exists to decide which of the operator's own files their
agent can still reach. A decision made about a different object than the one that
gets mounted is not a decision. Concretely, the failure is silent in both
directions: the launcher reports success, the agent runs believing the path is
hidden, and there is no post-mount emptiness check anywhere to notice. On the
ceiling seal the same shape leaves the governance ceiling WRITABLE, which is the
file the next boot trusts to decide what the fleet may do.
Not a goal
mount,unshare,prctl, seccomp-BPF viactypes) and reads the same/procthis codebasealready uses for path recovery and the mount-source sweep.
~/.aws,~/.gnupg,~/.kube,~/.docker,.config/gcloud, the 74-entry read-onlyceiling set): requiring a carried identity there would refuse links on exactly
the directories a dotfile manager symlinks, and observing all 409 in the
gateway puts a per-target probe per spawn back on the single event loop. Such a
name keeps its previous behaviour; the module spec records that residual.
WRITABLE_DIRScarve-out: it WIDENS access inside analready-sealed subtree and degrades open by design, so a lost race there costs
a probe its writable temp dir rather than exposing a credential, and its own
islinkrefusal already rejects a planted link. A test records that residual.comparison: which recreations a sandbox permits is a threat-model decision
about the operator's own tooling, and a list invented in the launcher would
either break ordinary hosts or quietly reopen the hole.
What changed (motivation → approach → change)
Symptom: a mask lands on the wrong object, or a ceiling stays writable, with no
error. Root cause: the launcher takes its classification and its mount from two
separate resolutions of one attacker-writable name.
The second lookup is removed rather than guarded. A new launcher helper,
_pin_mount_path, resolves each target ONCE into anO_PATHdescriptor,classifies it with
fstaton that descriptor, and returns/proc/self/fd/<fd>-- a path that names the object the descriptor holds, whatever the name says by
then. Every hiding mount now takes that path, so the object bound is by
construction the object classified.
O_PATHasks for no read permission, whichmatters because several masked leaves are 0600 files the gateway cannot open for
reading.
The FIRST look does not follow, and a link is still followed once. Those are two
statements and the fix needs both. The no-follow look uses
O_PATH | O_NOFOLLOW, which does NOT refuse a link -- measured, it returns adescriptor on the link itself -- and reports the identity of whatever occupies
the name. A link that was already there matches what the gateway recorded and
passes, so a supported symlinked data home keeps working; a directory replaced by
a link does not, and refuses. Once the occupant is known, a link is followed
exactly ONCE, as the guards this replaces followed them, so the mask covers the
store the keys actually live in.
O_PATHis what makes the no-follow first look possible, and only Linux has it.Without it,
open(O_NOFOLLOW)on a link fails withELOOP-- the kernel offers noway to hold the link itself -- so on any other host the pin refuses a link at a
protected name outright and says so (
no O_PATH … requires Linux). That isfail-closed and never runs in production: the namespace launcher is Linux-only
(
unshare,mount). The tests whose subject is a tolerated link are thereforeLinux-only, and one test asserts the refusal on every other platform rather than
skipping past it.
O_DIRECTORY | O_NOFOLLOWis what "just refuse a link" reaches for first, and itis not used: measured, it raises
NotADirectoryErroron a symlinked name, so thatrefusal lands on the supported layout rather than on the planter.
The expectation is carried from the gateway, and the seam is not per-caller.
An occupant read inside the launcher and compared inside the launcher answers
about the same instant twice. The window it has to cover spans the script build,
the
mkstempthat writes it and thefork/unshare, so the identity has to comefrom BEFORE all of that.
_refuse_aliased_masked_leavesalreadylstats everycrew hidden leaf to refuse an aliased one, so it now records what it saw at no
extra syscall. The four materialisers' established targets are added beside it,
and
~/.ssh-- not a crew leaf, and masked at the strict tier -- costs one namedlstat. The builder serialises that map asMASK_OCCUPANTSand probes nothing,which is the property
test_the_builder_does_not_stat_the_hidden_pathspins forit.
_pin_mount_paththen looks its OWN target up in that map instead of takingan
expect_occupantargument from each caller, so every hiding mount reaches onefunction and a new call site is covered the day it is written -- there is no
keyword for it to forget.
The comparison is on DEVICE AND INODE, and it carries no exceptions. An inode
identifies the object; weaker attributes admit a same-kind decoy (a directory
swapped for another directory) while the real tree sits unmasked at whatever name
the writer moved it to. The comparison sits BELOW the kind check, so a loop
meeting an object of the other kind still SKIPS as the plain guards did.
The read-only ceiling seal cannot take the handle form and is branched
explicitly: it is a bind followed by a REMOUNT, and a remount can only name the
mount the bind just created, so it resolves the name once more and REQUIRES the
object it reaches to equal the object it bound (device+inode, unchanged by a
bind of a path over itself); a mismatch refuses the spawn. The
.sshblock gainsone fix of the same kind: host trust is restored into the stand-in BEFORE that
stand-in is bound, so a name swapped after the pin cannot take the copied
known_hostsoutside the mask. The by-name gateway pass stays -- it is the onlyone that can refuse a symlinked leaf and print an operator remedy; the pin makes
the MOUNT correct, it does not replace that diagnosis.
The post-mount name check compares against a pinned identity, not a path. The
stand-in each hiding mount sources from is a fresh
mkdtemp/mkstempin ahost-shared tmpfs (
/run/user/$UIDor/dev/shm), writable by any same-UIDprocess. A check that re-resolved the stand-in's path after the mount could be
made to pass by a writer that swapped the protected name and then re-aimed the
stand-in path at it: both sides reach the same unmasked object. So each site pins
the stand-in's
(dev, ino)BEFORE mounting (_stand_in_identity, a no-followdescriptor; the file mask uses the descriptor
mkstempalready returned), and_verify_masked_namecompares the name's post-mount identity against that savedpair. A bind mount presents its source's device and inode, so a correctly masked
name reads back as exactly it. The name itself is read no-follow first: a
following
statalone would accept a link planted at the protected name andaimed at the stand-in (its tmpfs prefix is enumerable), with the mask sitting
elsewhere and the name replaceable. The pin records what it saw holding each
name (
_PINNED_OCCUPANTS, launcher-local), and a link at the name passes onlywhen it is that very link -- the tolerated dotfile layout the pin followed -- and
following it reaches the stand-in.
Two kinds of mask root, one loop. The cron apps-tree mask (#13273) gives some
mask roots a producer-vouched identity (
SENSITIVE_DIR_IDS): for those the loopopens the name
O_NOFOLLOW, compares the inode the descriptor holds against theapproved one, and refuses a link or a mismatch outright, because the producer's
own validation of that name refused a link. Every other mask root takes the pin
above: resolved once, a symlink followed once, the carried occupant identity
deciding whether the object changed. Both arms hand the mount a descriptor path,
and both then run the same post-mount name check, window binds, nested re-masks
and stage retirement, so a symlinked layout is refused exactly where its producer
already refused it and nowhere else. The nested re-hide inside a window -- the
masked
apps/meetings/data/editsunder the admittedapps/meetings/data-- is ahiding mount too, and once the window is bound its name resolves into the real
host tree, so it takes the same pin, descriptor-path mount and post-mount name
check as the loop above it; a source-position test pins that no
isdirby nameremains in that block.
~/.sshrefuses the race and skips the wrong kind. Its guard islexists, so aname occupied by anything -- link or directory -- reaches the pin. When the pin
declines the name, the name itself is read back: EMPTY now means it moved since the
guard, and the spawn refuses, since a skip there would exec with private keys
readable. Still OCCUPIED by the SAME object the gateway recorded means the pin declined
it for its kind -- a dangling link, or a link to a plain file, that was already
there -- which holds no key directory to hide, so the mask is skipped with a
stderr warning rather than failing every strict spawn on such a host. Occupied by
a DIFFERENT object is a substitution and refuses, even when the new object is of
the wrong kind: a key directory replaced by a file, or by a link to one, is
refused by the wrong-kind branch of
_pin_mount_pathrather than skipped.The carried expectation names what the name REACHED, not only the entry. Each
recording site stores
(dev, ino, is_link, kind, referent_dev, referent_ino), withkind
0absent (a dangling link),1directory,2regular file,3other, andthe referent pair being the object a link pointed at when the pass looked (the
entry itself when the name is not a link). The referent pair closes the case the
entry identity cannot: a tolerated dotfile-managed link whose directory is swapped
for another directory of the same kind leaves the link's own device, inode and
kind untouched, so the pin compares the followed descriptor's
fstatagainst therecorded referent as well, and refuses the swap. The kind settles two more cases
that device and inode alone cannot. First, not every changed object of the wrong kind
is a substitution: every path is offered to both the directory loop and the file
loop, and once the directory loop has masked a directory the file loop reaches the
STAND-IN -- a different object of the wrong kind. A wrong-kind miss therefore
refuses only when the pass saw an object of THIS loop's kind at the name (measured
on the
namespace sandboxlane: without it,aws-control-stagingrefused everysandboxed spawn on its second pass). Second, a link the pass already saw dangling,
and that is still the same link, has not changed; the pin skips it instead of
refusing a stale dotfile layout on every strict spawn. A link whose referent
vanished after the pass still refuses. An expectation recorded without those
elements is emitted at three and keeps the plain kind-skip behaviour. The builder
forwards the element as recorded, and the tests that exercise the kind branches
take their expectation from the builder's own emitted
MASK_OCCUPANTSline, sowhat CI proves is what ships.
_pin_mount_pathtakes one knob,require_present, and returns(fd, path).The carried expectation is looked up inside the pin from
MASK_OCCUPANTSand isnever passed in, which is the seam the design rests on; a per-call
expect_occupantor
requirewould be a second way to state the same fact with no caller.This change composes with main's existing hard-link alias defence (#13281,
FAIL_CLOSED_FILE_MASKS): that refuses a masked credential leaf reachable via asecond hard LINK, this pins each mask to the object its no-follow check saw. They
are complementary and both are retained.
Backwards compatibility
Compatible: this hardens the existing Linux launcher's mount path without
changing any external contract, config schema, or public API. A supported
symlinked data home /
stow-shaped~/.sshstill boots (asserted by test), and a~/.sshthat is a dangling link or a link to a file still boots, with a warning(asserted by test); the only new refusals are the substitutions and races this
exists to catch, plus the already-refused aliased-leaf cases.
Tests
test/test_sandbox_mount_pinned_target.py(new) loses the race on purpose. Itlifts the mount region verbatim out of the shipped launcher, plants a name swap
at the
tempfilecall every loop passes through (after classify, before mount),and records what each mount target RESOLVES to at the moment
mountis called --so one test body discriminates between the two shapes instead of asserting a call
form. Measured red on the parent commit, each on its own assertion: file mask,
directory mask, ceiling seal, and ssh
known_hostsstaging. All pass with thefix; two carry break-arms reverting one pinned site to the name-based form.
test_a_link_whose_referent_was_swapped_for_a_same_kind_decoy_refusesswaps thedirectory behind an unchanged link and shows the pin refuses while the unswapped
control passes; a mutation dropping the referent compare reddens it.
test_the_builder_forwards_the_referent_kindandtest_the_other_loop_meeting_a_masked_directory_still_skipslift the pin out ofthe builder's own output (via
runpy, neverexec) and assert the fourthelement arrives and decides the wrong-kind case both ways; a mutation dropping
it from the builder reddens both.
test_the_name_check_refuses_a_link_planted_at_the_name_after_the_pinplants alink to the stand-in and shows the check refuses both with a non-link pin record
and with none;
test_the_name_check_passes_the_link_the_pin_itself_followedisits control; a mutation trusting whatever link is present reddens the first.
test_the_unguarded_chain_really_is_exploitableis collected on every platform:off Linux it asserts the seal loop REFUSES the dangling link (no
O_PATH) andnothing is written through it, instead of skipping.
test_the_name_check_compares_against_the_pinned_identity_not_the_stand_in_pathre-aims the stand-in path at the replacement and shows the check still refuses;
test_every_hiding_mount_verifies_its_name_reaches_the_maskasserts every sitehands the check an identity that is one of the tmpfs sources it mounted from, so a
site passing the path reddens it.
test_ssh_name_holding_no_directory_skips_with_a_warning(dangling link, linkto a file) asserts the skip and the stderr line; the ssh break-arm mutates the
name read-back into an unconditional skip and shows the vanish case then runs
with no key mask.
test/test_sandbox_launcher_symlinked_protected_name.py(new, 12 cases) assertsthe two layouts get opposite answers and asserts the cost first: a stow-shaped
~/.sshboots and the mask lands on the real store;O_DIRECTORY | O_NOFOLLOWon that layout raises
NotADirectoryError; a directory substituted by a linkafter the guard refuses; an already-a-link name does not refuse (the
discriminator is a CHANGE of occupant). Two mutation arms (drop the carried
identity; revert the first look to a following open), each hashed against the
shipped launcher, plus a control arm asserting the unmutated source refuses both
substitutions.
The class invariant is asserted over the SEAM, not a list of sites: the pin looks
its expectation up itself, that lookup precedes the comparison which precedes the
follow (asserted by source position), and no protected name is resolved outside
the seam (asserted by scanning every launcher
os.opencarrying_O_PATH).All 39
test/test_sandbox_*.pyfiles green on current main (2063 passed, 5skipped), which carries the READONLY-before-SENSITIVE seal ordering (#14324) and
the apps-tree mask with its vouched identities (#13273). The sibling harnesses
that execute the launcher's own source carry the pinned call shape: the mount
region namespace supplies
stat,SENSITIVE_DIR_IDSandPRIVATE_DIR_IDS; thebreak-arm anchors sit on the pinned sites; the ceiling-seal harnesses carry the
pinning helpers; the ordering helper identifies mounts by the object each pinned
/proc/self/fd/<n>target resolves to; and the staging-mount filter selects onthe stage TARGET, since every hiding mount sources from a descriptor path.
black,mypyonsandbox.py, and the comment-history gate pass locally.Manual verification
Verified separately, unprivileged, that
/proc/self/fd/<fd>reports the pinneddevice and inode after the name is replaced by a symlink to a decoy, while the
name itself reports the decoy -- the property the fix rests on. A real bind mount
could not be exercised here: a nested
unshareis seccomp-denied inside an agentsandbox, which is also why the mount suites use a stand-in
_libc.Screenshots / video
N/A — this diff touches no user-visible frontend surface (the Linux namespace
sandbox launcher and its tests only).
Related Issues
Fixes #12642
Pattern harvest
Rule candidate: review-prompt
Pattern: a security check classifies an attacker-writable NAME and then re-resolves
that same name at the point of use, so a swap in between makes the decision apply
to a different object than the one acted on (TOCTOU by double name resolution).
The fix class: resolve once into a descriptor and act through
/proc/self/fd/<fd>,never the name a second time.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)