Skip to content
Memory corruption Advisory Advanced CVE-2024-6101

Inappropriate implementation in WebAssembly (CVE-2024-6101)

A debug assertion in V8's Liftoff WebAssembly baseline compiler fails because the calculated stack spill offset diverges from the expected offset during compilation. The reporter shows a crash in a debug build but does not demonstrate any exploitable memory corruption or attacker impact.

ginggilBesel Follow

Originally disclosed on Chrome VRP

Bounty$7,000 High View original
  • Fix shipped in 19 days

Security Bug

Important: Please do not change the component of this bug manually.

Please READ THIS FAQ before filing a bug: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/security/faq.md

Please see the following link for instructions on filing security bugs: https://www.chromium.org/Home/chromium-security/reporting-security-bugs

Reports may be eligible for reward payments under the Chrome VRP: https://g.co/chrome/vrp

NOTE: Security bugs are normally made public once a fix has been widely deployed.


VULNERABILITY DETAILS

DCHECK falling is because the calculated offset upper that the expected.

Expected offset: 80, Calculated offset: 80
Expected offset: 88, Calculated offset: 88
Expected offset: 112, Calculated offset: 112
Expected offset: 112, Calculated offset: 128

#ifdef ENABLE_SLOW_DCHECKS
bool LiftoffAssembler::ValidateCacheState() const {
  uint32_t register_use_count[kAfterMaxLiftoffRegCode] = {0};
  LiftoffRegList used_regs;
  int offset = StaticStackFrameSize();
  for (const VarState& var : cache_state_.stack_state) {
    // Check for continuous stack offsets.
    offset = NextSpillOffset(var.kind(), offset);
    // Add logging here
    std::cout << "Expected offset: " << var.offset() << ", Calculated offset: " << offset << std::endl;
    DCHECK_EQ(offset, var.offset());           // [1] 
    if (!var.is_reg()) continue;
    LiftoffRegister reg = var.reg();
    if ((kNeedI64RegPair || kNeedS128RegPair) && reg.is_pair()) {
[...]

the discrepancy occurs during the last NextSpillOffset calculation, where the Calculated offset becomes 128, but the Expected offset remains 112. This suggests that there might be an issue with the NextSpillOffset function

After NextSpillOffset: offset = 128, Expected offset: 112
Expected offset: 112, Calculated offset: 128

I also can't find what kind of var.kind() after running the poc. I think is not properly printed.

[1] https://source.chromium.org/chromium/chromium/src/+/main:v8/src/wasm/baseline/liftoff-assembler.cc;drc=b2df50672c06c070ecb137570d1072a3835ac4ca;l=1096


VERSION Chrome Version: [x.x.x.x] + [stable, beta, or dev] Operating System: [Please indicate OS, version, and service pack level]

REPRODUCTION CASE

  1. Please use linux_asan_d8_v8_arm64_dbg or
is_asan = true
is_clang = true
is_component_build = true
is_debug = true
is_lsan = true
target_cpu = "x64"
v8_enable_backtrace = true
v8_enable_google_benchmark = true
v8_enable_slow_dchecks = true
v8_enable_test_features = true
v8_target_cpu = "arm64"
  1. run ./d8 --wasm-staging poc.js

FOR CRASHES, PLEASE INCLUDE THE FOLLOWING ADDITIONAL INFORMATION

Type of crash: v8

#
# Fatal error in ../../src/wasm/baseline/liftoff-assembler.cc, line 1096
# Debug check failed: offset == var.offset() (128 vs. 112).
#
#
#
#FailureMessage Object: 0x7c724963e460
==== C stack trace ===============================

    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(___interceptor_backtrace+0x46) [0x59516e693b66]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8_libbase.so(v8::base::debug::StackTrace::StackTrace()+0x13) [0x7c724cde4c83]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8_libplatform.so(+0x3177a) [0x7c724cd3f77a]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8_libbase.so(V8_Fatal(char const*, int, char const*, ...)+0x288) [0x7c724cdaf3b8]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8_libbase.so(+0x514df) [0x7c724cdae4df]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::wasm::LiftoffAssembler::ValidateCacheState() const+0x371) [0x7c7253f02011]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(+0x7125a45) [0x7c7253f25a45]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(+0x7112efe) [0x7c7253f12efe]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::wasm::ExecuteLiftoffCompilation(v8::internal::wasm::CompilationEnv*, v8::internal::wasm::FunctionBody const&, v8::internal::wasm::LiftoffOptions const&)+0x954) [0x7c7253f0d7d4]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::wasm::WasmCompilationUnit::ExecuteFunctionCompilation(v8::internal::wasm::CompilationEnv*, v8::internal::wasm::WireBytesStorage const*, v8::internal::Counters*, v8::internal::wasm::WasmFeatures*)+0xb00) [0x7c7254110ec0]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::wasm::WasmCompilationUnit::ExecuteCompilation(v8::internal::wasm::CompilationEnv*, v8::internal::wasm::WireBytesStorage const*, v8::internal::Counters*, v8::internal::wasm::WasmFeatures*)+0x33f) [0x7c725410f6ff]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::wasm::CompileLazy(v8::internal::Isolate*, v8::internal::Tagged<v8::internal::WasmTrustedInstanceData>, int)+0x858) [0x7c72541a8558]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(+0x709faed) [0x7c7253e9faed]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Runtime_WasmCompileLazy(int, unsigned long*, v8::internal::Isolate*)+0x1da) [0x7c7253e9ecaa]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Simulator::DoRuntimeCall(v8::internal::Instruction*)+0x847) [0x7c72548b25f7]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Simulator::ExecuteInstruction()+0x213) [0x7c72548b0b53]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Simulator::Run()+0x288) [0x7c72548b0688]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Simulator::CheckPCSComplianceAndRun()+0x3de) [0x7c72548add0e]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Simulator::CallImpl(unsigned long, v8::internal::Simulator::CallArgument*)+0x607) [0x7c72548ad0b7]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(+0x4649e3d) [0x7c7251449e3d]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Execution::CallScript(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSFunction>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>)+0x5fd) [0x7c725144da8d]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::Script::Run(v8::Local<v8::Context>, v8::Local<v8::Data>)+0xb52) [0x7c7250997c02]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(v8::Shell::ExecuteString(v8::Isolate*, v8::Local<v8::String>, v8::Local<v8::String>, v8::Shell::ReportExceptions, v8::Global<v8::Value>*)+0xf9e) [0x59516e75e1ce]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(v8::SourceGroup::Execute(v8::Isolate*)+0x474) [0x59516e78bee4]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(v8::Shell::RunMainIsolate(v8::Isolate*, bool)+0x2fc) [0x59516e796afc]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(v8::Shell::RunMain(v8::Isolate*, bool)+0x2a5) [0x59516e795f55]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(v8::Shell::Main(int, char**)+0x176a) [0x59516e799d6a]
    /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7c724b029d90]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7c724b029e40]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(_start+0x2a) [0x59516e64f2ca]
