Skip to content

fix(sandbox): bind each launcher mask to the object its own check inspected - #13715

Merged
iamwhatever merged 1 commit into
mainfrom
fix/launcher-mount-pinned-target-12642
Sep 29, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/launcher-mount-pinned-target-12642

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

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 -- and
again as the mount(2) target path. Two lookups of one name are two different
resolutions, 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_argv make this worse rather than better. They
run 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_leaves is the sharpest case:
it refuses a symlinked masked leaf by os.lstat, and the launcher's own guards
then 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 stow or chezmoi dotfile layout a
failed 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

  • No new platform primitive: the launcher stays Linux-only (mount, unshare,
    prctl, seccomp-BPF via ctypes) and reads the same /proc this codebase
    already uses for path recovery and the mount-source sweep.
  • Not covering the 310 masked targets no pre-spawn pass observes (~/.aws,
    ~/.gnupg, ~/.kube, ~/.docker, .config/gcloud, the 74-entry read-only
    ceiling 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.
  • Not pinning the WRITABLE_DIRS carve-out: it WIDENS access inside an
    already-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
    islink refusal already rejects a planted link. A test records that residual.
  • Not inventing a list of "legitimate recreations" to exempt from the identity
    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 an O_PATH descriptor,
classifies it with fstat on 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_PATH asks for no read permission, which
matters 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 a
descriptor 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_PATH is what makes the no-follow first look possible, and only Linux has it.
Without it, open(O_NOFOLLOW) on a link fails with ELOOP -- the kernel offers no
way 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 is
fail-closed and never runs in production: the namespace launcher is Linux-only
(unshare, mount). The tests whose subject is a tolerated link are therefore
Linux-only, and one test asserts the refusal on every other platform rather than
skipping past it.

O_DIRECTORY | O_NOFOLLOW is what "just refuse a link" reaches for first, and it
is not used: measured, it raises NotADirectoryError on a symlinked name, so that
refusal 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 mkstemp that writes it and the fork/unshare, so the identity has to come
from BEFORE all of that. _refuse_aliased_masked_leaves already lstats every
crew 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 named
lstat. The builder serialises that map as MASK_OCCUPANTS and probes nothing,
which is the property test_the_builder_does_not_stat_the_hidden_paths pins for
it. _pin_mount_path then looks its OWN target up in that map instead of taking
an expect_occupant argument from each caller, so every hiding mount reaches one
function 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 .ssh block gains
one 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_hosts outside the mask. The by-name gateway pass stays -- it is the only
one 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/mkstemp in a
host-shared tmpfs (/run/user/$UID or /dev/shm), writable by any same-UID
process. 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-follow
descriptor; the file mask uses the descriptor mkstemp already returned), and
_verify_masked_name compares the name's post-mount identity against that saved
pair. 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 stat alone would accept a link planted at the protected name and
aimed 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 only
when 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 loop
opens the name O_NOFOLLOW, compares the inode the descriptor holds against the
approved 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/edits under the admitted apps/meetings/data -- is a
hiding 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 isdir by name
remains in that block.

~/.ssh refuses the race and skips the wrong kind. Its guard is lexists, so a
name 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_path rather 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), with
kind 0 absent (a dangling link), 1 directory, 2 regular file, 3 other, and
the 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 fstat against the
recorded 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 sandbox lane: without it, aws-control-staging refused every
sandboxed 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_OCCUPANTS line, so
what CI proves is what ships.

_pin_mount_path takes one knob, require_present, and returns (fd, path).
The carried expectation is looked up inside the pin from MASK_OCCUPANTS and is
never passed in, which is the seam the design rests on; a per-call expect_occupant
or require would 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 a
second 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 ~/.ssh still boots (asserted by test), and a
~/.ssh that 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. It
lifts the mount region verbatim out of the shipped launcher, plants a name swap
at the tempfile call every loop passes through (after classify, before mount),
and records what each mount target RESOLVES to at the moment mount is 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_hosts staging. All pass with the
fix; 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_refuses swaps the
directory 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_kind and
test_the_other_loop_meeting_a_masked_directory_still_skips lift the pin out of
the builder's own output (via runpy, never exec) and assert the fourth
element 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_pin plants a
link 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_followed is
its control; a mutation trusting whatever link is present reddens the first.
test_the_unguarded_chain_really_is_exploitable is collected on every platform:
off Linux it asserts the seal loop REFUSES the dangling link (no O_PATH) and
nothing is written through it, instead of skipping.
test_the_name_check_compares_against_the_pinned_identity_not_the_stand_in_path
re-aims the stand-in path at the replacement and shows the check still refuses;
test_every_hiding_mount_verifies_its_name_reaches_the_mask asserts every site
hands 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, link
to 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) asserts
the two layouts get opposite answers and asserts the cost first: a stow-shaped
~/.ssh boots and the mask lands on the real store; O_DIRECTORY | O_NOFOLLOW
on that layout raises NotADirectoryError; a directory substituted by a link
after 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.open carrying _O_PATH).

