[22] [JSC] Move FTL stack overflow check to prologue
Rated Medium because the diff fixes a JIT prologue-state invariant: the stack-overflow late path popped callee-saves but never restored SP before jumping to
ThrowStackOverflowAtPrologue, so the throw thunk ran with SP pointing inside a partially-constructed frame.
The stack overflow patchpoint ran inside the lowered function body — AFTER emitFunctionPrologue, frame allocation, and callee-save spilling — and tried to undo state before jumping to a thunk that expects "at prologue" stack shape.
Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp
Stack-pointer state divergence at a JIT exception edge: an out-of-line thunk was reached from a point that had advanced past the prologue without symmetrically unwinding SP.
The original code carried a FIXME pointing at the very bug number this commit closes — the author knew the stack-check belonged in the Air prologue and that the late-path emitRestore was a workaround.
Reaching the code requires forcing a real stack overflow at FTL function entry, and the resulting misbehavior most plausibly manifests as exception-machinery corruption or a crash rather than a memory-write primitive — but the diff alone does not bound the consequences inside the throw thunk.
This vulnerability weakens an internal invariant the exception-throw path depends on. Moving the check to a custom Air PrologueGenerator eliminates the symmetry requirement entirely.
Audit directions
- Late paths attached to patchpoints that jump to
...AtProloguethunks. Audit everyaddLatePathinSource/JavaScriptCore/ftl/andjit/ending injumpThunk(...AtPrologue...)and verify it restores both callee-saves and SP. - Shared thunks named
...AtPrologue. AuditCommonJITThunkIDentries with the suffix and review every call site for matching stack shape. - Stack-overflow checks placed after frame allocation. Audit other JIT tiers (DFG, baseline, Wasm OMG/BBQ) for stack-limit comparisons emitted after
subPtrof the frame size. - Defensive normalization in the thunk. Read
ThunkGenerators.cppfor whetherThrowStackOverflowAtProloguenormalises SP from FP on entry.