AddressSanitizer:DEADLYSIGNAL
=================================================================
==1105290==ERROR: AddressSanitizer: TRAP on unknown address 0x000000000000 (pc 0x7c724cddfe2f bp 0x7ffc88e59af0 sp 0x7ffc88e59af0 T0)
SCARINESS: 10 (signal)

bisect: https://chromium-review.googlesource.com/c/v8/v8/+/4224507

The original report as published on the Chromium issue tracker, by @ginggilBesel. 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. 8 min read.

Context

This report concerns V8's WebAssembly baseline compiler, Liftoff, as shipped in Google Chrome. Liftoff compiles a Wasm function body to machine code while tracking the location of every value on the interpreter-style value stack. Values live either in registers or in spill slots on the native stack, and the assembler keeps a cache state that records, for each stack entry, whether it is in a register and at which stack offset it is spilled. The helper NextSpillOffset computes the next free spill offset for a given value kind, and a debug-only consistency check, ValidateCacheState, walks the cache state and asserts that the recorded offset of each value matches the offset recomputed by NextSpillOffset.

The bug is filed as an inappropriate implementation in WebAssembly, tracked as CVE-2024-6101, rated high severity, with a bounty of 7000.00 USD under the Chrome VRP. It was disclosed on 2024-06-18.

Setup

The crash is reproduced with a debug build of d8, V8's standalone shell, configured for ARM64 code generation on an x64 host with slow DCHECKs enabled. The reporter gives two options: use the prebuilt linux_asan_d8_v8_arm64_dbg binary, or build with the following GN arguments:

Text
is_asan = true
is_clang = true
is_component_build = true
is_debug = true
is_lsan = true
target_cpu = "x64"
v8_enable_backtrace = true
v8_enable_google_benchmark = true
v8_enable_slow_dchecks = true
v8_enable_test_features = true
v8_target_cpu = "arm64"

The build enables slow DCHECKs and targets ARM64 code generation on an x64 host. The proof of concept is a JavaScript file, poc.js, run against the shell with the Wasm staging features enabled.

Finding it

The reporter instrumented ValidateCacheState to print the expected and calculated offsets for every entry in the cache state, and observed that the two diverge on the last entry:

Text
Expected offset: 80, Calculated offset: 80
Expected offset: 88, Calculated offset: 88
Expected offset: 112, Calculated offset: 112
Expected offset: 112, Calculated offset: 128

The first three entries agree. On the fourth, the offset stored in the VarState is 112, but the value recomputed by NextSpillOffset is 128. The reporter narrows this down to the final NextSpillOffset call, where the calculated offset jumps to 128 while the expected offset stays at 112:

Text
After NextSpillOffset: offset = 128, Expected offset: 112
Expected offset: 112, Calculated offset: 128

This points at NextSpillOffset itself, or at the way the value kind is handled when computing the next spill slot. The reporter also notes that the value of var.kind() could not be determined from the proof of concept, and suspects it is not printed properly, so the exact kind that triggers the mismatch is not identified in the report.

The check that fires is in liftoff-assembler.cc, at the line the reporter links to in the Chromium source browser (revision [redacted], line 1096). The instrumented excerpt is:

