Skip to content

WIP: env-marker trust family — provenance-validated respawn state, import strip-list, POSIX single truth (#2134/#2135/#2136/#2137) - #2150

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/env-marker-trust-family
Oct 29, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/env-marker-trust-family

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

WIP: env-marker trust family — internal state gets one source of truth; the environment stops being it at import time.

Four commits, one per issue. Cluster report with full mechanism + evidence: ~/workspace/fix-env-marker-family/REPORT.md (probe ledger: every census forgery face reproduced on master, inert after the fix; every genuine shape byte-identical).

#2136 — respawn provenance (F5). The internal-respawn gate keyed on ambient strings (__RUBASH_SHELL_PID presence opened $$ adoption, depth/BASHPID seeds and the positional transport). All four fork-shaped spawn sites now stamp __RUBASH_SPAWNER_PID (spawner pid + kernel start time); Executor::new honors the claim only when the stamp names the child's actual parent (getppid, the #867 cross-check), or under an orphan clause that sees through zombies, the exit-teardown window, and pid reuse. Same pass: __RUBASH_SHELL_PID no longer leaks through the process-env mirror into grandchildren, and the input-procsub builder now stamps subshell depth parent+1 (GNU subst.c:6362 — its child previously read $BASH_SUBSHELL=0).

#2134 — async-child signal face (F3). apply_async_child_entry_ignores applied SIGINT/SIGQUIT ignores from the ambient marker alone. Now the marker is scrubbed unconditionally and the ignores require validated provenance (#2136) plus a non-interactive invocation shape — an interactive shell is never born ignoring Ctrl+C. Genuine async respawns (always -c) are unchanged.

#2135 — function-stdin staging (F4). __RUBASH_FUNCTION_STDIN/_OFFSET join the import strip-list (table + mirror). No spawn builder ever stamped them; all legitimate writes are in-process post-import, so the #2111 faces are untouched.

#2137 — execution-scope trio (F7/F8/F9). __RUBASH_DEBUGGER_MODE/_ATTEMPTED and __RUBASH_COMSUB_BODY stripped at import (own-argv and in-process writers re-establish them). POSIX: the option state is the single truth — a validated respawn re-projects the marker from the transported option; a top-level entry drops the marker and the transported SETOPT family and lets the GNU channels (POSIXLY_CORRECT, SHELLOPTS, --posix, set -o posix) re-derive the pair in sync.

Pins: 35 new tests across tests/issue2134_*.rs, issue2135_*.rs, issue2136_*.rs, issue2137_*.rs — forgery shapes red on master, all green here; genuine-shape controls green on both. Regression battery in the report: focused transport/signal/subshell/coproc suites all green; lib and regression.rs deltas are the documented pre-existing VM reds only (incl. golden_eco_completion_register, adjudicated identical on pristine master).

Fixes #2134
Fixes #2135
Fixes #2136
Fixes #2137

…2136)

The internal-respawn gate keyed on ambient environment strings: any
parent could export __RUBASH_SHELL_PID and a fresh child adopted the
value as its own $$ (naming a process that may not exist), unlocked the
__RUBASH_POSITIONAL_PARAMS transport, and let __RUBASH_SUBSHELL_DEPTH /
__RUBASH_BG_* rewrite $BASH_SUBSHELL and the synthetic BASHPID chain.
GNU reaches the equivalent state only by fork: a forked child's $$ stays
the main shell's pid (variables.c dollar_vars), a subshell runs one
level deeper (execute_cmd.c execute_in_subshell), and no unrelated
parent can rewrite either.

