Commit 28159fc
fix(guest): exec timeout watcher must SIGKILL, not SIGALRM by GHSA-xjhv-pp2r-6f82 (#543)
* fix(guest): exec timeout watcher must SIGKILL, not SIGALRM
The timeout watcher in src/guest/src/service/exec/timeout.rs sent
Signal::SIGALRM (signal 14, catchable) when an exec exceeded its
deadline. Any workload that installed `signal.signal(SIGALRM, SIG_IGN)`
in Python or `trap '' ALRM` in shell absorbed the signal and ran to
completion past the configured timeout, returning exit_code=0 —
bypassing the deadline entirely.
The inline comment already said "Kill process with SIGKILL"; only the
code passed the wrong Signal. Use Signal::SIGKILL (signal 9,
uncatchable) so the watcher guarantees termination regardless of
in-process signal handlers.
An audit of catchable-signal usage across the codebase found no other
instances of this bug class. All graceful-shutdown paths
(container/lifecycle.rs, exec/registry.rs, vmm/controller/shim.rs,
runtime/rt_impl.rs, cli/serve/mod.rs) already escalate SIGTERM → wait →
SIGKILL correctly.
Two regression tests guard the fix:
- sdks/python/tests/test_exec_timeout_sigalrm.py — Python pytest port
of the reporter PoC: workload installs SIG_IGN for SIGALRM, sleeps 8s
with timeout=3s. Asserts result.exit_code != 0 AND elapsed <
TIMEOUT_S + 2.0.
- src/boxlite/tests/exec_options.rs::test_timeout_kills_sigalrm_ignoring_process
— canonical Rust integration test (counterpart to
security_enforcement.rs). Shell workload uses `trap '' ALRM; sleep 15`
with timeout=2s; same assertion shape.
Verified via controlled experiment (reverting timeout.rs to SIGALRM):
both new tests FAIL in the bug state with rich diagnostics
(`exit_code=0`, elapsed near WORKLOAD_S), both PASS with the fix.
Three independent control tests (test_api_key_credential_get_token,
test_oci_symlink_escape_blocked, test_timeout_kills_long_command) PASS
in both states — confirming the fix is precisely scoped and the new
tests aren't trivially-passing or trivially-failing.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(guest): two-stage SIGTERM/grace/SIGKILL on exec timeout
Replaces the single-step SIGKILL with the SIGTERM → grace → SIGKILL
pattern used elsewhere in the codebase (ExecRegistry::shutdown_all,
Container::shutdown, vmm/controller/shim.rs, runtime/rt_impl.rs).
Why two stages:
- SIGKILL alone is correct but harsh — cooperative workloads have no
chance to flush buffers, close files, or commit transactions. Sandbox
consumers (AI agents running short-lived scripts) usually want both
"let me clean up" AND "hard deadline still enforced".
- Industry default (Docker --stop-timeout, K8s terminationGracePeriod,
systemd TimeoutStopSec) is SIGTERM-first with SIGKILL fallback. Aligns
with user expectations.
- The watcher now logs whether grace was respected (info: exited cleanly)
or escalation was required (warn: workload absorbed SIGTERM).
The hard-deadline guarantee from the previous commit is preserved: any
workload that ignores SIGTERM via SIG_IGN / signal trap is still killed
by SIGKILL after the 2-second grace expires.
Stage-3 regression test:
sdks/python/tests/test_exec_timeout_sigalrm.py gains
test_exec_timeout_sigkill_fallback_when_sigterm_ignored. The workload
installs SIG_IGN for both SIGTERM and SIGALRM (every catchable signal
the watcher might fire in stages 1+2), so only the uncatchable SIGKILL
escalation after grace can stop it. Asserts exit_code != 0 AND
elapsed < TIMEOUT_S + GRACE_S + 2.0.
This complements the existing test_exec_timeout_kills_sigalrm_ignoring_process
(which exercises stage-1 SIGTERM against a workload that only traps
SIGALRM). Together the two tests cover all three stages of the watcher.
Verified via controlled experiments (logs in ../log/):
- 01-baseline-sigkill-*.log — single-step SIGKILL baseline, 5/5 PASS
- 02-two-stage-*.log — after refactor, 5/5 PASS (no regression
in existing tests)
- 03-stage3-test-*.log — with new stage-3 test, 6/6 PASS
- 04-control-sigterm-only-*.log — timeout.rs reverted to SIGTERM-only
(no SIGKILL fallback); only the new
stage-3 test FAILS with diagnostic
"exec returned exit_code=0 after 8.08s",
proving the test catches a genuine
regression and is not always-pass
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Gamnaam Song <gamnaamsong@Airbus380-841-Main-Controller.local>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 7f8df26 commit 28159fc
3 files changed
Lines changed: 235 additions & 7 deletions
File tree
- sdks/python/tests
- src
- boxlite/tests
- guest/src/service/exec
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
96 | 141 | | |
97 | 142 | | |
98 | 143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
6 | 9 | | |
7 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
8 | 19 | | |
9 | 20 | | |
10 | 21 | | |
11 | | - | |
12 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
13 | 26 | | |
14 | 27 | | |
15 | 28 | | |
| |||
18 | 31 | | |
19 | 32 | | |
20 | 33 | | |
21 | | - | |
22 | 34 | | |
23 | | - | |
24 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
25 | 61 | | |
26 | 62 | | |
27 | 63 | | |
0 commit comments