Skip to content

WIP: fix(trap): key transported entry-ignores by signal number at startup (#2193, lands #1124 pins) - #2198

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2193-trap-transport
Oct 30, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2193-trap-transport

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2193
Refs #1124

Defect

Startup consumption of the __RUBASH_TRAP_ORIG_IGN transport keyed the trap-table rebuild and the entry-ignore bookkeeping on the payload's raw spelling. Every other part of the shell keys signals by the canonical form derived from the signal number (normalize_signal, entry_ignored_key, canonical_trap_order), so:

  • __RUBASH_TRAP_ORIG_IGN=38 rebuilt a phantom __RUBASH_TRAP_38 entry that no lookup ever finds on tables where slot 38 is named — trap -p 38 and trap -p printed nothing, and trap 'echo X' 38 was not the GNU silent no-op (it installed the trap).
  • __RUBASH_TRAP_ORIG_IGN=USR1 was dropped the same way (USR1 vs the canonical SIGUSR1).
  • Only rubash's own canonical full-name spelling (SIGRTMIN+4) survived, because writer and reader accidentally agreed on it.

The bare number is exactly the payload a bionic/Termux parent must write for a hole signal (32..40 have no name to spell), and the short name is what a foreign parent may write — the chain broke precisely on the spellings it exists to carry. The LIVE path (real SIG_IGN at entry) already matches GNU byte-for-byte and is untouched.

GNU model: entry dispositions are original_signals[] indexed by signal number (trap.c:136-150); decode_signal (trap.c:236) resolves every spelling to the number; set_signal returns silently for SIG_HARD_IGNORE (trap.c:852).

Fix

canonicalize_orig_ignored_signals runs at the top of seed_startup_traps (the single startup consumption point, reached from Executor::new and the ENOEXEC fresh-shell path): each transported entry is mapped through normalize_signal — numeric payloads land on their slot, name payloads resolve through SIGNALS to the same slot — and the result is stored back via store_orig_ignored_signals (sort/dedup collapses dual spellings of one signal). Entries naming no signal in this platform's table, and the EXIT/DEBUG/ERR/RETURN pseudo-signals, are dropped. After that, the rebuild loop, is_hard_ignored, print_traps, and the child-boundary re-export (transport_inherited_ignores) all read one canonical, number-keyed set. No per-spelling exception list.

Pins

Lands the five held-out #1124 pins (tests/issue1124_trap_entry_ignore_regressions.rs, from ~/workspace/pin-backfill-batch/issue1124_pins_held_out.rs) plus one #2193 short-name pin:

  • Pins 1–3 assert the number-keyed reconstruction with the platform listing spelling — bionic lists a transported 38 as trap -- '' 38 (nameless hole), glibc and the Windows wire table list trap -- '' SIGRTMIN+4 (live-path spelling verified against GNU 5.3.20 on glibc) — via a cfg'd SIGNAL_38_LISTING constant.
  • Pins 1–4 are gated to linux / android / windows (the platforms whose tables contain signals 32/38; the BSD table has 31 entries). Pin 4 stays meaningful there (a non-ignored hole lists nothing); pin 5 is as authored (vacuous on clean-mask hosts, real on the Termux launcher shape).
  • New pin: USR1:SIGUSR1 dual-spelling payload lists exactly once as SIGUSR1 and refuses a set silently.

Local verification (targeted; full gate via this PR's CI)

  • Issue's five repros on master: 1/2/4 empty, 3 installs the trap (bug). On this build: all five GNU-shaped; dual-spelling payload collapses to one entry; bogus/pseudo payload leaves a clean table.
  • Live path (preexec SIG_IGN on 38 + USR1, set/reset/list script): fixed build byte-identical to GNU 5.3.20.
  • cargo test --lib builtins::trap 16/16 (3 new unit tests), --lib builtins::kill 22/22.
  • New pin file 6/6. Neighborhood: issue1034 2/2, issue546 7/7, issue1630 (async transport consumer) 4/4, issue1104/1105/1106 8/8, signal_trap_coverage 7/7, issue1654 7/7, issue0085/0086/0088/0290 4/4, host_internal_trap_suppression 1/1, cli_tests trap subset 11/11.

__RUBASH_TRAP_ORIG_IGN consumption (seed_startup_traps) keyed the
trap-table rebuild and the hard-ignore checks on the payload's raw
spelling, so a bare-number entry (38 — the only spelling a bionic
hole has) or a short name (USR1) landed on a phantom trap-table key
no lookup ever uses, and set/reset on the signal were not the GNU
silent no-ops. Only rubash's own canonical full-name spelling
survived the trip.

GNU keys entry dispositions by number: original_signals[] is
indexed by sig (trap.c:136-150), decode_signal (trap.c:236)
resolves every operand spelling to the number, and set_signal
returns silently for SIG_HARD_IGNORE (trap.c:852).

Canonicalize the transported set through the signal table at the
top of seed_startup_traps and store it back: numeric payloads land
on their slot, name payloads resolve through SIGNALS to the same
slot, dual spellings of one signal collapse, and entries naming no
signal in this platform's table (plus the EXIT/DEBUG/ERR/RETURN
pseudo-signals) drop. The rebuild, is_hard_ignored, print_traps and
the child-boundary re-export all read the one canonical set
afterwards. The live SIG_IGN path is untouched — verified
byte-identical to GNU 5.3.20 with a preexec SIG_IGN probe.

Lands the five held-out issue1124 pins
(tests/issue1124_trap_entry_ignore_regressions.rs) with the fix:
pins 1-3 assert the number-keyed reconstruction with the platform
listing spelling (bionic: bare 38; glibc/Windows wire: SIGRTMIN+4),
pins 1-4 are gated to the Linux-numbering platforms (the BSD table
has no signals 32/38), pin 5 stays as authored, and a short-name
transport pin covers the USR1 leg.

Refs #2193
Refs #1124
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 30, 2026 09:35
@caomengxuan666
caomengxuan666 merged commit 3fb862c into master Oct 30, 2026
10 of 11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2193-trap-transport branch October 30, 2026 09:36
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