Text
#ifdef ENABLE_SLOW_DCHECKS
bool LiftoffAssembler::ValidateCacheState() const {
  uint32_t register_use_count[kAfterMaxLiftoffRegCode] = {0};
  LiftoffRegList used_regs;
  int offset = StaticStackFrameSize();
  for (const VarState& var : cache_state_.stack_state) {
    // Check for continuous stack offsets.
    offset = NextSpillOffset(var.kind(), offset);
    // Add logging here
    std::cout << "Expected offset: " << var.offset() << ", Calculated offset: " << offset << std::endl;
    DCHECK_EQ(offset, var.offset());           // [1]
    if (!var.is_reg()) continue;
    LiftoffRegister reg = var.reg();
    if ((kNeedI64RegPair || kNeedS128RegPair) && reg.is_pair()) {
[...]

Exploitation

Step 1: build or obtain the debug shell

Use linux_asan_d8_v8_arm64_dbg, or build d8 with the GN arguments shown above. The build must have slow DCHECKs enabled, since the failing check lives inside an ENABLE_SLOW_DCHECKS block.

Step 2: run the proof of concept

Bash
./d8 --wasm-staging poc.js

The proof of concept is run with --wasm-staging. The script itself is not included in the report.

Step 3: observe the crash

The shell aborts on the failed debug check. The fatal error names the file and line, and reports the two offsets:

Text
#
# Fatal error in ../../src/wasm/baseline/liftoff-assembler.cc, line 1096
# Debug check failed: offset == var.offset() (128 vs. 112).
#
#
#
#FailureMessage Object: 0x7c724963e460
==== C stack trace ===============================

    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(___interceptor_backtrace+0x46) [0x59516e693b66]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8_libbase.so(v8::base::debug::StackTrace::StackTrace()+0x13) [0x7c724cde4c83]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8_libplatform.so(+0x3177a) [0x7c724cd3f77a]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8_libbase.so(V8_Fatal(char const*, int, char const*, ...)+0x288) [0x7c724cdaf3b8]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8_libbase.so(+0x514df) [0x7c724cdae4df]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::wasm::LiftoffAssembler::ValidateCacheState() const+0x371) [0x7c7253f02011]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(+0x7125a45) [0x7c7253f25a45]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(+0x7112efe) [0x7c7253f12efe]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::wasm::ExecuteLiftoffCompilation(v8::internal::wasm::CompilationEnv*, v8::internal::wasm::FunctionBody const&, v8::internal::wasm::LiftoffOptions const&)+0x954) [0x7c7253f0d7d4]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::wasm::WasmCompilationUnit::ExecuteFunctionCompilation(v8::internal::wasm::CompilationEnv*, v8::internal::WireBytesStorage const*, v8::internal::Counters*, v8::internal::wasm::WasmFeatures*)+0xb00) [0x7c7254110ec0]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::wasm::WasmCompilationUnit::ExecuteCompilation(v8::internal::wasm::CompilationEnv*, v8::internal::WireBytesStorage const*, v8::internal::Counters*, v8::internal::wasm::WasmFeatures*)+0x33f) [0x7c725410f6ff]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::wasm::CompileLazy(v8::internal::Isolate*, v8::internal::Tagged<v8::internal::WasmTrustedInstanceData>, int)+0x858) [0x7c72541a8558]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(+0x709faed) [0x7c7253e9faed]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Runtime_WasmCompileLazy(int, unsigned long*, v8::internal::Isolate*)+0x1da) [0x7c7253e9ecaa]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Simulator::DoRuntimeCall(v8::internal::Instruction*)+0x847) [0x7c72548b25f7]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Simulator::ExecuteInstruction()+0x213) [0x7c72548b0b53]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Simulator::Run()+0x288) [0x7c72548b0688]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Simulator::CheckPCSComplianceAndRun()+0x3de) [0x7c72548add0e]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Simulator::CallImpl(unsigned long, v8::internal::Simulator::CallArgument*)+0x607) [0x7c72548ad0b7]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(+0x4649e3d) [0x7c7251449e3d]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Execution::CallScript(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSFunction>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>)+0x5fd) [0x7c725144da8d]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::Script::Run(v8::Local<v8::Context>, v8::Local<v8::Data>)+0xb52) [0x7c7250997c02]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(v8::Shell::ExecuteString(v8::Isolate*, v8::Local<v8::String>, v8::Local<v8::String>, v8::Shell::ReportExceptions, v8::Global<v8::Value>*)+0xf9e) [0x59516e75e1ce]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(v8::SourceGroup::Execute(v8::Isolate*)+0x474) [0x59516e78bee4]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(v8::Shell::RunMainIsolate(v8::Isolate*, bool)+0x2fc) [0x59516e796afc]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(v8::Shell::RunMain(v8::Isolate*, bool)+0x2a5) [0x59516e795f55]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(v8::Shell::Main(int, char**)+0x176a) [0x59516e799d6a]
    /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7c724b029d90]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7c724b029e40]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(_start+0x2a) [0x59516e64f2ca]
