Skip to content

fix(shell): close loop, eval, background-job and glob budget bypasses - #893

Merged
ewhauser merged 2 commits into
mainfrom
claude/determined-hellman-6e15e0
Oct 20, 2026
Merged

ewhauser merged 2 commits into
mainfrom
claude/determined-hellman-6e15e0

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Fixes the internal/shell findings from the second review of main at 19ff56a.

  • Loop guard spoofing (HIGH): the interpreter now spots instrumented loop guards by their *syntax.CallExpr node (new RunnerConfig.LoopGuard hook), not by the __jb_loop_iter name. A literal user call or function with that name fails validation. A dynamic call ($c) is now a normal command lookup that counts toward the command budget (it fails with command not found). Loop counts only use IDs the instrumenter created.
  • eval/source/trap skipped compileChunk (HIGH): a new RunnerConfig.NestedChunkTransformer runs compileChunk on chunks parsed at run time, each with a fresh loop namespace. A budget violation inside one exits with 126; a validation error returns 2.
  • exec > >(cat) hang (HIGH): a statement no longer waits for >(…) substitutions that exec keeps open. They are joined when the shell exits. exec 3< <(…) still works.
  • Background jobs outliving Run (HIGH): background jobs and process substitutions now belong to a shared job group. When Run ends, Runner.StopJobs cancels the background jobs, closes the shell side of each procsubst pipe, and joins every goroutine, all before the procsubst FS scope is restored. This fixes the data race on exec.FS.
  • Glob budget only at parse time (MEDIUM): the expander now charges EstimateGlobOperations each time a pathname expansion runs, through an optional expand.GlobBudgetCallbacks interface. It raises interp.GlobLimitError (exit 126). The parse-time estimate is gone. Small change outside internal/shell: shell/expand/expand.go.
  • Recursion through eval/source/& (MEDIUM): eval and source frames count toward MaxFunctionDepth. No more than 256 background jobs can be live at once per shell family.
  • kill -9 $$ silently ignored (LOW): non-catchable signals now return an error (cannot send SIGKILL in the sandbox, status 1).
  • coproc panic (LOW): coproc and mksh |& now fail validation with a clear error.

The dedicated __jb_ prefix check is limited to the exact __jb_loop_iter name, because internal/runtime has a test that allows (and charges) user commands with a __jb_ prefix.

SPEC.md: updated the budget implementation notes (guard identity, nested chunk compilation, runtime glob charging, eval/source depth, background job cap and joining, coproc and non-catchable kill).

Tests: internal/shell/budget_review_test.go has one regression test per finding. go test -race ./internal/shell/... and make lint pass.

@ewhauser
ewhauser enabled auto-merge (squash) October 20, 2026 15:05
@ewhauser
ewhauser merged commit 57be482 into main Oct 20, 2026
17 checks passed
@ewhauser
ewhauser deleted the claude/determined-hellman-6e15e0 branch October 20, 2026 15:13
@ewhauser ewhauser mentioned this pull request Oct 20, 2026
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