Commit 6b9c38c
authored
fix(interpreter): add max_subst_depth limit to prevent OOM from nested $() (#1107)
## Summary
- Add dedicated `max_subst_depth` limit (default 32) to
`ExecutionLimits` to prevent OOM from deeply nested command
substitutions
- Each `$(...)` level clones the full interpreter state — memory grows
as depth × state_size
- Previously shared `max_function_depth` counter (default 100) was too
generous for expensive state-cloning operations
- Harden `arithmetic_fuzz` target with tighter resource limits
## Changes
- `limits.rs`: new `max_subst_depth` field, `subst_depth` counter,
`push_subst`/`pop_subst` methods, `MaxSubstDepth` error variant
- `interpreter/mod.rs`: switch both command substitution paths from
`push_function`/`pop_function` to `push_subst`/`pop_subst`
- `arithmetic_fuzz.rs`: add `max_function_depth(10)`,
`max_subst_depth(5)`, `max_stdout_bytes(4096)`, `max_stderr_bytes(4096)`
- `blackbox_security_tests.rs`: set `max_subst_depth` in `tight_bash()`
and `dos_bash()` helpers
- New `subst_depth_limit_tests.rs`: 3 regression tests including decoded
fuzz crash input
- `specs/006-threat-model.md`: add TM-DOS-088
## Test plan
- [x] `cargo test --test subst_depth_limit_tests` — 3 new tests pass
- [x] `cargo test --test blackbox_security_tests` — 78 tests pass
(previously stack-overflowed)
- [x] `cargo test --all-features -- --skip ssh_supabase` — all pass
- [x] `cargo clippy --all-targets --all-features -- -D warnings` — clean
- [x] `cargo fmt --check` — clean
Closes #10881 parent 34cf2c2 commit 6b9c38c
File tree
6 files changed
+158
-7
lines changed- crates/bashkit
- fuzz/fuzz_targets
- src
- interpreter
- tests
- specs
6 files changed
+158
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6212 | 6212 | | |
6213 | 6213 | | |
6214 | 6214 | | |
6215 | | - | |
6216 | | - | |
| 6215 | + | |
| 6216 | + | |
| 6217 | + | |
| 6218 | + | |
| 6219 | + | |
6217 | 6220 | | |
6218 | | - | |
| 6221 | + | |
6219 | 6222 | | |
6220 | 6223 | | |
6221 | 6224 | | |
| |||
6260 | 6263 | | |
6261 | 6264 | | |
6262 | 6265 | | |
6263 | | - | |
| 6266 | + | |
6264 | 6267 | | |
6265 | 6268 | | |
6266 | 6269 | | |
| |||
8436 | 8439 | | |
8437 | 8440 | | |
8438 | 8441 | | |
8439 | | - | |
| 8442 | + | |
8440 | 8443 | | |
8441 | 8444 | | |
8442 | 8445 | | |
| |||
8457 | 8460 | | |
8458 | 8461 | | |
8459 | 8462 | | |
8460 | | - | |
| 8463 | + | |
8461 | 8464 | | |
8462 | 8465 | | |
8463 | 8466 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
87 | 95 | | |
88 | 96 | | |
89 | 97 | | |
| |||
103 | 111 | | |
104 | 112 | | |
105 | 113 | | |
| 114 | + | |
106 | 115 | | |
107 | 116 | | |
108 | 117 | | |
| |||
201 | 210 | | |
202 | 211 | | |
203 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
204 | 219 | | |
205 | 220 | | |
206 | 221 | | |
| |||
287 | 302 | | |
288 | 303 | | |
289 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
290 | 308 | | |
291 | 309 | | |
292 | 310 | | |
| |||
309 | 327 | | |
310 | 328 | | |
311 | 329 | | |
312 | | - | |
| 330 | + | |
313 | 331 | | |
314 | 332 | | |
| 333 | + | |
315 | 334 | | |
316 | 335 | | |
317 | 336 | | |
| |||
444 | 463 | | |
445 | 464 | | |
446 | 465 | | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
447 | 482 | | |
448 | 483 | | |
449 | 484 | | |
| |||
461 | 496 | | |
462 | 497 | | |
463 | 498 | | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
464 | 502 | | |
465 | 503 | | |
466 | 504 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1228 | 1228 | | |
1229 | 1229 | | |
1230 | 1230 | | |
| 1231 | + | |
1231 | 1232 | | |
1232 | 1233 | | |
1233 | 1234 | | |
| |||
1322 | 1323 | | |
1323 | 1324 | | |
1324 | 1325 | | |
| 1326 | + | |
1325 | 1327 | | |
1326 | 1328 | | |
1327 | 1329 | | |
| |||
0 commit comments