AddressSanitizer:DEADLYSIGNAL
=================================================================
==1105290==ERROR: AddressSanitizer: TRAP on unknown address 0x000000000000 (pc 0x7c724cddfe2f bp 0x7ffc88e59af0 sp 0x7ffc88e59af0 T0)
SCARINESS: 10 (signal)

The stack shows the path from script execution through Execution::CallScript and Script::Run, into the simulator, then Runtime_WasmCompileLazy and CompileLazy, which is where a Wasm function is compiled on first call. From there it enters WasmCompilationUnit::ExecuteCompilation, ExecuteFunctionCompilation and ExecuteLiftoffCompilation, and finally LiftoffAssembler::ValidateCacheState, where the debug check fails. The AddressSanitizer output that follows is the trap raised by the fatal error, not a separate memory-safety finding.

The reporter records the crash type as v8.

Root cause

The report identifies the mismatch as originating in the calculation of the next spill offset: the recorded VarState offset for the last stack entry is 112, while NextSpillOffset computes 128 for the same entry. Because ValidateCacheState recomputes offsets by chaining NextSpillOffset over the stack state, any disagreement between the offset assigned when the value was spilled and the offset recomputed later means the two code paths treat the value's kind, or its slot size, differently. The reporter's conclusion is that there is likely an issue in NextSpillOffset. The exact value kind involved is not established in the report, since the reporter could not get var.kind() to print.

The report also includes a bisect link to a V8 change, https://chromium-review.googlesource.com/c/v8/v8/+/4224507. The report does not describe what that change does.

In a release build the DCHECK_EQ and the surrounding ENABLE_SLOW_DCHECKS block are compiled out, so the inconsistency would not abort the process. What the mismatched offset would mean for generated code in that configuration is not analysed in the report.

Impact

The report is a debug-check failure in the Liftoff assembler, reached by compiling a Wasm module under --wasm-staging on the ARM64 backend. The platform records it as a high-severity inappropriate implementation in WebAssembly with a 7000.00 USD bounty. The report itself does not describe a memory-corruption primitive, an information leak, or a path from the mismatch to attacker-controlled behaviour in a release build; it documents the failed invariant and the conditions under which it fires.

Fix

The report does not state which change fixed the issue.

Variants to test

  1. Run the same poc.js with --wasm-staging on other Liftoff backends (x64, ia32, arm) in a debug build with v8_enable_slow_dchecks = true. A positive result is the same Debug check failed: offset == var.offset() fatal error with differing offsets.
  2. Instrument ValidateCacheState to print var.kind() alongside the offsets, as the reporter intended, and rerun the proof of concept. A positive result identifies the value kind whose slot size differs between the spill path and NextSpillOffset.
  3. Exercise Wasm functions that mix register-pair values (i64 and s128, which use kNeedI64RegPair and kNeedS128RegPair) with other stack values, since the validation loop branches on register pairs. A positive result is a mismatch appearing only when a pair-typed value is on the stack.
  4. Build at revisions on either side of the bisected change and run the same module. A positive result is the check failing on one side and passing on the other, confirming the introducing commit.

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. 18 min read.

What happened, in plain words

Google Chrome runs JavaScript, and it also runs WebAssembly (Wasm), a second language that browsers can execute. The part of Chrome that turns Wasm into instructions the processor understands is called V8, and inside V8 there is a compiler called Liftoff. Liftoff is the fast, simple compiler: it translates a Wasm function into machine code the first time that function is called.

While Liftoff translates a function, it has to keep track of where every value lives. A value can sit in a register (a small, very fast storage slot inside the processor) or it can be "spilled" to the native stack (a region of memory used as a scratch pad). The compiler keeps a record, called the cache state, of which value is where. A small helper function, NextSpillOffset, works out the next free position on that scratch pad for a value of a given kind. In debug builds only, a consistency check called ValidateCacheState walks the record and confirms that the position stored for each value matches the position NextSpillOffset would compute for it.

In this report, that check fails. For the last value on the stack, the stored position is 112, but NextSpillOffset computes 128. The reporter traced this to the NextSpillOffset calculation and filed it as an inappropriate implementation in WebAssembly. The platform tracks it as CVE-2024-6101, rates it high severity, and paid a bounty of 7000.00 USD under the Chrome VRP. It was disclosed on 2024-06-18.

A few terms used above, explained from zero:

  • WebAssembly (Wasm): a compact language that browsers can run alongside JavaScript, often used for games, video tools and other heavy programs. A browser downloads a Wasm module and the engine compiles it to machine code.
  • Compiler: a program that translates code written by a person into instructions the processor can execute.
  • Register: a tiny storage location inside the processor, much faster than ordinary memory but limited in number.
  • Stack: a region of memory used to hold temporary values and bookkeeping while a program runs. "Spilling" means moving a value out of a register into the stack because the register is needed for something else.
  • Debug build: a version of a program built with extra checks and logging that are removed from the version shipped to users. The checks are there to catch mistakes during development.
  • DCHECK: a "debug check", an assertion that is only compiled into debug builds. If the condition is false, the program stops immediately with a fatal error.
  • CVE: a public identifier for a known security flaw, so that people can refer to it unambiguously.
  • Bounty: a payment a company makes to someone who reports a security problem to it.
  • Chrome VRP: Google's Vulnerability Reward Program, the scheme under which Chrome security reports are rewarded.

Context

This report concerns V8's WebAssembly baseline compiler, Liftoff, as shipped in Google Chrome. Liftoff compiles a Wasm function body to machine code while tracking the location of every value on the interpreter-style value stack. Values live either in registers or in spill slots on the native stack, and the assembler keeps a cache state that records, for each stack entry, whether it is in a register and at which stack offset it is spilled. The helper NextSpillOffset computes the next free spill offset for a given value kind, and a debug-only consistency check, ValidateCacheState, walks the cache state and asserts that the recorded offset of each value matches the offset recomputed by NextSpillOffset.

The bug is filed as an inappropriate implementation in WebAssembly, tracked as CVE-2024-6101, rated high severity, with a bounty of 7000.00 USD under the Chrome VRP. It was disclosed on 2024-06-18.

Two more ideas from that paragraph, in everyday terms:

  • Baseline compiler: the first, quick compiler an engine uses. It does not produce the fastest code, but it produces code quickly, so a program can start running without waiting for a slower, more optimising compiler. Liftoff is V8's baseline compiler for Wasm.
  • Inappropriate implementation: a category for bugs where the code does something other than what the design intended, as opposed to, say, a buffer overflow. Here the bookkeeping about where values are stored disagrees with itself.

Setup

The crash is reproduced with a debug build of d8, V8's standalone shell, configured for ARM64 code generation on an x64 host with slow DCHECKs enabled. The reporter gives two options: use the prebuilt linux_asan_d8_v8_arm64_dbg binary, or build with the following GN arguments:

Text
is_asan = true
is_clang = true
is_component_build = true
is_debug = true
is_lsan = true
target_cpu = "x64"
v8_enable_backtrace = true
v8_enable_google_benchmark = true
v8_enable_slow_dchecks = true
v8_enable_test_features = true
v8_target_cpu = "arm64"

What each line means, in plain words:

  • is_asan = true: turn on AddressSanitizer, a tool that watches memory accesses and reports suspicious ones. It is a development aid, not part of the shipped browser.
  • is_clang = true: use the Clang compiler to build the code.
  • is_component_build = true: build the program as several separate shared libraries rather than one big file. This makes rebuilds faster.
  • is_debug = true: build the debug version, which includes the extra checks such as DCHECK.
  • is_lsan = true: turn on LeakSanitizer, a companion tool that reports memory that was allocated and never freed.
  • target_cpu = "x64": the machine that will run the build is an ordinary 64-bit Intel/AMD machine.
  • v8_enable_backtrace = true: include support for printing a stack trace when something goes wrong.
  • v8_enable_google_benchmark = true: include the benchmarking support used by V8's own performance tests.
  • v8_enable_slow_dchecks = true: include the expensive debug checks. This is the flag that matters most here, because the failing check lives inside an ENABLE_SLOW_DCHECKS block.
  • v8_enable_test_features = true: include features that exist only for testing.
  • v8_target_cpu = "arm64": generate code for the ARM64 processor family, even though the build runs on an x64 machine. The build generates ARM64 code even though it runs on an x64 machine.

The relevant flags are is_debug and v8_enable_slow_dchecks, which enable the expensive validation code that catches the inconsistency, and v8_target_cpu = "arm64", which selects the ARM64 Liftoff backend. The proof of concept is a JavaScript file, poc.js, run against the shell with the Wasm staging features enabled.

A note on the two processor families: x64 is the instruction set used by most desktop and laptop processors from Intel and AMD. ARM64 is the instruction set used by many phones and by recent Apple laptops. A build can run on one and produce code for the other, which is what target_cpu and v8_target_cpu arrange here. d8 is V8's own small command-line program, a way to run JavaScript and Wasm without a whole browser around it.

Finding it

The reporter instrumented ValidateCacheState to print the expected and calculated offsets for every entry in the cache state, and observed that the two diverge on the last entry:

Text
Expected offset: 80, Calculated offset: 80
Expected offset: 88, Calculated offset: 88
Expected offset: 112, Calculated offset: 112
Expected offset: 112, Calculated offset: 128

"Instrumented" means the reporter added a few lines of printing code to the function so it would report what it was doing. Each line of output is one entry on the value stack. The first number is the position the compiler recorded when it stored the value; the second is the position the check recomputes now. The first three entries agree. On the fourth, the offset stored in the VarState is 112, but the value recomputed by NextSpillOffset is 128. The reporter narrows this down to the final NextSpillOffset call, where the calculated offset jumps to 128 while the expected offset stays at 112:

Text
After NextSpillOffset: offset = 128, Expected offset: 112
Expected offset: 112, Calculated offset: 128

This points at NextSpillOffset itself, or at the way the value kind is handled when computing the next spill slot. The reporter also notes that the value of var.kind() could not be determined from the proof of concept, and suspects it is not printed properly, so the exact kind that triggers the mismatch is not identified in the report.

A VarState is the record for one value on the stack: it says whether the value is in a register and, if it has been spilled, at which offset. The "kind" is the type of the value, for example a 32-bit integer, a 64-bit integer or a 128-bit vector. Different kinds take different amounts of space, which is why the kind matters when computing the next free offset.

The check that fires is in liftoff-assembler.cc, at the line the reporter links to in the Chromium source browser (revision [redacted], line 1096). The instrumented excerpt is:

Text
#ifdef ENABLE_SLOW_DCHECKS
bool LiftoffAssembler::ValidateCacheState() const {
  uint32_t register_use_count[kAfterMaxLiftoffRegCode] = {0};
  LiftoffRegList used_regs;
  int offset = StaticStackFrameSize();
  for (const VarState& var : cache_state_.stack_state) {
    // Check for continuous stack offsets.
    offset = NextSpillOffset(var.kind(), offset);
    // Add logging here
    std::cout << "Expected offset: " << var.offset() << ", Calculated offset: " << offset << std::endl;
    DCHECK_EQ(offset, var.offset());           // [1]
    if (!var.is_reg()) continue;
    LiftoffRegister reg = var.reg();
    if ((kNeedI64RegPair || kNeedS128RegPair) && reg.is_pair()) {
[...]

Line by line:

  • #ifdef ENABLE_SLOW_DCHECKS: everything until the matching #endif is only compiled in when slow debug checks are enabled. In a normal build this whole function disappears.
  • bool LiftoffAssembler::ValidateCacheState() const {: the start of the checking function. It belongs to the Liftoff assembler and returns true or false.
  • uint32_t register_use_count[kAfterMaxLiftoffRegCode] = {0};: an array that counts how many times each register is used, all starting at zero.
  • LiftoffRegList used_regs;: a list of registers that are in use.
  • int offset = StaticStackFrameSize();: the starting position on the stack, the size of the fixed part of the frame.
  • for (const VarState& var : cache_state_.stack_state) {: walk through every recorded value on the stack, one at a time.
  • offset = NextSpillOffset(var.kind(), offset);: ask the helper where the next value of this kind would go, given the current position.
  • std::cout << ...: the reporter's added printing, showing the recorded offset and the recomputed one side by side.
  • DCHECK_EQ(offset, var.offset());: the actual check. If the recomputed offset and the recorded offset differ, the program stops with a fatal error. The // [1] is the reporter's marker linking to the source line.
  • if (!var.is_reg()) continue;: if this value is not in a register, skip the rest of the loop body and move to the next value.
  • LiftoffRegister reg = var.reg();: fetch the register that holds this value.
  • if ((kNeedI64RegPair || kNeedS128RegPair) && reg.is_pair()) {: on some targets a 64-bit or 128-bit value needs a pair of registers rather than one. This branch handles that case.
  • [...]: the reporter cut the rest of the function out of the excerpt.

Exploitation

Step 1: build or obtain the debug shell

Use linux_asan_d8_v8_arm64_dbg, or build d8 with the GN arguments shown above. The build must have slow DCHECKs enabled and target ARM64, because the validation path and the backend that triggers the mismatch are both required.

The check only exists when slow DCHECKs are compiled in. A normal release build of Chrome has neither, so nothing would be noticed there.

Step 2: run the proof of concept

Bash
./d8 --wasm-staging poc.js
  • ./d8: run the d8 shell from the current directory.
  • --wasm-staging: switch on Wasm features that are still being staged, that is, implemented but not yet enabled by default.
  • poc.js: the proof-of-concept script. The script itself is not included in the report.

Step 3: observe the crash

The shell aborts on the failed debug check. The fatal error names the file and line, and reports the two offsets:

Text
#
# Fatal error in ../../src/wasm/baseline/liftoff-assembler.cc, line 1096
# Debug check failed: offset == var.offset() (128 vs. 112).
#
#
#
#FailureMessage Object: 0x7c724963e460
==== C stack trace ===============================

    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(___interceptor_backtrace+0x46) [0x59516e693b66]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8_libbase.so(v8::base::debug::StackTrace::StackTrace()+0x13) [0x7c724cde4c83]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8_libplatform.so(+0x3177a) [0x7c724cd3f77a]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8_libbase.so(V8_Fatal(char const*, int, char const*, ...)+0x288) [0x7c724cdaf3b8]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8_libbase.so(+0x514df) [0x7c724cdae4df]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::wasm::LiftoffAssembler::ValidateCacheState() const+0x371) [0x7c7253f02011]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(+0x7125a45) [0x7c7253f25a45]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(+0x7112efe) [0x7c7253f12efe]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::wasm::ExecuteLiftoffCompilation(v8::internal::wasm::CompilationEnv*, v8::internal::wasm::FunctionBody const&, v8::internal::wasm::LiftoffOptions const&)+0x954) [0x7c7253f0d7d4]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::wasm::WasmCompilationUnit::ExecuteFunctionCompilation(v8::internal::wasm::CompilationEnv*, v8::internal::WireBytesStorage const*, v8::internal::Counters*, v8::internal::wasm::WasmFeatures*)+0xb00) [0x7c7254110ec0]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::wasm::WasmCompilationUnit::ExecuteCompilation(v8::internal::wasm::CompilationEnv*, v8::internal::WireBytesStorage const*, v8::internal::Counters*, v8::internal::wasm::WasmFeatures*)+0x33f) [0x7c725410f6ff]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::wasm::CompileLazy(v8::internal::Isolate*, v8::internal::Tagged<v8::internal::WasmTrustedInstanceData>, int)+0x858) [0x7c72541a8558]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(+0x709faed) [0x7c7253e9faed]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Runtime_WasmCompileLazy(int, unsigned long*, v8::internal::Isolate*)+0x1da) [0x7c7253e9ecaa]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Simulator::DoRuntimeCall(v8::internal::Instruction*)+0x847) [0x7c72548b25f7]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Simulator::ExecuteInstruction()+0x213) [0x7c72548b0b53]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Simulator::Run()+0x288) [0x7c72548b0688]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Simulator::CheckPCSComplianceAndRun()+0x3de) [0x7c72548add0e]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Simulator::CallImpl(unsigned long, v8::internal::Simulator::CallArgument*)+0x607) [0x7c72548ad0b7]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(+0x4649e3d) [0x7c7251449e3d]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::internal::Execution::CallScript(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSFunction>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>)+0x5fd) [0x7c725144da8d]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/libv8.so(v8::Script::Run(v8::Local<v8::Context>, v8::Local<v8::Data>)+0xb52) [0x7c7250997c02]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(v8::Shell::ExecuteString(v8::Isolate*, v8::Local<v8::String>, v8::Local<v8::String>, v8::Shell::ReportExceptions, v8::Global<v8::Value>*)+0xf9e) [0x59516e75e1ce]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(v8::SourceGroup::Execute(v8::Isolate*)+0x474) [0x59516e78bee4]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(v8::Shell::RunMainIsolate(v8::Isolate*, bool)+0x2fc) [0x59516e796afc]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(v8::Shell::RunMain(v8::Isolate*, bool)+0x2a5) [0x59516e795f55]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(v8::Shell::Main(int, char**)+0x176a) [0x59516e799d6a]
    /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7c724b029d90]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7c724b029e40]
    /home/rheza/v8/v8/out/linux_asan_d8_v8_arm64_dbg/d8(_start+0x2a) [0x59516e64f2ca]
AddressSanitizer:DEADLYSIGNAL
=================================================================
==1105290==ERROR: AddressSanitizer: TRAP on unknown address 0x000000000000 (pc 0x7c724cddfe2f bp 0x7ffc88e59af0 sp 0x7ffc88e59af0 T0)
SCARINESS: 10 (signal)

How to read this output:

  • The first lines say what went wrong: a fatal error in liftoff-assembler.cc at line 1096, because the debug check offset == var.offset() was false, with 128 on one side and 112 on the other.
  • ==== C stack trace =============================== introduces the list of function calls that were active when the program stopped. Read it from the bottom upwards: the bottom is the outermost call, the top is where the failure happened.
  • The bottom entries are the C library starting the program (__libc_start_main), then d8's main function, then the shell running the script (Shell::RunMain, Shell::RunMainIsolate, SourceGroup::Execute, Shell::ExecuteString).
  • Above those, Script::Run and Execution::CallScript are V8 running the JavaScript file.
  • The Simulator entries are V8 pretending to be an ARM64 processor while running on an x64 machine. Because the build targets ARM64 but runs on x64, V8 interprets the ARM64 instructions in software.
  • Runtime_WasmCompileLazy and CompileLazy are where a Wasm function is compiled the first time it is called. This is the "lazy" part: compilation is postponed until the function is actually needed.
  • WasmCompilationUnit::ExecuteCompilation, ExecuteFunctionCompilation and ExecuteLiftoffCompilation are the steps that hand the function to Liftoff.
  • LiftoffAssembler::ValidateCacheState is the check that failed.
  • V8_Fatal and the StackTrace entries are the machinery that prints the message and the trace.
  • The AddressSanitizer:DEADLYSIGNAL and ERROR: AddressSanitizer: TRAP lines at the end are the trap raised by the fatal error itself, not a separate memory-safety finding. AddressSanitizer notices that the program stopped abruptly and reports it.

The stack shows the path from script execution through Execution::CallScript and Script::Run, into the simulator, then Runtime_WasmCompileLazy and CompileLazy, which is where a Wasm function is compiled on first call. From there it enters WasmCompilationUnit::ExecuteCompilation, ExecuteFunctionCompilation and ExecuteLiftoffCompilation, and finally LiftoffAssembler::ValidateCacheState, where the debug check fails. The AddressSanitizer output that follows is the trap raised by the fatal error, not a separate memory-safety finding.

The reporter records the crash type as v8.

Root cause

The report identifies the mismatch as originating in the calculation of the next spill offset: the recorded VarState offset for the last stack entry is 112, while NextSpillOffset computes 128 for the same entry. Because ValidateCacheState recomputes offsets by chaining NextSpillOffset over the stack state, any disagreement between the offset assigned when the value was spilled and the offset recomputed later means the two code paths treat the value's kind, or its slot size, differently. The reporter's conclusion is that there is likely an issue in NextSpillOffset. The exact value kind involved is not established in the report, since the reporter could not get var.kind() to print.

In everyday terms: two parts of the same program are doing the same arithmetic and getting different answers. One part, when it stored the value, decided it belonged at position 112. The other part, checking later, works through the stack from the beginning and arrives at 128. Since the check walks the stack in order and adds up the space each value needs, a difference of 16 bytes at the last entry suggests the two paths disagree about how much room one of the values takes. The reporter could not confirm which kind of value caused it.

The report also includes a bisect link to a V8 change, https://chromium-review.googlesource.com/c/v8/v8/+/4224507. The report does not describe what that change does. A "bisect" is a search through the history of a codebase to find the exact change that introduced a behaviour: you test an old version and a new version, then keep halving the range until you land on one commit.

In a release build the DCHECK_EQ and the surrounding ENABLE_SLOW_DCHECKS block are compiled out, so the inconsistency would not abort the process. What the mismatched offset would mean for generated code in that configuration is not analysed in the report.

Impact

The report is a debug-check failure in the Liftoff assembler, reached by compiling a Wasm module under --wasm-staging on the ARM64 backend. The platform records it as a high-severity inappropriate implementation in WebAssembly with a 7000.00 USD bounty. The report itself does not describe a memory-corruption primitive, an information leak, or a path from the mismatch to attacker-controlled behaviour in a release build; it documents the failed invariant and the conditions under which it fires.

An "invariant" is a condition the code assumes is always true. Here the invariant is that the stored offset and the recomputed offset are the same. The check exists to catch the moment that assumption stops holding, before it can cause trouble elsewhere.

Fix

The report does not state which change fixed the issue.

Variants to test

  1. Run the same poc.js with --wasm-staging on other Liftoff backends (x64, ia32, arm) in a debug build with v8_enable_slow_dchecks = true. A positive result is the same Debug check failed: offset == var.offset() fatal error with differing offsets.
  2. Instrument ValidateCacheState to print var.kind() alongside the offsets, as the reporter intended, and rerun the proof of concept. A positive result identifies the value kind whose slot size differs between the spill path and NextSpillOffset.
  3. Exercise Wasm functions that mix register-pair values (i64 and s128, which use kNeedI64RegPair and kNeedS128RegPair) with other stack values, since the validation loop branches on register pairs. A positive result is a mismatch appearing only when a pair-typed value is on the stack.
  4. Build at revisions on either side of the bisected change and run the same module. A positive result is the check failing on one side and passing on the other, confirming the introducing commit.

Glossary

  • AddressSanitizer (ASan): a development tool that watches memory accesses and reports suspicious ones, such as reading or writing outside an allocated block.
  • ARM64: a family of processor instruction sets used in many phones and some laptops.
  • Baseline compiler: the first, quick compiler an engine uses so code can start running without waiting for a slower optimising compiler.
  • Bisect: a search through a codebase's history that halves the range of candidate changes until the one that introduced a behaviour is found.
  • Bounty: a payment made by a company to someone who reports a security problem to it.
  • Cache state: the compiler's record of where each value on the stack currently lives, in a register or at a spill offset.
  • Commit: a single recorded change in a codebase's history.
  • CVE: a public identifier for a known security flaw.
  • d8: V8's standalone command-line shell for running JavaScript and WebAssembly without a full browser.
  • DCHECK: a debug check, an assertion compiled only into debug builds that stops the program if its condition is false.
  • GN: the build configuration tool used to generate V8 and Chromium builds.
  • i64: a 64-bit integer value type in WebAssembly.
  • Inappropriate implementation: a bug category where the code does something other than what the design intended, rather than a memory-safety flaw.
  • Invariant: a condition the code assumes is always true.
  • Lazy compilation: postponing compilation of a function until it is first called.
  • LeakSanitizer (LSan): a development tool that reports memory that was allocated and never freed.
  • Liftoff: V8's baseline compiler for WebAssembly.
  • Machine code: the instructions a processor executes directly.
  • Proof of concept (PoC): a small script or program that demonstrates a bug.
  • Register: a tiny, fast storage location inside the processor.
  • Register pair: two registers used together to hold a value too large for one register, such as a 64-bit or 128-bit value on some targets.
  • s128: a 128-bit vector value type in WebAssembly.
  • Simulator: software inside V8 that interprets instructions for one processor family while running on another.
  • Spill: moving a value out of a register into the stack because the register is needed for something else.
  • Spill offset: the position on the stack where a spilled value is stored.
  • Stack trace: the list of function calls that were active when a program stopped.
  • Staging features: features that are implemented but not yet enabled by default, switched on with a flag for testing.
  • V8: the JavaScript and WebAssembly engine used by Google Chrome.
  • VarState: the record for one value on the compiler's value stack, saying whether it is in a register and at which offset it is spilled.
  • WebAssembly (Wasm): a compact language that browsers can run alongside JavaScript, often used for heavy programs such as games and video tools.
  • x64: the instruction set used by most desktop and laptop processors from Intel and AMD.

More by ginggilBesel

View all

19 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.