RTT::jsToWasmICEntrypoint should use DoNotHaveTagRegisters
CVE: CVE-2026-86974 · Safari 27.2 · Released October 26, 2026 Impact: Processing maliciously crafted web content may lead to memory corruption Apple's description: A type confusion issue was addressed with improved checks. Credit: Hossein Lotfi (@hosselot) of TrendAI Zero Day Initiative
High. Two switch arms trusted a register that nothing had reloaded, so undefined, a double, or a boolean could pass a cell check and be dereferenced as a heap pointer. That is a reliable renderer crash from script. The funcref arm's fake-object ceiling depends on downstream checks and address knowledge.
When JavaScript calls an exported WebAssembly function, JavaScriptCore can send the call through a JIT-generated inline cache. That cache checks each JS argument and unboxes it into the Wasm calling convention. The stub, RTT::jsToWasmICEntrypoint(), guards its fast path with tag checks that classify each value as an int32, a number, or a pointer to a heap cell, and it sends anything else to a slow path. Those checks are only sound if two reserved registers, numberTagRegister and notCellMaskRegister, actually hold the engine's tag constants when the stub runs. The stub cannot assume that on entry.
The angle: A page that mixes optimized Wasm with a strict-mode tail call can enter the stub with a stale notCellMaskRegister, so non-object values like undefined, numbers, or booleans are accepted as heap object pointers and dereferenced.
Source/JavaScriptCore/wasm/js/JSToWasm.cpp
JSTests/stress/wasm-js-to-wasm-ic-materializes-tag-registers.js
Patch Details
The fix is confined to one function, RTT::jsToWasmICEntrypoint(), plus a new regression test.
Before the patch, the generator tracked tag-register state with an emission-time boolean, haveTagRegisters, and a local lambda, materializeTagRegistersIfNeeded. The lambda emitted emitMaterializeTagCheckRegisters() at most once per stub, and each argument arm was expected to call it before any check that reads the tag registers. Only the I32 and F32/F64 arms did. The I64 arm and the reference-type (funcref) arm never called the lambda, yet both issued branchIfNotCell(scratchGPR) in its default HaveTagRegisters mode, which reads GPRInfo::notCellMaskRegister.
The patch removes the state dependency entirely:
- Flag and lambda deleted.
haveTagRegistersandmaterializeTagRegistersIfNeededare gone, along with both call sites in the I32 and F32/F64 arms. - Every tag check switched to immediates.
branchIfNotInt32, bothbranchIfNotCellsites (I64 and ref arms), andbranchIfNotNumbernow passDoNotHaveTagRegisters. In that mode the helpers encodeNumberTag/NotCellMaskas immediate operands and never read the reserved registers. - Scratch-reuse reset removed. In the I64 arm, when the target Wasm GPR collides with the scratch register, the code borrows
numberTagRegisteras a scratch fortoBigInt64and used to sethaveTagRegisters = falseto force a later rematerialization. Nothing reads the flag any more, so the reset goes too. TheFIXMEabout restoring both registers stays.
The new stress test, wasm-js-to-wasm-ic-materializes-tag-registers.js, builds two small Wasm modules by hand. The first is a trivial identity callee of type T → T. The second is a trigger function that keeps ten i64 locals live across a call to an imported JS function. That pressure forces OMG to allocate one of them into x27/x28. The test links the import's call site to the callee's IC, tiers trigger up to OMG, then feeds non-cell values (undefined, 13.37, null, true) through the chain. It asserts that the i64 and funcref arms both send these values to the slow path and produce the same result the non-optimizing tiers would.
Background
Tagged JSValues.
On 64-bit platforms, JavaScriptCore packs every JS value into a single 64-bit word using NaN-boxing. Pointers to heap objects ("cells") have their upper tag bits clear. Int32s carry a fixed number tag in the high bits. Doubles are stored with an added offset so they never collide with pointers. undefined, null, and booleans are small immediate bit patterns. A value is a cell exactly when value & NotCellMask is zero.
Tag registers.
Tag checks run on nearly every JIT fast path, so JSC keeps the two constants NumberTag and NotCellMask in two reserved callee-save registers, GPRInfo::numberTagRegister and GPRInfo::notCellMaskRegister. On ARM64, notCellMaskRegister is x28. JS-tier code can then test a value against a register instead of materializing a 64-bit immediate each time.
TagRegistersMode.
Helpers such as branchIfNotCell, branchIfNotInt32, and branchIfNotNumber take a TagRegistersMode argument. In HaveTagRegisters mode, the default, they read the registers. In DoNotHaveTagRegisters mode they encode the masks as immediates. emitMaterializeTagCheckRegisters() is the helper that reloads the constants into the registers when a stub cannot assume they are already set.
Callee-save registers and tail calls.
Callee-save registers survive a call because the callee spills them in its prologue and restores them before returning. A tail call restores the current frame's callee-saves and then jumps directly to the target instead of returning. The target therefore sees whatever values were in those registers when the tail-calling frame was entered. In JS, strict-mode functions are eligible for proper tail calls, which JSC implements via op_tail_call.
Wasm execution tiers. JSC compiles Wasm in tiers. BBQ is the baseline Wasm JIT, and OMG is the optimizing tier built on the B3 backend. Inside Wasm code, the registers JS treats as reserved are not pinned, so OMG's register allocator is free to place ordinary Wasm values in them. Crossings between Wasm and JS go through thunks. An exit thunk handles a Wasm function calling an imported JS function.
The JS-to-Wasm IC.
When JS calls an exported Wasm function, the call site can be linked to a per-signature stub produced by RTT::jsToWasmICEntrypoint(). The generator loops over the Wasm parameters in reverse order and emits one switch arm per parameter type. Each arm inline-checks the JSValue, unboxes it, and stores it into the Wasm argument register or stack slot. A failed check branches to a slow path that performs the full ToWebAssemblyValue conversion, including throwing the appropriate TypeError. The arms relevant here are I32, I64 (expects a BigInt), F32/F64, and reference types such as funcref.
Analysis
This is a missing invariant re-establishment at a JIT entrypoint. A cell check reads a reserved register that some callers can deliver stale, so the type check is bypassed and a non-cell JSValue is dereferenced as a JSCell*.
OMG wasm "trigger" exit thunk JS imp() (baseline, strict) JS-to-Wasm IC
x28 := live i64 ─────► x28 untouched ──► prologue spills x28 ─► tail call restores x28 ─►┐
│
Before (I64 / funcref arm): After: ▼
branchIfNotCell(v) branchIfNotCell(v, DoNotHaveTagRegisters)
└─► v & x28 (x28 == 0 → "cell") └─► v & #NotCellMask → non-cell
└─► load8 [v + 5] (I64) └─► slowPath (ToWebAssemblyValue)
└─► load32 [v + 0] (funcref)
The left half of the diagram shows how the bad register value reaches the stub. The right half shows what the stub does with it. The column pair at the bottom contrasts the old and new check.
Start with the generator's assumption. haveTagRegisters lives at emission time and records whether the generator has already emitted a materialization in this stub. It tells you nothing about the register contents at run time. That would be fine if every arm reading the registers consulted the flag. The I32 and F32/F64 arms did. The I64 and funcref arms did not, and both still emitted branchIfNotCell in HaveTagRegisters mode. Because the loop runs backwards over the parameters, the first arm emitted is the one for the last parameter. If that parameter is i64 or funcref, or if no earlier-emitted arm has materialized the registers, the cell check reads whatever notCellMaskRegister holds at IC entry. A Wasm signature with a single i64 or funcref parameter, which is exactly what the test's callee uses, never materializes the registers at all.
Next, the attacker's control over that entry state. The test builds the chain in the diagram's top row:
trigger, tiered up to OMG, keeps ten i64 locals live acrosscall $imp. Under that register pressure OMG allocates one of them into x27/x28. x28 is not pinned in Wasm, so it can hold an ordinary Wasm value there.- The Wasm-to-JS exit thunk calls the JS import
impand leaves x28 as it is. impruns in the baseline JS tier. Its prologue treats x28 as a callee-save and spills the stale value into its frame.impis strict mode, soreturn callee(x)compiles toop_tail_call. The tail call restores the frame's callee-saves, putting the stale x28 back, and far-jumps intocallee's monomorphically linked JS-to-Wasm IC.- The IC's I64 or funcref arm runs
branchIfNotCellagainstvalue & x28. The globals feeding the live locals are all0, so the mask is zero. Every JSValue then reads as "cell".
Steps 2 through 4 are the important part. No single component misbehaves in isolation. The exit thunk was never responsible for restoring x28. The baseline prologue correctly preserves callee-saves. The tail call correctly restores them. The composition of these steps carries a Wasm-owned register value into a JS-tier stub that assumed a clean entry state, and the stub was the one place that needed to re-establish its own invariant.
Once the cell check is bypassed, the arms diverge in what they dereference. In the I64 arm, branchIfNotHeapBigInt loads the cell's type byte, which per the test is load8 [rawBits + 5], where rawBits is the NaN-boxed encoding of undefined, 13.37, null, or true. In the funcref arm, emitLoadStructure loads a structure ID via load32 [rawBits + 0] and then dereferences the decoded Structure to read classInfoOffset(). In both cases the outcome is a wild read at an address derived from the attacker-chosen JSValue encoding. The test marks true as the sharpest witness for the I64 arm. On the slow path ToBigInt(true) legitimately yields 1n, so the correct answer is "1", yet the unfixed fast path still crashes because it treats the boolean's bits as a pointer.
The bug is reachable from ordinary web content: Wasm modules, an imported JS function, a strict-mode tail call, and enough iterations to link the IC and tier the caller up to OMG. All of this happens inside the WebContent process. When the computed address is unmapped, which is the default case for small immediate encodings like undefined and booleans, the result is a reliable renderer crash.
Escalation beyond the crash is conditional, and the ceilings differ by arm. The I64 arm could only proceed to toBigInt64 on a forged "HeapBigInt" if the byte read at the type offset happened to equal HeapBigIntType. That would turn the bug into a read of BigInt digit storage through an attacker-influenced pointer, an info-leak-class ceiling. The funcref arm is stronger in principle. If its downstream class-info and RTT checks could be satisfied against attacker-shaped memory, the forged value would reach Wasm as a funcref, which is a fake-object-class consequence inside the renderer. That depends on those downstream checks being satisfiable and on address knowledge the bug does not supply by itself. Whatever the ceiling, the impact stays inside the renderer sandbox, and reaching beyond it would require a separate escape.
The fix restores the invariant by removing the stub's dependency on the register rather than by adding the two missing materializeTagRegistersIfNeeded() calls. With DoNotHaveTagRegisters, every check in the switch tests against immediate masks, so the stub's soundness no longer depends on how the caller arrived. This also makes the scratch-reuse case in the I64 arm safe by construction. Borrowing numberTagRegister for toBigInt64 previously meant later arms had to remember to rematerialize, and now no later arm reads it.
A strict-mode tail call can carry an OMG-clobbered notCellMaskRegister into the IC, where a zero mask lets undefined, doubles, and booleans pass as cell pointers.
Insight
When a code generator tracks machine state with an emission-time "already materialized" boolean, the robust fix is to delete the dependency, for example with immediate masks, rather than patch the call sites that forgot the guard.
Audit directions
-
Stubs that read reserved registers at entrypoints reachable with stale state. Invariant: every code path into a stub either re-establishes or does not read engine-reserved registers. Narrow: grep
Source/JavaScriptCore/wasm/js/(WasmToJS.cpp,JSToWasm.cpp,WebAssemblyFunction*) and the Wasm thunk generators forbranchIfNotCell(,branchIfInt32(,branchIfNotNumber(,boxInt32(andboxDouble(calls in defaultHaveTagRegistersmode. A match is any such call in a stub reachable from Wasm, from a tail call, or from an exit thunk without a dominatingemitMaterializeTagCheckRegisters(). Wider: audit every stub reachable viaop_tail_callor a far-jump from JS into Wasm, or the reverse, for other reserved registers such as the Wasm context instance pointer or the memory base and bounds registers. The tell is a stub that reads such a register without first loading it from a trusted slot. Widest: any engine with tier-specific reserved registers faces the same question at its tier boundaries. Examples are V8's root register and pointer-compression cage base, and SpiderMonkey's wasmInstanceReg/HeapReg. -
Emission-time "materialized once" flags that only some consumers consult. Invariant: cached-register state must be enforced at the consumer, not by convention at each producer site. Narrow: search JSC's
jit/,wasm/, andftl/for localbool have*flags and*IfNeededlambdas guarding register materialization. Check whether every switch arm or helper that reads the cached register calls the guard, and whether intervening scratch reuse resets it, as the removedhaveTagRegisters = falsedid. Wider: the same shape appears wherever a baseline compiler caches loaded values across emitted code, such as cached instance, memory-start, or constant registers. V8 Liftoff's cache state for the instance and memory start is a comparable mechanism worth reviewing. Widest: for any lazily initialized resource, ask whether some path reaches the consumer while skipping the initializer. The safest fix shape is to remove the dependency, as this patch does with immediates. -
Callee-save registers carried across language/tier boundaries via spill-and-restore, especially tail calls. Narrow: enumerate which callee-saved registers OMG/B3 may allocate inside Wasm that JS tiers treat as reserved. Wider: trace each Wasm-to-JS exit thunk to see whether it restores those registers before running JS code. A match is a reserved JS register that is in Wasm's allocatable set and not reset at the exit thunk. Widest: the same question applies to any engine whose tiers disagree on the reserved-register set. The V8 and SpiderMonkey reserved registers named above are the natural starting points.
-
IC fast paths that dereference a value as a cell right after one register-dependent cell check. Narrow: review the JS-to-Wasm and Wasm-to-JS conversion fast paths, including the funcref, externref, and anyref arms and other
emitLoadStructureusers, for checks whose soundness depends on mutable machine state rather than immediates or trusted memory. A match is a structure or type-byte load guarded only by a check that reads a register not established in the same stub. Wider: these sites are where a defeated guard could turn a crash into a fake-object primitive, so rank findings by what the subsequent loads feed into. Ceiling: this direction is specific to JSC's tag-register design and its JS/Wasm conversion stubs. The cross-engine form of the question is already covered by the first and third directions.