Skip to content

executor: keep a stationary session out of a recreated cwd ghost (identity-gated anchor verdict) - #3281

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/3275-ghost-anchor-gate
Nov 10, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/3275-ghost-anchor-gate

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3275

Problem

A session whose cwd is deleted and then recreated at the same path crossed into the recreated directory (the "ghost"): the stationary session read files that exist only in the new directory, where GNU — anchored in the dead inode — reports ENOENT. The crossing sat in the #3198 anchor refresh: asked "does the cwd path resolve?", it answered by re-opening the anchor onto whatever inode the path now names, and both the spawn stamp and the in-process anchored read consumed that verdict. A session that never moved was thereby teleported at its next spawn or read.

Change

Split the two refresh intents in src/executor/external_inner.rs:

  • refresh_cwd_anchor_for is now documented and used as the ADOPT refresh: the cd funnels (via refresh_cwd_anchor) keep it, because a session that has itself moved to the path SHOULD adopt the inode the path now names.
  • New session_cwd_path_resolves: the verdict the spawn stamp (stamp_spawn_cwd) and the anchored read (read_via_cwd_anchor) now ask. While an anchor is held for the cwd value, the path resolves for the session only if it still names the anchor's very (dev, ino); a mismatch — the ghost — counts as "does not resolve", so the caller spends the anchor (fchdir / openat) and the session's children and reads keep landing in the dead inode, as GNU's do. With no anchor naming the cwd there is nothing to compare against and the verdict falls back to the plain refresh, unchanged.

No path-string equality is ever treated as identity; the only adoption path remains the session's own cd.

Pins and evidence