Every fork-shaped spawn site (async/subshell wrapper in compound_exec,
coproc child, output process substitution in external_setup, input
process substitution in trap_exec) now also stamps __RUBASH_SPAWNER_PID
with the spawner's own identity: its process id, plus its kernel start
time where the platform exposes one (Linux /proc stat field 22).
Executor::new honors the provenance claim only when the stamp names
the child's actual parent (getppid — the same cross-check the
PDEATHSIG arming uses, rubash#867), or the child was orphaned to the
namespace init and the stamped spawner is gone. "Gone" sees through
the two ways a dead spawner can look alive in the orphan window: a
zombie (and, on Linux, a process in exit teardown — address space
already released, vsize 0, state letter not yet flipped to Z, which is
exactly the state a spawner is in when its child first observes the
reparenting) and an unrelated process that reused the pid (its start
time differs from the stamp's). An unvalidated claim is consumed but
inert: $$ falls back to the process's own pid, depth/BASHPID seeds to
the top-level defaults, positionals to the command line's.

Hygiene in the same pass: __RUBASH_SHELL_PID was removed from the env
table but not from the process-env mirror, so it leaked into every
external command a respawned child spawned (a nested shell launched
from an async child adopted its grandparent's pid); the coproc claim
key and the spawner stamp are now consumed from both stores as well.

Adjacent divergence fixed in-family: the input-process-substitution
builder never stamped the subshell depth, so its child reported
$BASH_SUBSHELL=0 where GNU reports parent+1 (subst.c process_substitute
makes the producer a forked child one level deeper, like the consumer
form); it stamps parent+1 now.

Pins: tests/issue2136_respawn_provenance.rs (10 tests; the forgery,
stranger-stamp, procsub-depth and nested-leak shapes are red on master,
all green here; the genuine async/procsub/coproc/orphan shapes stay
green on both). The orphan pin's spawn helper closes the inherited
build-slot flock fd so the local slot cannot flip the shell's async
spawn-path gate and change the pid topology the pin asserts on; the
pin is identical under CI, which never runs under the slot.
…2134)

apply_async_child_entry_ignores honored __RUBASH_ASYNC_CHILD=1 at face
value: any script could export it and every shell it spawned was born
ignoring SIGINT/SIGQUIT — surviving Ctrl+C with exit 0 where the control
exits 130 — and with -i the forgery reached the interactive face. The
old comment's defence ("the same disposition trap '' INT achieves
deliberately") is false in the direction that matters: trap is an act
inside the victim shell; this key is set by a different process. GNU
reaches the ignore state only in a genuinely forked async child
(jobs.c setup_async_signals at the fork site); dispositions are
inherited through fork/exec, never asserted by data.

The entry point now scrubs the key unconditionally (as before) and
applies the ignores only when the process's respawn provenance
validates against its actual parent (rubash#2136, read from the live
process environment before the executor imports it) AND the invocation
is a -c respawn shape — an -i/--interactive flag or a stdin-driven
operand-less invocation refuses even with validated provenance, so an
interactive shell is never born ignoring Ctrl+C. Genuine async respawns
are always -c children (the command-file spill keeps -c with an empty
operand), so their classification is unchanged: the golden async-child
shapes, the ASYNC_CHILD_ENTRY soft-ignore fold in seed_startup_traps,
and trap/pdeathsig arming (separate channels, rubash#866) are
untouched.

Pins: tests/issue2134_async_child_forgery.rs (7 tests; the plain
forgery, the stranger-stamp forgery, and both interactive-shape
refusals are red on the pre-fix tree, all green here; control,
validated-parentage and genuine-async shapes green on both).
__RUBASH_FUNCTION_STDIN / __RUBASH_FUNCTION_STDIN_OFFSET stage a
substitute stdin for function calls; every read site consults the live
environment table (the rubash#2111 function-stdin surface). An ambient
copy in a fresh process's environment was imported untouched, so a
parent exporting __RUBASH_FUNCTION_STDIN=<file> hijacked the child's
stdin: the first function-call read — and external commands running in
the staged scope — consumed the named file instead of the process's
real stdin.

Both keys join the import strip-list at Executor::new, next to the
__RUBASH_CURRENT_FUNCTION/__RUBASH_IN_SOURCE precedent: removed from
the imported table and from the process-env mirror (so respawn builders
seeded from the process environment cannot re-import them downstream).
Every legitimate write is in-process and post-import — the
function-call stdin scope in command_input_scope.rs / ast_exec.rs and
the source builtin's explicit-path staging in source.rs — so no
transport loses anything: no spawn builder ever stamped these keys.

Pins: tests/issue2135_function_stdin_import.rs (6 tests; both forgery
shapes red on the pre-fix tree, all green here; control and the genuine
pipe / while-read / herestring staging faces green on both).
…ts one truth (#2137)

Three ambient-trust faces of the same family, one import boundary:

F7 — __RUBASH_DEBUGGER_MODE / __RUBASH_DEBUGGER_ATTEMPTED: every writer
is this process's own argv handling (invocation.rs --debugger, main.rs
option arms), which runs after Executor::new imports the environment.
An ambient copy made every -c child attempt a debugger startup and set
the ATTEMPTED latch. Both keys are stripped at import (table + mirror);
own-argv handling re-establishes them, verified by the --debugger pin.

F8 — __RUBASH_COMSUB_BODY: bracketed in-process state around an
embedded command-substitution run (command_substitution.rs) and the
mutation fold (embedded_mutations.rs), always restored afterwards. An
ambient copy rewrote a top-level fatal expansion's exit status from
127 to 1 (parameter_errors.rs expansion_fatal_status). Stripped at
import; the in-process writers re-establish it per run.

F9 — POSIX split state: posix_mode_enabled() and ~30 dialect sites read
the __RUBASH_POSIX_MODE marker while `set -o` reports
__RUBASH_SETOPT_posix, and both halves were ambient-writable, so they
disagreed in both directions (dialect on / option off; option on with
inconsistent fatality). The option state is now the single source of
truth at the import boundary: a validated respawn (rubash#2136 — a
fork-shaped child whose option state is transported state) re-projects
the marker from the transported option truth; a top-level entry drops
the marker and the transported SETOPT family, and the GNU channels
re-derive the pair in sync (POSIXLY_CORRECT and SHELLOPTS/BASHOPTS via
set_shell_option in initialize_fresh_shell_env_vars, --posix argv,
in-session `set -o posix` via apply_posix_mode_transition, the only
writer that ever kept the pair in sync). The marker is a write-only
projection from here on. Only the posix pair leaves the process-env
mirror: the niu host's pretty-print read of __RUBASH_POSIX_MODE
consults a live shell's own mirror, and the non-posix SETOPT keys keep
their diagnostic surface (companion observation, not changed here).

Pins: tests/issue2137_execution_scope_markers.rs (12 tests; the five
forgery shapes red on the pre-fix tree, all green here; the
--debugger, genuine-comsub, POSIXLY_CORRECT, --posix, in-session-flip
and respawn-inheritance controls green on both).
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 29, 2026 18:34
@caomengxuan666
caomengxuan666 merged commit 6cfecfc into master Oct 29, 2026
17 of 18 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/env-marker-trust-family branch October 30, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment