Skip to content

WIP: fix(signals): install handlers for trapped stop-class signals and SIGCONT - #2350

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2344-stop-signal-traps
Oct 31, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2344-stop-signal-traps

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2344 — audit ch1 RC1 fix (RC-freeze audit-fix line).

Root cause

The kernel-signal backend's managed set (MANAGED_CORE + the hand-kept managed_trap_keys table in src/builtins/kill.rs) is the eligibility set for the rule "the trap table drives kernel dispositions" — and it omitted exactly SIGTSTP/SIGTTIN/SIGTTOU/SIGCONT. The trap table recorded their traps (trap -p TSTP listed them), but reconcile never computed a wish for them, so no handler was ever installed: trapped CONT silently discarded; trapped TSTP/TTIN/TTOU left at SIG_DFL → the shell really stopped (audit /proc State: T evidence) and the trap was dropped on resume; trap '' TSTP never installed SIG_IGN.

GNU: trap.c:838 set_signal() installs trap_handler for ANY trapped signal, stop class included; delivery defers via pending_traps[] to trap.c:328 run_pending_traps() at a safe point, so the shell never stops.

Fix (mechanism, not a case list)

Verification

  • Probes s1–s15 (script files, safe supervisor harness with /proc State sampling + SIGCONT watchdog) run against GNU 5.3.20 oracle, baseline cb39c1d, and the fixed build: every shape byte-identical to GNU post-fix, including deferral past a foreground wait (trap after wait completes, $? preserved), wait interrupted at 148, untrapped TSTP still stopping with an EXIT trap armed and after trap -, child shells inheriting SIG_DFL (child stops, parent trap silent), and entry-ignored TSTP staying un-trappable.
  • New pins tests/issue2344_stop_signal_trap_regressions.rs: 10/10 locally via the build slot (12.76s). Pins are watchdog-bounded (own process group, grace SIGCONT, hard SIGKILL) so a regression fails instead of hanging CI.
  • Adjacent smoke: signal_trap_coverage_regressions 7/7, issue1034_sleep_trap_deferral_regressions 2/2, builtins::kill lib tests 22/22. cargo check clean; fmt applied to touched files only; 0 CR.

Gate split: full suites = CI + collector. Not verified here: interactive/tty faces (terminal-generated ^Z during a builtin sleep, TTOU write-triggered delivery) — same gap the audit recorded for RC1.

…CONT (Refs #2344)

The kernel-signal backend's managed set — the eligibility set for the
rule that the trap table drives kernel dispositions — omitted exactly
SIGTSTP/SIGTTIN/SIGTTOU/SIGCONT. Traps on them were recorded in the
trap table (trap -p listed them) but no handler was ever installed:
a trapped CONT was silently discarded, a trapped stop signal left
the disposition at SIG_DFL so the shell really stopped and the trap
was dropped on resume, and `trap '' TSTP` never installed SIG_IGN.

GNU installs the deferring handler for ANY trapped signal:
trap.c:838 set_signal -> sig.c:830 set_signal_handler (sa_flags=0),
execution deferred through pending_traps[] to trap.c:328
run_pending_traps at a command boundary, so a trapped stop signal
never stops the shell. Restore that invariant:

- MANAGED_CORE and managed_trap_keys gain TSTP/TTIN/TTOU/CONT, so
  reconcile computes their wishes (trap -> handler, trap '' ->
  SIG_IGN, none/reset -> entry disposition) and the entry snapshot,
  fork-child restore, and boundary dispatch all see them.
- exit_reroutes excludes the stop class and CONT: GNU's terminating
  set (sig.c:127 terminating_signals[]) names neither — their
  default actions are stop/resume, not termination — so an armed
  EXIT trap must not reroute an untrapped stop (oracle: the shell
  still stops, verified by /proc State evidence).
- The in-process layer routes (ancestor/direct-child) keep the stop
  class + CONT non-adjudicable: those lanes synthesize death
  verdicts, and a stop/resume has no death verdict to synthesize.
- sleep_interruptibly's virtual-child death model excludes the stop
  class: a stop signal never kills a real foreground child, so the
  delivery defers to the sleep's completion like any other trapped
  arrival.

Regression pins: tests/issue2344_stop_signal_trap_regressions.rs
(10 tests, watchdog-bounded so a regression fails instead of
hanging: the child runs in its own process group and a watchdog
SIGCONT/SIGKILL caps every run). Oracle-verified byte-for-byte
against GNU bash 5.3.20 via script files, including the deferral
shape (trap dispatches after the foreground wait completes, $?
preserved), the wait-builtin interrupt (128+20), child non-
inheritance of the handler, and the entry-ignored hard-ignore.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 31, 2026 06:44
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