← All reports

RTT::jsToWasmICEntrypoint should use DoNotHaveTagRegisters

HighJavaScriptCore WebAssembly JS-to-Wasm call IC (UninitializedMemory

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

Severity: High | Component: JavaScriptCore WebAssembly JS-to-Wasm call IC (RTT::jsToWasmICEntrypoint in wasm/js/JSToWasm.cpp) | c983da4 | Bugzilla 321609

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

- bool haveTagRegisters = false;
- auto materializeTagRegistersIfNeeded = [&] {
- if (!haveTagRegisters) {
- haveTagRegisters = true;
- jit.emitMaterializeTagCheckRegisters();
- }
- };
...
case Wasm::TypeKind::I32: {
- materializeTagRegistersIfNeeded();
jit.loadValue(jsParam, scratchGPR);
- slowPath.append(jit.branchIfNotInt32(scratchGPR));
+ slowPath.append(jit.branchIfNotInt32(scratchGPR, DoNotHaveTagRegisters));
...
case Wasm::TypeKind::I64: {
jit.loadValue(jsParam, scratchGPR);
- slowPath.append(jit.branchIfNotCell(scratchGPR));
+ slowPath.append(jit.branchIfNotCell(scratchGPR, DoNotHaveTagRegisters));
slowPath.append(jit.branchIfNotHeapBigInt(scratchGPR));
...
if (wasmCallInfo.params[i].location.gpr() == scratch) {
scratch = GPRInfo::numberTagRegister;
// FIXME: In theory this only needs to restore the numberTagRegister not both but this is rare.
- haveTagRegisters = false;
}
...
auto isNull = jit.branchIfNull(scratchGPR);
if (!type.isNullable())
slowPath.append(isNull);
- slowPath.append(jit.branchIfNotCell(scratchGPR));
+ slowPath.append(jit.branchIfNotCell(scratchGPR, DoNotHaveTagRegisters));
 
jit.emitLoadStructure(scratchGPR, scratchGPR);
...
case Wasm::TypeKind::F32:
case Wasm::TypeKind::F64: {
- materializeTagRegistersIfNeeded();
if (!isStack)
scratchFPR = wasmCallInfo.params[i].location.fpr();
 
jit.loadValue(jsParam, scratchGPR);
- slowPath.append(jit.branchIfNotNumber(scratchGPR));
+ slowPath.append(jit.branchIfNotNumber(scratchGPR, DoNotHaveTagRegisters));

JSTests/stress/wasm-js-to-wasm-ic-materializes-tag-registers.js

+// notCellMaskRegister (x28 on ARM64) is not wasm-pinned, so OMG parks a live wasm i64 in it.
+// The wasm->JS exit thunk leaves it alone, the JS callee's baseline prologue spills the stale
+// value into its frame, and a strict-mode tail call restores it before far-jumping into the IC.
+// With notCellMaskRegister == 0 the `value & notCellMask` test says "cell" for every JSValue, so
+// branchIfNotHeapBigInt / emitLoadStructure dereference raw non-cell bits.
...
+ function imp(x) {
+ "use strict";
+ return callee(x); // strict mode -> op_tail_call -> restores the stale callee saves
+ }

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:

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.

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.

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:

  1. trigger, tiered up to OMG, keeps ten i64 locals live across call $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.
  2. The Wasm-to-JS exit thunk calls the JS import imp and leaves x28 as it is.
  3. imp runs in the baseline JS tier. Its prologue treats x28 as a callee-save and spills the stale value into its frame.
  4. imp is strict mode, so return callee(x) compiles to op_tail_call. The tail call restores the frame's callee-saves, putting the stale x28 back, and far-jumps into callee's monomorphically linked JS-to-Wasm IC.
  5. The IC's I64 or funcref arm runs branchIfNotCell against value & x28. The globals feeding the live locals are all 0, 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.

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.