Skip to content

WIP: fix nested rubash child signal death killing the outer shell - #2248

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/2236-nested-signal
Oct 30, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/2236-nested-signal

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2236

Problem

A nested rubash child that kills itself with an untrapped signal took the outer shell down with it: outer died by the same signal, no inner-rc, no further commands. GNU (all four outer/inner arms probed byte-wise) reports inner-rc=143, prints the foreground death notice (Terminated <child argv>), and continues. The divergence existed only for rubash×rubash nesting.

Mechanism

execute_direct_shell_script runs a same-shell script child in-process on the parent's Executor (no second execve — strace-verified). The child's kill -TERM $$ therefore addressed the hosting process: the ancestor route (#1654) is armed only for flat subshell layers (subshell_depth > 0), so the delivery fell through to libc::raise and killed the outer shell. Two sibling shapes compounded it: in a subshell host the child inherited the adopted outer shell_pid, so its $$ named the outer process and the suicide escaped as a real kill(2); and a delivery queued as the child's last command was left for the parent's boundary poll (or the fresh-shell exit discard).

Fix

  • src/builtins/kill.rs: new DIRECT_CHILD_ROUTE thread-local (RAII arm, sibling of ANCESTOR_ROUTE). While armed, a kill delivery to the process's own pid joins the ancestor lane (ANCESTOR_SIGNALS) — the lane whose contract is "no kernel-disposition judge, adjudicated by the then-current trap table". The plain self-signal queue would be wrong: its entries carry the stale-handler check, and an untrapped signal has no kernel handler by design ([linux] Blocked rubash is unkillable by SIGTERM: signal_hook installs with SA_RESTART and pending signals dispatch only at command boundaries #226). Plus an adjudicated-death record (ADJUDICATED_SIGNAL_DEATH) written by both untrapped adjudication funnels.
  • src/executor/trap_exec.rs: run_pending_signal_traps and observe_signals_while_blocked record an untrapped 128+signal verdict into the death record.
  • src/executor/external_finish.rs: execute_direct_shell_script gains contain_child_signals (true for the THIS_SH/script and same-shell-binary entries; false for ENOEXEC, which keeps the historical fork-child model). For the span of a contained run: the route is armed, shell_pid presents as the process pid and subshell depth as 0 (the child's fresh-process identity; the tail already restores both), the notice text is captured pre-run, an exit drain adjudicates a last-command delivery at child depth 0, and if the adjudicated death is the final status the parent queues the jobs.c death notice via the existing note_child_signal_death.

GNU grounding: child-as-own-process (execute_cmd.c:6139-6233), boundary adjudication by the current trap table (trap.c run_pending_traps), foreground death notice (jobs.c).

Verification (GNU bash 5.3.20 oracle, debug build of this branch)

  • Four-arm matrix (gnu/rubash outer × gnu/rubash inner) + single-layer suicide: all byte-identical, stderr notice included.
  • Shapes: plain / forged-key / function / subshell / pipeline / comsub / bg+wait / -c — all byte-identical to GNU (pipeline modulo a pre-existing PIPESTATUS race that also reproduces with a plain echo script and a GNU stage; noted in the cluster REPORT).
  • Extra: child EXIT trap runs on signal death and the notice still prints; trapped child continues; ignored child continues; USR1 death notice (branch-1 form); kill -0/kill -l inside a child; three-level nesting; an external SIGTERM to a waiting outer still kills it (no containment leak).
  • Perf cluster's 15-case trap/select battery, three-way (GNU / master bbd95e3 / this branch): base==fixed on all 15; trap-exit-reroute keeps its recorded pre-existing diff-gnu on both.
  • Regression pins tests/issue2236_nested_signal_death_regressions.rs: 9/9 green on this branch; on master the five untrapped-death pins are red, the four guard pins (trapped/ignored/-c/single-layer) already green.

Full gate via PR CI per cluster discipline.

A same-shell script child runs in-process (execute_direct_shell_script),
so when the child killed itself with an untrapped signal the delivery
fell through to raise(2) on the hosting process and the OUTER shell
died with the child's signal. GNU runs the child as its own process
(execute_cmd.c:6139-6233): the kill can only kill the child, the
parent observes 128+signal, prints the jobs.c foreground death
notice, and continues.

While a contained child runs, kill deliveries addressed to the
process's own pid now join the ancestor lane instead of raising, so
the child's own trap table adjudicates them (trapped: action runs,
child continues; ignored: dropped; untrapped: only the child ends at
128+signal). For the span of the run the executor presents the
child's fresh-process identity (shell_pid = the process pid,
subshell depth 0), an exit drain adjudicates a delivery that arrived
as the child's last command, and an adjudicated death is recorded so
the exit boundary can queue the parent's death notice for the child.
ENOEXEC children keep the historical fork-child model untouched.

Regression pins: tests/issue2236_nested_signal_death_regressions.rs
(9 pins, GNU bash 5.3.20 oracle; the five untrapped-death pins are
red on master bbd95e3).

Refs #2236
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 30, 2026 16:27
@caomengxuan666
caomengxuan666 merged commit 9da5eb9 into master Oct 30, 2026
13 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2236-nested-signal branch November 2, 2026 01:08
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