All 39 test/test_sandbox_*.py files green on current main (2063 passed, 5
skipped), 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_IDS and PRIVATE_DIR_IDS; the
break-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 on
the stage TARGET, since every hiding mount sources from a descriptor path.
black, mypy on sandbox.py, and the comment-history gate pass locally.

Manual verification

Verified separately, unprivileged, that /proc/self/fd/<fd> reports the pinned
device 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 unshare is seccomp-denied inside an agent
sandbox, 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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@chenmingwei23
chenmingwei23 requested review from a team and hoang-phan98 September 25, 2026 06:41
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 03ee5cd19385bab83f24dc9e8173ececc3fa6931 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify the namespace/e2e lanes are green on this revision: the no-exceptions inode comparison already refused one measured ordinary recreation (aws-control-staging) mid-lane.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 03ee5cd19385bab83f24dc9e8173ececc3fa6931 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 03ee5cd

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 03ee5cd19385bab83f24dc9e8173ececc3fa6931: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 03ee5cd19385bab83f24dc9e8173ececc3fa6931 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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 — aws-control-staging already tripped it once.

What this change ships

Inventory (10 items) — 10 justified

Intent: 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.

  1. Every hiding mount now binds the object its own check inspected (O_PATH descriptor), not a re-resolved name — justified
  2. A protected name whose object changed since the gateway's pass refuses the spawn; the comparison carries no exceptions, cost table recorded in the spec — justified
  3. An established target absent at pin time refuses instead of silently skipping; nested-under-mask absences stay ordinary — justified
  4. After each hiding mount, the name must reach its stand-in or the spawn refuses — justified
  5. The ceiling seal refuses when identity changes between bind, remount, and after — justified
  6. A masked path that exists but cannot be pinned refuses instead of running visible — justified
  7. A symlinked ~/.ssh is now masked (was silently skipped with keys readable); a dangling/file link warns and skips — justified
  8. known_hosts is staged into the stand-in before mounting, never written through the masked name after — justified
  9. The gateway refuses the spawn when an established target cannot be re-statted — justified
  10. Off-Linux (no O_PATH) a link at a protected name refuses outright; residuals (write carve-out stays by-name, pin follows links Launcher mask mounts follow a symlink planted at a protected leaf, leaving the name replaceable #13802) pinned by tests — justified

Residual siblings are counted, not implied: 99 of 409 masked targets carry identities, the 310 others and the WRITABLE_DIRS carve-out are recorded in spec + pinning tests. Rewritten test pins (exists→_pin_mount_path, isdir→lexists) preserve the decisions they recorded, with evidence in the same tests. The new-refusals-on-legitimate-operations question belongs to Security Scope Review.

[FIRST-PRINCIPLES-REVIEWED] 03ee5cd

Description read

[DESCRIPTION-READ] 460bf536aa159707f197630e523455e1f8aa80fb0e6420f1fc78224df58c9e14

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed 03ee5cd19385bab83f24dc9e8173ececc3fa6931 — this comment is updated in place on each push.

Review details

Nothing 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 — _replaced = expect_occupant is not None and occupant[:3] != expect_occupant[:3] cannot tell a rename-aside from an ordinary atomic publish, so md-notebook's unattended sync loop (syncer._sync_loop → record_last_sync → _write_settings_sync → replace_with_retry) changing workspace/md-notebook/settings.json's inode between namespace_argv's os.lstat at sandbox.py:10122 and the child's SENSITIVE_FILES pin kills that in-flight spawn (chat turn, cron job or subagent) with a DIFFERENT object holds that name than the one the pass that established it saw, naming a substitution that did not happen → Fix: the remedy needs code this PR does not touch, so it cannot gate the merge — carry a per-leaf "this target's legitimate writer publishes by rename" flag alongside the occupant record for the three _MD_NOTEBOOK_STATE_LEAVES (and live_target.json) and skip only the dev/ino leg for those, or, on mismatch, re-check whether the recorded inode is still linked in the parent before refusing.

[OPUS-REVIEWED] 03ee5cd

Verdict parsed from the review's SHA-scoped output markers for commit 03ee5cd19385bab83f24dc9e8173ececc3fa6931.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 03ee5cd19385bab83f24dc9e8173ececc3fa6931: <one-sentence reason>

@chenmingwei23
chenmingwei23 force-pushed the fix/launcher-mount-pinned-target-12642 branch from 8b23a38 to a5f47f3 Compare September 25, 2026 07:25
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 25, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/launcher-mount-pinned-target-12642 branch from a5f47f3 to 21b329b Compare September 25, 2026 09:24
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 25, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/launcher-mount-pinned-target-12642 branch from 21b329b to aa45e26 Compare September 25, 2026 10:53
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 25, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 25, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 25, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/launcher-mount-pinned-target-12642 branch from 9414e98 to df48402 Compare September 25, 2026 13:05
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 25, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/launcher-mount-pinned-target-12642 branch from df48402 to 735a7e2 Compare September 25, 2026 13:56
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5) — ⏭️ skipped

Revision 03ee5cd19385bab83f24dc9e8173ececc3fa6931 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Handover: this PR is parked for a design decision, not abandoned

Six successive blocking review findings landed on this branch, all of one class: a decision in the
masking path that is keyed on a protected name rather than bound to the object behind it.
Each fix was real and each closed its site; the next site then appeared. The sixth moved from a leaf
to an ancestor, which is the evidence that the set of points needing a carried identity was never
enumerable by working outward from the previous finding.

Work stopped here deliberately. What remains is a threat-model choice, not a patch. This comment is
the artifact, so the next attempt starts from the table rather than from round one.

Head at park: a3ba80b4b1. Two commits. No further pushes.


1. Complete enumeration of the masking path

Three columns as asked: where the stand-in is staged, whether an identity is carried into the
decision, and whether that identity is the object's (st_dev, st_ino) or merely an
attribute (a name, a kind, link-ness).

1a. Target side -- the protected name being covered

All six mask sites converge on one function, _pin_mount_path (sandbox.py:6457). It performs its
own carried lookup (:6605-6606) and its own comparison (:6680), so no call site can forget to
ask.

# Mask site Line Stand-in staged Identity carried Identity is
1 private-window staging 6956 n/a (target side) yes, by the seam object (dev,ino)
2 private-dir mask 6969 n/a yes, by the seam object
3 read-only seal, bind 7010 n/a yes, by the seam object
4 read-only seal, remount 7029 n/a yes, by the seam object
5 sensitive-file mask 7113 n/a yes, by the seam object
6 key-directory mask 7186 n/a yes, by the seam object

This half converged. A mask site added tomorrow arrives covered, because the pin looks the
identity up itself; there is no keyword left to omit.

It converged with a measured boundary. A strict spawn masks 409 targets. A pre-spawn pass
already observes 99 of them without following (the crew hidden leaves, the materializers'
established targets, and the key directory). The remaining 310 are observed by nothing, so
_carried_occupant returns None for them and the comparison is skipped -- prior behaviour, not a
regression. Those 310 include the dotfile-managed credential directories (.aws, .gnupg,
.kube, .docker, .config/gcloud, .config/gh) and the whole 74-entry read-only ceiling set.

Closing the 310 by observing them in the gateway is not available: that is a filesystem probe per
target per spawn on the single event loop, which is exactly what
test_the_builder_does_not_stat_the_hidden_paths exists to forbid, at 409 probes instead of the 52
that caused the original freeze on a stalled network home.

1b. Source side -- the stand-in that gets mounted over the name

# Stand-in Created at Staged where Identity carried Identity is
7 private-window stage dir 6960 shared tmpfs no name only
8 per-directory empty dir 6976 shared tmpfs no name; re-stated by name at 6986
9 sensitive-file empty file 7118 shared tmpfs no name; re-stated by name at 7124
10 key-directory stand-in 7170 shared tmpfs no name; re-stated by name at 7194

The staging root is _tmpfs_src, a probed candidate that falls back to the system temp directory.
It is writable by the same uid the agent runs as. Each stand-in is handed to mount(2) as a
pathname, and _verify_masked_name (:6708) re-resolves that pathname with os.stat at
:6738. So the post-mount check confirms that a name reaches a name.

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

# Decision Line Stand-in staged Identity carried Identity is
11 required-mask descendant subtraction 6242-6251 n/a no lexical name prefix

This is the sixth finding, and it is a third kind of site. It is not a follow and not a stand-in: it
is a set-membership decision. A required target is dropped from the child's list when a string
prefix of it appears among the hidden directories, on the reasoning that the ancestor's own mask
will cover it. If that ancestor is not the object the pass saw, the descendant was suppressed for a
mask that never lands where it was assumed to.

The subtraction is lexical on purpose -- asking the filesystem here would re-break the no-probe
ratchet above and would answer the same question one instant too early. That is why this site cannot
simply be given an identity: for the 310 unobserved targets there is nothing recorded to require.


2. The six findings: fixed, or open

"Addressed" and "fixed" are not the same, so each row says which.

# Finding State on this branch
6395 pin follows a swapped link (first site) FIXED -- by the previous worker, before this session
6967 key-directory pin follows a swapped link FIXED -- marker cleared on the following head, confirmed
7072 required masks discard the pre-spawn occupant FIXED -- the seam moved the lookup inside the pin, so every site carries it
6721 post-mount verification trusts a replaceable stand-in name OPEN -- implemented, measured, reverted. See below
6689 same-kind replacement bypasses the carried check MECHANICALLY FIXED, POLICY ABSENT -- the comparison is now dev/ino (:6680). The exception list the finding also asks for is deliberately not written
6261 unpinned ancestor can expose a renamed protected tree OPEN -- not attempted

On 6721: the fix was written -- pin each stand-in O_PATH|O_NOFOLLOW at creation, mount
/proc/self/fd/<fd> as the source, verify against the identity captured at creation. It broke 8
tests across four suites. Three were break-arm anchors that could be re-pointed cheaply. The one
that cannot: the main suite plants its race at the tempfile call that creates each stand-in, via a
shim four tests share. Creating stand-ins relative to a held staging-root descriptor removes that
call, so those tests lose their synchronisation point entirely. That is a harness redesign, not a
re-anchor.

On 6689: the strict comparison is in place and no exceptions accompany it, because which recreations
are legitimate decides what the sandbox permits. Section 4 is the list to choose from.


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
every present and future mask site. That is a real convergence and it should be kept whatever is
decided next.

The source side is not pinnable by checking harder. A stand-in that lives at a name in a shared
directory, writable by the uid the agent runs as, can be repointed between any check and the use
that follows it. Adding a check narrows the window; it does not remove it. The fix there is
structural: one staging root held as a descriptor, every stand-in created with dir_fd= so it never
has a resolvable path of its own, mounted through /proc/self/fd/<fd>, verified against the
identity captured at creation. O_TMPFILE gives genuinely anonymous staging for the file case;
directories have no equivalent, so the held root descriptor is what removes the name for them.

The builder side is a different question again. It can only carry an identity for targets some
pass observed, and 310 of 409 are not observed by design. So conditioning the subtraction needs
either the per-target probe the ratchet forbids, or a rule that an unobserved ancestor does not get
to suppress its descendants -- which changes what gets masked, and is a decision rather than a fix.

Underneath all six sits one undecidable thing. At a single instant, "an attacker replaced the
object at this name" and "the owner recreated the object at this name" are the same observation.
dev/ino makes that observation sharp; it does not make the distinction decidable. So the strict
comparison does not remove the risk -- it converts it into an availability cost, and section 4 is
the size of that cost. Any amount of additional checking inherits the same limit, which is why
round six looks like round one.

My read: the target-side seam is worth keeping as it stands. The source side wants the structural
change, and it is a self-contained piece of work with a known harness cost. The residual after both
is the recreation policy, which no implementation choice can settle.


4. What the strict dev/ino comparison now rejects

Every row but the last is an ordinary event on a healthy host.

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 iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. ~/.ssh in strict mode. The guard changed from os.path.isdir(SSH_DIR) to os.path.lexists with require=True and S_ISDIR. A dangling ~/.ssh link, or one that points at a file, used to be skipped; now the spawn stops.
  2. 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.
  3. /proc dependency. Every mask now needs /proc/self/fd inside 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.

iamwhatever
iamwhatever previously approved these changes Sep 29, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Rebased onto main (43e5de9488) and addressed the review:

  1. ~/.ssh in strict mode — now refuses only the race (the name emptied between the lexists guard and the pin). A name still occupied by something that is not a directory (dangling link, link to a file) skips the ssh mask with a stderr warning instead of stopping the spawn. Two new tests cover both shapes; the ssh break-arm now mutates that name read-back.
  2. Symlink rule vs fix(cron): mask the apps tree from every cron child that runs model-supplied code #13273 — settled by hand in the merged SENSITIVE_DIRS loop: a mask root the producer vouched for (SENSITIVE_DIR_IDS, the apps tree) keeps fix(cron): mask the apps tree from every cron child that runs model-supplied code #13273's O_NOFOLLOW + inode compare and refuses a link, because its producer already refused one; every other root takes this PR's pin and follows a link once. Both arms hand the mount a descriptor path and share the post-mount name check, window binds, nested re-masks and stage retirement.
  3. Identity drift / /proc dependency — unchanged, fail-closed, as you read them.

All 39 test/test_sandbox_*.py files green on main (2063 passed). PR body updated to describe the merged loop and the ssh rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Every sandbox pre-spawn pass validates a name the launcher resolves again

2 participants