Baseline RetAddrEntry PC Offset Truncation
The eager Baseline JIT compilation path in SpiderMonkey queues scripts for compilation without enforcing the same script-length limit that the normal entry path applies, so a bytecode PC offset larger than the 28-bit RetAddrEntry bitfield can be stored. In debug builds this trips an assertion and crashes the content process; in release builds the offset is silently truncated, producing incorrect return-address metadata that could misdirect exception handling and stack walking.
- Fixed in 4 days
- Paid in 16 days
- Disclosed after 4 days
Created attachment 9583053 poc.zip
Baseline RetAddrEntry PC Offset Truncation
Summary
The Baseline JIT return-address table stores the bytecode PC offset in the 28-bit RetAddrEntry::pcOffset_ bitfield. The normal Baseline entry path rejects oversized scripts on x86-64 with BaselineMaxScriptLength == 0x0fffffff, matching that 28-bit storage limit. The eager Baseline compilation path used during stencil instantiation does not apply the same length check.
As a result, content can first seed a JitHint and then load a larger script with the same script key. If the larger script places an IC at a bytecode offset above the 28-bit limit, the off-thread eager Baseline compiler attempts to store that oversized PC offset in RetAddrEntry. Debug builds abort on pcOffset_ == pcOffset. Release builds truncate the high bits in the bitfield, producing incorrect BaselineScript return-address metadata.
Affected Component
- SpiderMonkey Baseline JIT
- off-thread eager Baseline compilation
- JitHints-based eager compilation
- BaselineScript return-address table
Impact
Confirmed impact:
- Firefox content process assertion failure at
js/src/jit/BaselineJIT.h:150 - The content process exits with signal 11 after the assertion.
- The symbolized stack enters
RetAddrEntry::RetAddrEntryfromBaselineCodeGen::emitNextIC,emit_GetGName, andBaselineCompileTask::runTask.
Security relevance:
- This is not only a debug assertion.
pcOffset_is a 28-bit bitfield, so release builds store a truncated PC offset. - The Baseline return-address table maps native return addresses back to bytecode PCs for ICs, VM calls, exception handling, stack walking, and related runtime operations.
- A truncated PC offset can make those operations use a bytecode location different from the actual execution site.
- In exception handling, this can select the wrong try-note or stack depth and cause Baseline frame stack slots to be interpreted incorrectly.
- A controlled memory-corruption primitive has not been established in this report.
Suggested severity: high, pending exploitability assessment.
Root Cause
RetAddrEntry stores the bytecode PC offset in a 28-bit bitfield.
Relevant source:
js/src/jit/BaselineJIT.h:100-164
The failing checks are debug-only:
uint32_t pcOffset_ : 28;
MOZ_ASSERT(pcOffset_ == pcOffset);
MOZ_ASSERT(pcOffset <= BaselineMaxScriptLength);
The normal x86-64 Baseline script length limit is aligned with the 28-bit bound.
js/src/jit/BaselineJIT.h:66-74
The eager Baseline compilation path queues scripts during stencil instantiation without checking BaselineMaxScriptLength.
Relevant source:
js/src/frontend/Stencil.cpp:2720-2798js/src/frontend/Stencil.cpp:2819-2826
emitNextIC creates an IC return-address entry using the current bytecode pcOffset.
js/src/jit/BaselineCodeGen.cpp:783-788
A high-offset GetGName IC reaches this path.
js/src/jit/BaselineCodeGen.cpp:3683-3690
Firefox default settings enable JitHints-based eager Baseline compilation.
modules/libpref/init/StaticPrefList.yaml:9073-9142dom/script/ScriptLoader.cpp:2742-2766
Reproducer
poc.html
payload.js
server.py
PoC structure:
poc.htmlloadspayload.jstwice from the same URL.- The first
payload.jsresponse is a small seed script that creates a JitHint. - The second
payload.jsresponse is a large script from the same URL, placing aGetGNameIC after a bytecode offset above the 28-bit limit. server.pyserves different responses for the first and second requests to the same/payload.jsURL.- No shell-only function or preference change is required.
Default-Settings Reproduction
Command:
<firefox> --headless --no-remote --profile <empty-profile> <poc-url>
Result:
firefox_status=11
reason=debug-assertion-after-done
done=1
assertion=1
Assertion:
Assertion failure: pcOffset_ == pcOffset, at js/src/jit/BaselineJIT.h:150
Program firefox received signal 11.
Symbolized stack:
js::jit::RetAddrEntry::RetAddrEntry
mozilla::Vector<js::jit::RetAddrEntry>::emplaceBack
js::jit::BaselineCodeGen<js::jit::BaselineCompilerHandler>::emitNextIC
js::jit::BaselineCodeGen<js::jit::BaselineCompilerHandler>::emit_GetGName
js::jit::BaselineCompiler::emitBody
js::jit::BaselineCompiler::compileImpl
js::jit::BaselineCompileTask::runTask
js::jit::BaselineCompileTask::runHelperThreadTask
JS::RunHelperThreadTask
Expected Behavior
The Baseline compiler should do one of the following:
- enforce
script->length() <= BaselineMaxScriptLengthin the eager Baseline path as well; - safely fail Baseline compilation for scripts whose PC offsets cannot be represented in
RetAddrEntry; - widen or change return-address metadata encoding so PC offsets are not truncated.
Release builds must not create BaselineScripts containing truncated bytecode PC offsets.
Suggested Fix
Minimum fix:
- Before queueing a script for eager Baseline compilation, reject scripts with
script->length() > BaselineMaxScriptLengthusing a release-enforced compile failure. - Share script length validation between the normal Baseline entry path and the eager Baseline path.
More robust fix:
- Validate
pcOffset <= BaselineMaxScriptLengthin release builds before storing aRetAddrEntry. - Widen
RetAddrEntry::pcOffset_or move the kind field out of the packed value to eliminate truncation. - Add a regression test that reloads a large same-key script through JitHints-based eager Baseline compilation.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The eager Baseline compilation path queues scripts during stencil instantiation without checking BaselineMaxScriptLength, so a PC offset exceeding the 28-bit RetAddrEntry bitfield is stored and truncated.
Impact
Debug builds abort with an assertion and the content process exits with signal 11; release builds store a truncated PC offset that could make exception handling and stack walking use the wrong bytecode location, though a controlled memory-corruption primitive was not established.
What the attacker needed
No special preferences needed; victim loads attacker page in Firefox
The fix
The eager Baseline path should reject scripts longer than BaselineMaxScriptLength with a release-enforced failure, and ideally the PC offset should be validated in release builds or the bitfield widened.
How it was found
- Load a page that requests the same script URL twice.
- Serve a small seed script on the first request so a JitHint is created for that script key.
- Serve a large script on the second request from the same URL, placing a GetGName IC beyond the 28-bit bytecode offset limit.
- Run Firefox headless with an empty profile against the page and observe the assertion and signal 11.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Firefox compiles JavaScript in stages, and one stage keeps a table that maps machine-code return addresses back to positions in the original script. That table stores each position in a fixed-size slot, and the code path that compiles scripts early forgot to check that the script is short enough to fit. A very large script can therefore put a too-large position into the slot, which crashes debug builds and silently corrupts the table in release builds.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.