New stem tests/issue3275_ghost_recreated_cwd.rs (4 cells): ghost in-process read, ghost spawn child, cd-back adoption (positive), no-recreation control. Fail-first on the base tree: the two ghost cells red with the crossed values (ghost content printed rc 0; spawned ls listed the ghost's marker), positive and control green. Head: 4/4. Neighbours unchanged: issue3198 7/7, issue3201 5/5, issue2526 4/4 + 3/3. lib bilateral: head 1230 passed / 0 failed, base 1229 / 1 — the sole base red is the known issue2875 procsub load flake, green in isolation on the same base tree and green in the head run. RUSTFLAGS="-D warnings" rc=0, fmt rc=0. GNU values are the 5.3.20 oracle's (including grep's 2 for an unopenable operand in the dead inode).

What this PR deletes

  • The spawn stamp's and the anchored read's direct calls to the adopt refresh refresh_cwd_anchor_for, replaced by the identity-gated verdict (the adopt refresh itself stays, for the cd funnels).
  • The stale half of refresh_cwd_anchor_for's doc comment (it claimed the stamp was a caller); no code path is removed wholesale.

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 10, 2026 20:25
@caomengxuan666
caomengxuan666 merged commit bc049e1 into master Nov 10, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 10, 2026
…entity verdict

anchor_fd_for_dead_cwd asked refresh_cwd_anchor_for — the ADOPT
refresh owned by the cd funnels — whether the session cwd still
resolves, and cd_target_via_cwd_anchor asked a bare metadata()
check. Both predate the identity gate #3281 put on the spawn
stamp and the anchored read. In the deleted-then-recreated
(ghost) state the refresh answers true (and re-anchors onto the
ghost), and the metadata check succeeds on the ghost's spelling,
so the (b)/(c) consumers fell back to string resolution into the
recreated directory while the stamp and the read spend the
anchor.

Both gates now ask the identity question.
anchor_fd_for_dead_cwd asks session_cwd_path_resolves directly.
cd_target_via_cwd_anchor is a free function over the anchor cell
with no &self to ask, so it applies the same (dev, ino)
comparison against the anchor handle's own identity, falling
back to the plain resolvability check when that identity is
unreadable — the same fallback the identity verdict takes when
no anchor names the cwd.

Only the source of the resolvability verdict changes: the
two-state rule, the rubash#1820 FIFO probe discipline, and every
anchored walk are untouched.

Merge-order remainder of the #3268 (c) face: #3281 reached
master first (bc049e1), so the convergence the captain review
booked lands in this merge round.
caomengxuan666 added a commit that referenced this pull request Nov 10, 2026
…rom a deleted cwd (#3283)

Refs #3268

## Scope

This PR covers faces (b) and (c) of #3268 only:

- (b) the `cd` builtin's own move out of a deleted cwd (`cd ..`,
  `cd -L ..`, `cd -P ..`, `cd ../a2`, repeated `cd ..`).
- (c) shell-side redirection opens from a deleted cwd: input,
  output, append and read/write targets across the open ladders,
  the rejection gates' validation probes, the compound fd-0 bind,
  the `read` builtin's target funnel, and the text channel's
  slurp — including the composite cell `x=$(cat <../f)` that the
  (a)(d)(e) design lane assigned to this face.

Faces (a), (d) and (e) are separate lanes and are not addressed
here. The deleted-then-recreated ("ghost") shape is #3275's
scope; this PR's consumers reuse the shared anchor gate and
neither add nor remove ghost behavior, and the pin deliberately
carries no ghost cell. #2796's symlink face and #2798's pwd face
are untouched (the design lane's scope check; the one shared
evidence cell, deleted-cwd `cd ..` in #2796's list, is this
face's headline and is covered here on its own mechanism).

## Mechanism

GNU owners: `change_to_directory` (builtins/cd.def:522) —
canonicalized chdir first (`sh_canonpath`, lib/sh/pathcanon.c,
with PATH_CHECKEXISTS | PATH_CHECKDOTDOT, so the deleted
component itself fails it), then the verbatim chdir of the
operand (POSIX step 9 tail) against the process cwd inode;
`do_redirections` (redir.c:237) opens redirection targets in
the forked child (execute_cmd.c `execute_disk_command`), whose
inherited cwd is that same inode. Both resolve relative to an
inode that survives unlinking.

Under G-02 the session cwd is a field: cd probed
canonicalize(cwd + operand) as a string, and the shell-side
redirect opens joined the target onto the same string, so both
died at the deleted component. This PR spends the existing cwd
anchor (the #3198 family's open handle) under its two-state
rule — relative filesystem operand, the session cwd's path no
longer resolves, the anchor naming exactly that cwd:

- cd: the executor call sites lend `execute_with_io` an anchor
  resolver; when the joined-string probe fails for a relative
  operand, the anchor walk (openat O_DIRECTORY from the anchor
  handle) supplies the physical directory and the shared tail
  commits the move exactly as for the probed route; the walk's
  own error is the reported verdict when it fails.
- Redirects: anchor arms at the shell-process open points of a
  relative target — `open_input_redirect`,
  `probe_input_redirect_readwrite`, `create_redirect_output`,
  `open_append_target`, the rejection gates in redirection.rs
  and command_input_scope.rs (via one shared
  `anchored_redirect_probe`), the compound fd-0 stream bind
  (fstatat classification, openat acquisition), the read
  builtin's target funnel, and the text channel's one slurp
  open. rubash#1820's FIFO probe discipline is preserved on the
  anchor route (fstatat classification, faccessat validation,
  never a probe open of a FIFO); the empty word never takes the
  anchor route.

Absolute spellings through the dead directory keep the plain
string verdict on both faces — oracle-verified, and pinned as
controls (`cd $PWD/..`, `cat $PWD/../f`).

The merge round also converged the gates' own resolvability
verdict onto the family's identity gate: `anchor_fd_for_dead_cwd`
now asks `session_cwd_path_resolves`, and
`cd_target_via_cwd_anchor`'s metadata check applies the same
(dev, ino) comparison against the anchor handle — so a path
recreated around the stationary session counts as dead for these
consumers too, exactly as it already did for the spawn stamp and
the anchored read (a cross-PR obligation from #3281's landing,
executed in this PR's merge round because #3281 reached master
first).

## What this PR deletes

No file, code path, or test is deleted. The change is additive
anchor arms on existing funnels plus one signature widening:
`cd::execute_with_io` gains an `anchor_resolver` parameter
(the standalone `cd::execute` entry and the two in-file unit
tests pass `None`). The joined-path opens remain the verdict
in every state where the anchor does not apply.
9 files changed, +1119/−34 against the base below.

## Evidence

Base: `5e0a4e14` (master at branch time; the merge round
brought the branch onto master `3a93856b` and re-ran every leg
on the merged tree — the head figures below are the merged
tree's). Oracle: GNU bash
5.3.20 (`~/workspace/rubash-audit/gnu-bash-5.3.20/bin/bash`),
per-cell probes with the deleted cwd staged by
`cd a; (cd ..; rmdir a)`; every pin expectation is an oracle
measurement.

Pin `tests/issue3268_deleted_cwd_cd_redirect.rs` — 19
completion-form cells (assertions are output bytes + status,
never timing; Unix-only because the anchor is a Unix handle):
19 passed; 0 failed on the head tree; on the base tree the
fail-first red set is exactly the defect cells
(5 passed / 14 failed), the controls stay green on both.

Neighbour pins on the head tree: issue3198 7 passed / 0 failed,
issue3201 5 passed / 0 failed; the merge round's convergence
check also re-ran issue3275 (4 passed / 0 failed) and issue2526
(4 + 3 passed / 0 failed) on the merged tree. Lib suite: head
1233 passed; 0 failed; 4 ignored, base (master `3a93856b`)
1233 passed; 0 failed; 4 ignored — failure name
sets identical (difference empty). `RUSTFLAGS="-D warnings"`
check (lib + bins) rc=0; `cargo check --tests` rc=0;
`cargo fmt --check` rc=0; `check-marker-literals.py` rc=0;
`check-utf8-boundary-hygiene.sh` clean. Cross-target:
`cargo check --tests --target armv7-linux-androideabi` rc=0
(local, NDK recipe); the darwin cross-target and macOS test
legs pass in this head's CI.

Known residual, deliberately not pinned: `cd .` from a deleted
cwd — GNU succeeds with a getcwd diagnostic on stderr and
$PWD spelled `D/a/.` (the `change_to_directory` resetpwd
residue); this PR succeeds with $PWD kept at `D/a` and no
diagnostic. The diagnostic half belongs to the
getcwd-reporting family next to #2798, not to this face; the
pin asserts the verdict and continued function only.
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.

1 participant