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

Type Confusion in V8 (CVE-2024-11395)

After the wasm-to-js wrapper is tiered up, its frame is typed as WASM_TO_JS_FUNCTION, which the unwinder's switch does not handle, so the pending stack-switch information is never cleared. A later garbage collection then treats the frame as a stack switch and computes a wrong parameter limit, causing a debug assertion failure or a segmentation fault in release builds.

Anonymous Follow

Originally disclosed on Chrome VRP

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

Title:

Debug check failed: kCanBeWeak || (!IsSmi() == HAS_STRONG_HEAP_OBJECT_TAG(ptr_)).

Component:

Blink>JavaScript>Runtime

Description:

In M130 and M131, the wasm-to-js frame is treated as StackFrame::WASM_TO_JS_FUNCTION after the tier-up of the wasm-to-js wrapper.

However, in function Isolate::UnwindAndFindHandler, this frame fails to call HandleStackSwitch(iter) because type StackFrame::WASM_TO_JS_FUNCTION is not handled by the switch-case.

Now only StackFrame::WASM_TO_JS and StackFrame::STUB can call the HandleStackSwitch.

C++
Tagged<Object> Isolate::UnwindAndFindHandler() {
  ...
#if V8_ENABLE_WEBASSEMBLY
  auto HandleStackSwitch = [&](StackFrameIterator& iter) {
    if (iter.wasm_stack() == nullptr) return;
    auto& switch_info = iter.wasm_stack()->stack_switch_info();
    if (!switch_info.has_value()) return;
    Tagged<Object> suspender_obj = root(RootIndex::kActiveSuspender);
    if (!IsUndefined(suspender_obj)) {
      // If the wasm-to-js wrapper was on a secondary stack and switched
      // to the central stack, handle the implicit switch back.
      if (switch_info.source_fp == iter.frame()->fp()) {
        thread_local_top()->is_on_central_stack_flag_ = false;
        stack_guard()->SetStackLimitForStackSwitching(
            reinterpret_cast<uintptr_t>(iter.wasm_stack()->jslimit()));
        iter.wasm_stack()->clear_stack_switch_info();
      }
    }
  };
#endif

  ...
  for (StackFrameIterator iter(this, thread_local_top(),
                               StackFrameIterator::NoHandles{});
       ; iter.Advance(), visited_frames++) {
    ...
    switch (frame->type()) {
      ...
      case StackFrame::WASM_TO_JS: {
        HandleStackSwitch(iter);                                           [1]
        break;
      }
      ...
      case StackFrame::STUB: {
#if V8_ENABLE_WEBASSEMBLY
        HandleStackSwitch(iter);                                           [2]
#endif

As a result, clear_stack_switch_info will not be executed.

Further more, when GC is triggered in the secondary stack from the wasm-to-js wrapper, the function TypedFrame::Iterate will get the remaining stack_switch_info and treat the frame as a stack-switching case and calculate a wrong parameters_limit address which points to the main stack.

Then there may be a huge space between parameters_base and parameters_limit, causing DCHECK or SEGV.

C++
void TypedFrame::Iterate(RootVisitor* v) const {
  ...
  wasm::StackMemory::StackSwitchInfo maybe_stack_switch;
  if (iterator_->wasm_stack() != nullptr) {
    maybe_stack_switch = iterator_->wasm_stack()->stack_switch_info();
  }
  FullObjectSlot parameters_limit(
      maybe_stack_switch.has_value() && maybe_stack_switch.source_fp == fp()            [3]
          ? maybe_stack_switch.target_sp
          : frame_header_base.address() - spill_slots_size);
#else
  FullObjectSlot parameters_limit(frame_header_base.address() -
                                  spill_slots_size);
#endif
  FullObjectSlot parameters_base(&Memory<Address>(sp()));
  FullObjectSlot spill_slots_end(frame_header_base.address() -
                                 spill_slots_size);

  // Visit the rest of the parameters.
  if (HasTaggedOutgoingParams(code)) {
    v->VisitRootPointers(Root::kStackRoots, nullptr, parameters_base,                  [4]
                         parameters_limit);
  }

I wrote a testcase to trigger this vulnerability.

This vulnerability will not influence new M132 versions after commit 534c66a175cef8102cbe8b5562cc44269eb69048 because then the tier-up wrapper code is added to the cache and the frame will be treated as StackFrame::WASM_TO_JS. So, this vulnerability is hidden then.

Just use a d8 debug build d8-asan-linux-debug-v8-component-96808.zip from https://commondatastorage.googleapis.com/v8-asan/index.html?prefix=linux-debug/ to trigger it.

run command

./d8 --experimental-wasm-jspi --turboshaft-wasm-wrappers poc.js

It will crash with DCHECK Debug check failed: kCanBeWeak || (!IsSmi() == HAS_STRONG_HEAP_OBJECT_TAG(ptr_)).

And in the release version, it may get a SEGV during GC.

I think this vulnerability may be exploited. I will try and update if success.

Crash Log:

LOG
#
# Fatal error in ../../src/objects/tagged-impl.h, line 147
# Debug check failed: kCanBeWeak || (!IsSmi() == HAS_STRONG_HEAP_OBJECT_TAG(ptr_)).
#
#
#
#FailureMessage Object: 0x7213a2628060
==== C stack trace ===============================

    /test/test/d8(__interceptor_backtrace+0x46) [0x5700cf3d1ea6]
    /test/test/libv8_libbase.so(v8::base::debug::StackTrace::StackTrace()+0x13) [0x7213a61e3ac3]
    /test/test/libv8_libplatform.so(+0x358da) [0x7213b18d28da]
    /test/test/libv8_libbase.so(V8_Fatal(char const*, int, char const*, ...)+0x2a0) [0x7213a61ae260]
    /test/test/libv8_libbase.so(+0x5732f) [0x7213a61ad32f]
    /test/test/libv8.so(v8::internal::ClearStaleLeftTrimmedPointerVisitor::VisitRootPointers(v8::internal::Root, char const*, v8::internal::FullObjectSlot, v8::internal::FullObjectSlot)+0x118) [0x7213ab3ec118]
    /test/test/libv8.so(v8::internal::TypedFrame::Iterate(v8::internal::RootVisitor*) const+0x5c0) [0x7213aaec4790]
    /test/test/libv8.so(v8::internal::Isolate::Iterate(v8::internal::RootVisitor*, v8::internal::ThreadLocalTop*)+0x578) [0x7213aaefef38]
    /test/test/libv8.so(v8::internal::Heap::IterateRoots(v8::internal::RootVisitor*, v8::base::EnumSet<v8::internal::SkipRoot, int>, v8::internal::Heap::IterateRootsMode)+0x539) [0x7213ab39ec39]
    /test/test/libv8.so(v8::internal::ScavengerCollector::CollectGarbage()+0x11cb) [0x7213ab60276b]
    /test/test/libv8.so(v8::internal::Heap::Scavenge()+0x57a) [0x7213ab38da6a]
    /test/test/libv8.so(v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*)+0xc09) [0x7213ab38a3d9]
    /test/test/libv8.so(+0x51f3522) [0x7213ab3f3522]
    /test/test/libv8.so(+0x51f2d07) [0x7213ab3f2d07]
    /test/test/libv8.so(+0x82c0283) [0x7213ae4c0283]
Trace/breakpoint trap

VERSION

Chrome Version: M130, M131

Operating System: Linux

CREDIT

Anonymous.

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

Context

This is a V8 bug in the JavaScript runtime that ships with Chrome, filed under Blink>JavaScript>Runtime and tracked as CVE-2024-11395. The affected component is V8 itself, and the report is a Chrome VRP advisory disclosed on 19 November 2024 with a bounty of 8,000 USD. The researcher is listed as Anonymous.

The bug involves the wasm-to-js wrapper. With JSPI, that wrapper can run on a secondary stack and switch to the central stack, and V8 records the switch in stack_switch_info attached to the wasm stack. The bookkeeping around that switch is what this bug breaks.

Setup

The bug is reproduced with a d8 debug build. The report names the build d8-asan-linux-debug-v8-component-96808.zip, available from the V8 asan index at https://commondatastorage.googleapis.com/v8-asan/index.html?prefix=linux-debug/. The operating system is Linux, and the affected versions are M130 and M131.

The proof of concept is a file called poc.js, run with two flags: --experimental-wasm-jspi and --turboshaft-wasm-wrappers.

Finding it

The researcher noticed that in M130 and M131, after the tier-up of the wasm-to-js wrapper, the wasm-to-js frame is treated as StackFrame::WASM_TO_JS_FUNCTION. In Isolate::UnwindAndFindHandler, that frame type is not handled by the switch-case, so the frame never calls HandleStackSwitch(iter). Only StackFrame::WASM_TO_JS and StackFrame::STUB reach that call.

The relevant code from the report:

C++
Tagged<Object> Isolate::UnwindAndFindHandler() {
  ...
#if V8_ENABLE_WEBASSEMBLY
  auto HandleStackSwitch = [&](StackFrameIterator& iter) {
    if (iter.wasm_stack() == nullptr) return;
    auto& switch_info = iter.wasm_stack()->stack_switch_info();
    if (!switch_info.has_value()) return;
    Tagged<Object> suspender_obj = root(RootIndex::kActiveSuspender);
    if (!IsUndefined(suspender_obj)) {
      // If the wasm-to-js wrapper was on a secondary stack and switched
      // to the central stack, handle the implicit switch back.
      if (switch_info.source_fp == iter.frame()->fp()) {
        thread_local_top()->is_on_central_stack_flag_ = false;
        stack_guard()->SetStackLimitForStackSwitching(
            reinterpret_cast<uintptr_t>(iter.wasm_stack()->jslimit()));
        iter.wasm_stack()->clear_stack_switch_info();
      }
    }
  };
#endif

  ...
  for (StackFrameIterator iter(this, thread_local_top(),
                               StackFrameIterator::NoHandles{});
       ; iter.Advance(), visited_frames++) {
    ...
    switch (frame->type()) {
      ...
      case StackFrame::WASM_TO_JS: {
        HandleStackSwitch(iter);                                           [1]
        break;
      }
      ...
      case StackFrame::STUB: {
#if V8_ENABLE_WEBASSEMBLY
        HandleStackSwitch(iter);                                           [2]
#endif

Because the WASM_TO_JS_FUNCTION frame type falls through without a matching case, clear_stack_switch_info is never executed. The stale switch information stays on the wasm stack.

Exploitation

Step 1: trigger the tier-up and unwind

Run the proof of concept against the debug build:

Bash
./d8 --experimental-wasm-jspi --turboshaft-wasm-wrappers poc.js

The report does not include the contents of poc.js. The researcher states that the testcase triggers the vulnerability.

Step 2: trigger GC on the secondary stack

When GC is triggered in the secondary stack from the wasm-to-js wrapper, TypedFrame::Iterate reads the remaining stack_switch_info and treats the frame as a stack-switching case. It then computes a wrong parameters_limit address that points to the main stack.

The code from the report:

C++
void TypedFrame::Iterate(RootVisitor* v) const {
  ...
  wasm::StackMemory::StackSwitchInfo maybe_stack_switch;
  if (iterator_->wasm_stack() != nullptr) {
    maybe_stack_switch = iterator_->wasm_stack()->stack_switch_info();
  }
  FullObjectSlot parameters_limit(
      maybe_stack_switch.has_value() && maybe_stack_switch.source_fp == fp()            [3]
          ? maybe_stack_switch.target_sp
          : frame_header_base.address() - spill_slots_size);
#else
  FullObjectSlot parameters_limit(frame_header_base.address() -
                                  spill_slots_size);
#endif
  FullObjectSlot parameters_base(&Memory<Address>(sp()));
  FullObjectSlot spill_slots_end(frame_header_base.address() -
                                 spill_slots_size);

  // Visit the rest of the parameters.
  if (HasTaggedOutgoingParams(code)) {
    v->VisitRootPointers(Root::kStackRoots, nullptr, parameters_base,                  [4]
                         parameters_limit);
  }

Because parameters_limit points to the main stack while parameters_base is on the secondary stack, there may be a huge space between the two.

Step 3: observe the crash

In the debug build the run crashes with the DCHECK:

Text
Debug check failed: kCanBeWeak || (!IsSmi() == HAS_STRONG_HEAP_OBJECT_TAG(ptr_))

The full crash log from the report:

LOG
#
# Fatal error in ../../src/objects/tagged-impl.h, line 147
# Debug check failed: kCanBeWeak || (!IsSmi() == HAS_STRONG_HEAP_OBJECT_TAG(ptr_)).
#
#
#
#FailureMessage Object: 0x7213a2628060
==== C stack trace ===============================

    /test/test/d8(__interceptor_backtrace+0x46) [0x5700cf3d1ea6]
    /test/test/libv8_libbase.so(v8::base::debug::StackTrace::StackTrace()+0x13) [0x7213a61e3ac3]
    /test/test/libv8_libplatform.so(+0x358da) [0x7213b18d28da]
    /test/test/libv8_libbase.so(V8_Fatal(char const*, int, char const*, ...)+0x2a0) [0x7213a61ae260]
    /test/test/libv8_libbase.so(+0x5732f) [0x7213a61ad32f]
    /test/test/libv8.so(v8::internal::ClearStaleLeftTrimmedPointerVisitor::VisitRootPointers(v8::internal::Root, char const*, v8::internal::FullObjectSlot, v8::internal::FullObjectSlot)+0x118) [0x7213ab3ec118]
    /test/test/libv8.so(v8::internal::TypedFrame::Iterate(v8::internal::RootVisitor*) const+0x5c0) [0x7213aaec4790]
    /test/test/libv8.so(v8::internal::Isolate::Iterate(v8::internal::RootVisitor*, v8::internal::ThreadLocalTop*)+0x578) [0x7213aaefef38]
    /test/test/libv8.so(v8::internal::Heap::IterateRoots(v8::internal::RootVisitor*, v8::base::EnumSet<v8::internal::SkipRoot, int>, v8::internal::Heap::IterateRootsMode)+0x539) [0x7213ab39ec39]
    /test/test/libv8.so(v8::internal::ScavengerCollector::CollectGarbage()+0x11cb) [0x7213ab60276b]
    /test/test/libv8.so(v8::internal::Heap::Scavenge()+0x57a) [0x7213ab38da6a]
    /test/test/libv8.so(v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*)+0xc09) [0x7213ab38a3d9]
    /test/test/libv8.so(+0x51f3522) [0x7213ab3f3522]
    /test/test/libv8.so(+0x51f2d07) [0x7213ab3f2d07]
    /test/test/libv8.so(+0x82c0283) [0x7213ae4c0283]
Trace/breakpoint trap

The stack shows the path: ScavengerCollector::CollectGarbage and Heap::Scavenge lead to Heap::IterateRoots, which calls Isolate::Iterate, which calls TypedFrame::Iterate, which calls ClearStaleLeftTrimmedPointerVisitor::VisitRootPointers, where the DCHECK fires. In a release build, the report says the same condition may produce a SEGV during GC.

Root cause

Isolate::UnwindAndFindHandler only calls HandleStackSwitch for StackFrame::WASM_TO_JS and StackFrame::STUB. After the tier-up of the wasm-to-js wrapper, the frame is typed StackFrame::WASM_TO_JS_FUNCTION, which has no case, so the implicit switch back is never handled and clear_stack_switch_info is skipped. The stale StackSwitchInfo then makes TypedFrame::Iterate take the stack-switching branch and use target_sp as parameters_limit, which points to the main stack. The root visitor is handed a range spanning both stacks, and the DCHECK or SEGV follows.

The report notes that the bug does not affect new M132 versions after commit [redacted], because from then on the tier-up wrapper code is added to the cache and the frame is treated as StackFrame::WASM_TO_JS. The report says the vulnerability is hidden in that version.

Impact

The report describes a crash: a DCHECK failure in debug builds and a possible SEGV during GC in release builds. The researcher writes that the vulnerability may be exploitable and that they would try and update if successful. No working exploit or memory-corruption primitive is demonstrated in the report. The affected versions are M130 and M131 on Linux.

Fix

The report does not describe a patch. It states that M132 versions after commit [redacted] are not affected because the tier-up wrapper code is added to the cache and the frame is treated as StackFrame::WASM_TO_JS, which reaches HandleStackSwitch. Whether a separate fix was applied to M130 and M131 is not stated.

Variants to test

  1. Other frame types that can carry a StackSwitchInfo but are not handled in the UnwindAndFindHandler switch. A positive result is a frame that reaches GC with stack_switch_info still set.
  2. Tier-up paths for other wrappers, such as wasm-to-js wrappers under different flags. A positive result is a frame type change after tier-up that skips the stack switch handling.
  3. GC triggered while executing on a secondary stack with JSPI enabled. A positive result is a parameters_limit that points to a different stack than parameters_base, visible as a DCHECK in tagged-impl.h or a SEGV in TypedFrame::Iterate.
  4. Release builds of the same versions, to see whether the DCHECK turns into a SEGV during scavenge. A positive result is a crash in ScavengerCollector::CollectGarbage with the same stack shape as the log above.

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

What happened, in plain words

Chrome runs JavaScript using a program inside it called V8. V8 is the JavaScript engine: the part that reads your web page's scripts and actually executes them. V8 can also run WebAssembly, a faster, lower-level kind of code that web pages can load alongside JavaScript, and the two can call each other.

This report is about a bug in V8 that was tracked as CVE-2024-11395. A CVE is a public catalogue number given to a known security flaw so people can refer to it unambiguously. The bug was reported through Chrome's bug bounty programme, the Chrome VRP (Vulnerability Reward Program), where Google pays people for finding and reporting security problems. The report was disclosed on 19 November 2024, the severity was rated high, and the bounty was 8,000 USD. The researcher is listed as Anonymous.

The feature involved is the wasm-to-js wrapper, used with WebAssembly JS Promise Integration (JSPI). To understand it, imagine two rooms in a building: one room where WebAssembly code runs and another where JavaScript runs. Normally code moves between the rooms in a simple, predictable way. JSPI lets WebAssembly call into JavaScript and wait for an answer, a bit like placing an order at a counter and waiting for your number to be called. To make that waiting work, V8 sometimes runs the WebAssembly-to-JavaScript handover on a second, temporary workbench (called a secondary stack) and then hops back to the main workbench (the central stack).

A stack, in computing, is the area of memory where a program keeps track of which function called which, and what each one is currently doing. Think of a stack of sticky notes: each function call adds a note, and when the function finishes the note is removed. V8 has more than one stack in this scenario, and it needs to remember when it has hopped from one to the other. It writes that memory down in a small record called stack_switch_info, attached to the WebAssembly stack.

This bug is about that record not being cleaned up. When the cleanup is skipped, later code reads the leftover record, believes the program is still in the middle of a stack hop, and calculates a memory address in the wrong place. That leads to a crash, and the researcher suggests it might be exploitable.

A simple comparison: a form asks for your age, and someone types the word "blue". If the system blindly treats "blue" as a number, it may do something nonsensical. In V8's case, a frame type is not handled by the switch-case, so the stack switch cleanup is skipped and the wrong memory is read.

Context

This is a V8 bug in the JavaScript runtime that ships with Chrome, filed under Blink>JavaScript>Runtime. Blink is Chrome's rendering engine, the part that turns HTML and CSS into what you see, and it contains the JavaScript runtime. The affected component is V8 itself, and the report is a Chrome VRP advisory disclosed on 19 November 2024 with a bounty of 8,000 USD. The researcher is listed as Anonymous.

The feature involved is WebAssembly JS Promise Integration (JSPI) and the wasm-to-js wrapper. A wrapper here is a small piece of glue code that lets one kind of code call another: when WebAssembly calls into JavaScript, V8 runs a wrapper frame to manage the handover. With JSPI, that wrapper can run on a secondary stack and switch to the central stack, and V8 records the switch in a StackSwitchInfo structure attached to the wasm stack. The bookkeeping around that switch is what this bug breaks.

Setup

The bug is reproduced with a d8 debug build. d8 is V8's own command-line shell: a small program that runs JavaScript and WebAssembly directly, without a browser window, so developers can test the engine in isolation. A debug build is a version compiled with extra internal checks switched on, which catch mistakes early and loudly instead of letting them pass silently. The report names the build d8-asan-linux-debug-v8-component-96808.zip, available from the V8 asan index at https://commondatastorage.googleapis.com/v8-asan/index.html?prefix=linux-debug/. ASan stands for AddressSanitizer, a tool that watches memory accesses for errors. The operating system is Linux, and the affected versions are M130 and M131, which are Chrome milestone numbers: Chrome 130 and Chrome 131.

The proof of concept is a file called poc.js. A proof of concept is a small, deliberately harmless demonstration that a bug is real. It is run with two flags: --experimental-wasm-jspi and --turboshaft-wasm-wrappers. A flag is an option you add on the command line to change how a program behaves. Turboshaft is the name of one of V8's internal compilers, the parts that turn code into fast machine instructions.

Finding it

The researcher noticed that in M130 and M131, after the tier-up of the wasm-to-js wrapper, the wasm-to-js frame is treated as StackFrame::WASM_TO_JS_FUNCTION. Tier-up is V8's habit of starting with simple, quick-to-produce code and later replacing it with a more optimised version once it sees the code being used a lot, like swapping a rough sketch for a detailed drawing once you know the sketch is worth keeping. A frame type is a label saying what kind of function call a stack entry represents.

In Isolate::UnwindAndFindHandler, that frame type is not handled by the switch-case, so the frame never calls HandleStackSwitch(iter). A switch-case is a common programming construct that picks one branch out of several based on a value, like a railway signal choosing one track. An Isolate is V8's term for one isolated JavaScript environment, with its own memory and state. Only StackFrame::WASM_TO_JS and StackFrame::STUB reach that call.

The relevant code from the report:

C++
Tagged<Object> Isolate::UnwindAndFindHandler() {
  ...
#if V8_ENABLE_WEBASSEMBLY
  auto HandleStackSwitch = [&](StackFrameIterator& iter) {
    if (iter.wasm_stack() == nullptr) return;
    auto& switch_info = iter.wasm_stack()->stack_switch_info();
    if (!switch_info.has_value()) return;
    Tagged<Object> suspender_obj = root(RootIndex::kActiveSuspender);
    if (!IsUndefined(suspender_obj)) {
      // If the wasm-to-js wrapper was on a secondary stack and switched
      // to the central stack, handle the implicit switch back.
      if (switch_info.source_fp == iter.frame()->fp()) {
        thread_local_top()->is_on_central_stack_flag_ = false;
        stack_guard()->SetStackLimitForStackSwitching(
            reinterpret_cast<uintptr_t>(iter.wasm_stack()->jslimit()));
        iter.wasm_stack()->clear_stack_switch_info();
      }
    }
  };
#endif

  ...
  for (StackFrameIterator iter(this, thread_local_top(),
                               StackFrameIterator::NoHandles{});
       ; iter.Advance(), visited_frames++) {
    ...
    switch (frame->type()) {
      ...
      case StackFrame::WASM_TO_JS: {
        HandleStackSwitch(iter);                                           [1]
        break;
      }
      ...
      case StackFrame::STUB: {
#if V8_ENABLE_WEBASSEMBLY
        HandleStackSwitch(iter);                                           [2]
#endif

Line by line, in plain words:

  • Tagged<Object> Isolate::UnwindAndFindHandler() { starts the function that walks the stack looking for a handler. Tagged<Object> means the function returns a V8 object that carries a small tag saying what kind of object it is.
  • #if V8_ENABLE_WEBASSEMBLY is a compile-time switch: the code below is only included if WebAssembly support is built in.
  • auto HandleStackSwitch = [&](StackFrameIterator& iter) { defines a small helper, a lambda (an unnamed function stored in a variable), which takes a stack frame iterator. An iterator is an object that walks through a collection one item at a time.
  • if (iter.wasm_stack() == nullptr) return; stops immediately if there is no WebAssembly stack attached to this iterator.
  • auto& switch_info = iter.wasm_stack()->stack_switch_info(); fetches the recorded stack-switch information from the WebAssembly stack.
  • if (!switch_info.has_value()) return; stops if no switch was recorded.
  • Tagged<Object> suspender_obj = root(RootIndex::kActiveSuspender); looks up the active suspender, the object that represents a paused WebAssembly call waiting to resume.
  • if (!IsUndefined(suspender_obj)) { only continues if that suspender exists.
  • The comment explains the intent: if the wrapper was on a secondary stack and switched to the central stack, handle the switch back.
  • if (switch_info.source_fp == iter.frame()->fp()) { checks that the recorded source frame pointer matches the current frame. A frame pointer is a memory address marking where a function's stack frame begins.
  • thread_local_top()->is_on_central_stack_flag_ = false; records that execution is no longer on the central stack.
  • stack_guard()->SetStackLimitForStackSwitching(...) resets the stack limit used for stack switching, using the WebAssembly stack's limit.
  • iter.wasm_stack()->clear_stack_switch_info(); erases the recorded switch information. This is the crucial cleanup line.
  • The closing braces end the helper and the conditional block.
  • for (StackFrameIterator iter(...); ; iter.Advance(), visited_frames++) { walks through every frame on the stack, one at a time.
  • switch (frame->type()) { chooses a branch based on the frame's type label.
  • case StackFrame::WASM_TO_JS: { handles the wasm-to-JavaScript frame type and calls HandleStackSwitch(iter); at marker [1].
  • case StackFrame::STUB: { handles stub frames and calls HandleStackSwitch(iter); at marker [2].

Because the WASM_TO_JS_FUNCTION frame type falls through without a matching case, clear_stack_switch_info is never executed. The stale switch information stays on the wasm stack, like a note left on the wrong desk after everyone has gone home.

Exploitation

Step 1: trigger the tier-up and unwind

Run the proof of concept against the debug build:

Bash
./d8 --experimental-wasm-jspi --turboshaft-wasm-wrappers poc.js

Line by line:

  • ./d8 runs the d8 shell from the current directory.
  • --experimental-wasm-jspi turns on the experimental JSPI feature.
  • --turboshaft-wasm-wrappers turns on the Turboshaft wasm wrapper path.
  • poc.js is the proof-of-concept script to execute.

The report does not include the contents of poc.js. The researcher states that the testcase triggers the vulnerability.

Step 2: trigger GC on the secondary stack

GC stands for garbage collection: the automatic process by which the engine finds memory that is no longer in use and frees it for reuse, like a cleaner clearing abandoned tables in a restaurant. When GC is triggered in the secondary stack from the wasm-to-js wrapper, TypedFrame::Iterate reads the remaining stack_switch_info and treats the frame as a stack-switching case. It then computes a wrong parameters_limit address that points to the main stack. An address here is simply a location in memory.

The code from the report:

C++
void TypedFrame::Iterate(RootVisitor* v) const {
  ...
  wasm::StackMemory::StackSwitchInfo maybe_stack_switch;
  if (iterator_->wasm_stack() != nullptr) {
    maybe_stack_switch = iterator_->wasm_stack()->stack_switch_info();
  }
  FullObjectSlot parameters_limit(
      maybe_stack_switch.has_value() && maybe_stack_switch.source_fp == fp()            [3]
          ? maybe_stack_switch.target_sp
          : frame_header_base.address() - spill_slots_size);
#else
  FullObjectSlot parameters_limit(frame_header_base.address() -
                                  spill_slots_size);
#endif
  FullObjectSlot parameters_base(&Memory<Address>(sp()));
  FullObjectSlot spill_slots_end(frame_header_base.address() -
                                 spill_slots_size);

  // Visit the rest of the parameters.
  if (HasTaggedOutgoingParams(code)) {
    v->VisitRootPointers(Root::kStackRoots, nullptr, parameters_base,                  [4]
                         parameters_limit);
  }

Line by line:

  • void TypedFrame::Iterate(RootVisitor* v) const { starts the function that walks a typed frame's contents so the garbage collector can find every live object. A root visitor is the object that receives each such pointer.
  • wasm::StackMemory::StackSwitchInfo maybe_stack_switch; declares a variable to hold any recorded stack-switch information.
  • if (iterator_->wasm_stack() != nullptr) { checks whether a WebAssembly stack is attached.
  • maybe_stack_switch = iterator_->wasm_stack()->stack_switch_info(); copies the recorded switch information into the variable.
  • FullObjectSlot parameters_limit( begins computing the upper end of the range of parameters to scan. A slot is a small memory location that can hold one pointer.
  • maybe_stack_switch.has_value() && maybe_stack_switch.source_fp == fp() at marker [3] checks whether a switch was recorded and whether it belongs to this frame.
  • ? maybe_stack_switch.target_sp chooses the recorded target stack pointer if so.
  • : frame_header_base.address() - spill_slots_size); otherwise falls back to the normal calculation based on the frame header and spill slots (temporary storage for values the function needs to keep).
  • The #else branch is the version compiled when WebAssembly support is off, which always uses the normal calculation.
  • FullObjectSlot parameters_base(&Memory<Address>(sp())); sets the lower end of the range from the current stack pointer.
  • FullObjectSlot spill_slots_end(...) computes where the spill slots end.
  • if (HasTaggedOutgoingParams(code)) { checks whether the code has outgoing parameters that the collector must follow.
  • v->VisitRootPointers(Root::kStackRoots, nullptr, parameters_base, parameters_limit); at marker [4] asks the visitor to walk every pointer between the base and the limit.

Because parameters_limit points to the main stack while parameters_base is on the secondary stack, there may be a huge space between the two.

Step 3: observe the crash

In the debug build the run crashes with the DCHECK:

Text
Debug check failed: kCanBeWeak || (!IsSmi() == HAS_STRONG_HEAP_OBJECT_TAG(ptr_))

A DCHECK is a debug-only assertion: a check that the programmer believes must always be true, compiled in only for debug builds. When it fails, the program stops and prints a message. Here the message says a value that was supposed to look like a proper tagged object does not.

The full crash log from the report:

LOG
#
# Fatal error in ../../src/objects/tagged-impl.h, line 147
# Debug check failed: kCanBeWeak || (!IsSmi() == HAS_STRONG_HEAP_OBJECT_TAG(ptr_)).
#
#
#
#FailureMessage Object: 0x7213a2628060
==== C stack trace ===============================

    /test/test/d8(__interceptor_backtrace+0x46) [0x5700cf3d1ea6]
    /test/test/libv8_libbase.so(v8::base::debug::StackTrace::StackTrace()+0x13) [0x7213a61e3ac3]
    /test/test/libv8_libplatform.so(+0x358da) [0x7213b18d28da]
    /test/test/libv8_libbase.so(V8_Fatal(char const*, int, char const*, ...)+0x2a0) [0x7213a61ae260]
    /test/test/libv8_libbase.so(+0x5732f) [0x7213a61ad32f]
    /test/test/libv8.so(v8::internal::ClearStaleLeftTrimmedPointerVisitor::VisitRootPointers(v8::internal::Root, char const*, v8::internal::FullObjectSlot, v8::internal::FullObjectSlot)+0x118) [0x7213ab3ec118]
    /test/test/libv8.so(v8::internal::TypedFrame::Iterate(v8::internal::RootVisitor*) const+0x5c0) [0x7213aaec4790]
    /test/test/libv8.so(v8::internal::Isolate::Iterate(v8::internal::RootVisitor*, v8::internal::ThreadLocalTop*)+0x578) [0x7213aaefef38]
    /test/test/libv8.so(v8::internal::Heap::IterateRoots(v8::internal::RootVisitor*, v8::base::EnumSet<v8::internal::SkipRoot, int>, v8::internal::Heap::IterateRootsMode)+0x539) [0x7213ab39ec39]
    /test/test/libv8.so(v8::internal::ScavengerCollector::CollectGarbage()+0x11cb) [0x7213ab60276b]
    /test/test/libv8.so(v8::internal::Heap::Scavenge()+0x57a) [0x7213ab38da6a]
    /test/test/libv8.so(v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*)+0xc09) [0x7213ab38a3d9]
    /test/test/libv8.so(+0x51f3522) [0x7213ab3f3522]
    /test/test/libv8.so(+0x51f2d07) [0x7213ab3f2d07]
    /test/test/libv8.so(+0x82c0283) [0x7213ae4c0283]
Trace/breakpoint trap

Line by line:

  • The first lines report a fatal error in tagged-impl.h at line 147, with the failed debug check.
  • #FailureMessage Object: 0x7213a2628060 is the address of the object associated with the failure.
  • ==== C stack trace =============================== begins the list of function calls that led to the crash, from the innermost call at the top to the outermost at the bottom.
  • The first entries are the crash handler and stack-trace helpers in libv8_libbase.so and libv8_libplatform.so.
  • V8_Fatal is the function that prints the fatal error and aborts.
  • ClearStaleLeftTrimmedPointerVisitor::VisitRootPointers is where the check fires, while visiting pointers.
  • TypedFrame::Iterate is the frame walk described above.
  • Isolate::Iterate walks the isolate's roots.
  • Heap::IterateRoots walks all roots of the heap.
  • ScavengerCollector::CollectGarbage and Heap::Scavenge are the garbage collector's scavenger, which collects young objects.
  • Heap::PerformGarbageCollection is the entry point that decides which collector to run.
  • The remaining lines are unnamed addresses inside libv8.so.
  • Trace/breakpoint trap is the signal that ends the process when the debugger trap fires.

The stack shows the path: ScavengerCollector::CollectGarbage and Heap::Scavenge lead to Heap::IterateRoots, which calls Isolate::Iterate, which calls TypedFrame::Iterate, which calls ClearStaleLeftTrimmedPointerVisitor::VisitRootPointers, where the DCHECK fires. In a release build, the report says the same condition may produce a SEGV during GC. SEGV stands for segmentation violation: the operating system killing a program because it touched memory it is not allowed to touch.

Root cause

Isolate::UnwindAndFindHandler only calls HandleStackSwitch for StackFrame::WASM_TO_JS and StackFrame::STUB. After the tier-up of the wasm-to-js wrapper, the frame is typed StackFrame::WASM_TO_JS_FUNCTION, which has no case, so the implicit switch back is never handled and clear_stack_switch_info is skipped. The stale stack_switch_info then makes TypedFrame::Iterate take the stack-switching branch and use target_sp as parameters_limit, which points to the main stack. The root visitor is handed a range spanning both stacks, and the DCHECK or SEGV follows.

The report notes that the bug does not affect new M132 versions after commit [redacted], because from then on the tier-up wrapper code is added to the cache and the frame is treated as StackFrame::WASM_TO_JS. A commit is a recorded change to the source code, identified by a long hash. The report says the vulnerability is hidden in that version.

Impact

The report describes a crash: a DCHECK failure in debug builds and a possible SEGV during GC in release builds. The researcher writes that the vulnerability may be exploitable and that they would try and update if successful. No working exploit or memory-corruption primitive is demonstrated in the report. The affected versions are M130 and M131 on Linux.

Fix

The report does not describe a patch. It states that M132 versions after commit [redacted] are not affected because the tier-up wrapper code is added to the cache and the frame is treated as StackFrame::WASM_TO_JS, which reaches HandleStackSwitch. Whether a separate fix was applied to M130 and M131 is not stated.

Variants to test

  1. Other frame types that can carry a StackSwitchInfo but are not handled in the UnwindAndFindHandler switch. A positive result is a frame that reaches GC with stack_switch_info still set.
  2. Tier-up paths for other wrappers, such as wasm-to-js wrappers under different flags. A positive result is a frame type change after tier-up that skips the stack switch handling.
  3. GC triggered while executing on a secondary stack with JSPI enabled. A positive result is a parameters_limit that points to a different stack than parameters_base, visible as a DCHECK in tagged-impl.h or a SEGV in TypedFrame::Iterate.
  4. Release builds of the same versions, to see whether the DCHECK turns into a SEGV during scavenge. A positive result is a crash in ScavengerCollector::CollectGarbage with the same stack shape as the log above.

Glossary

  • Address: a numbered location in a computer's memory, like a house number on a street.
  • ASan (AddressSanitizer): a tool that watches memory accesses and reports errors such as reading outside an allowed area.
  • Blink: Chrome's rendering engine, which turns HTML and CSS into the page you see and hosts the JavaScript runtime.
  • Bug bounty programme: a scheme where an organisation pays people for responsibly reporting security flaws.
  • Chrome VRP: Chrome's Vulnerability Reward Program, Google's bug bounty programme for Chrome.
  • Commit: a recorded change to source code, identified by a long hash.
  • CVE: a public catalogue number for a known security vulnerability.
  • d8: V8's command-line shell for running JavaScript and WebAssembly without a browser.
  • Debug build: a version of a program compiled with extra internal checks switched on.
  • DCHECK: a debug-only assertion that stops the program if a condition the programmer believed impossible turns out to be true.
  • Flag: a command-line option that changes how a program behaves.
  • Frame: a record on the stack of one function call and its local state.
  • Frame pointer: a memory address marking where a function's stack frame begins.
  • Garbage collection (GC): the automatic process of finding and freeing memory that is no longer in use.
  • Isolate: V8's term for one isolated JavaScript environment with its own memory and state.
  • Iterator: an object that walks through a collection one item at a time.
  • JSPI (WebAssembly JS Promise Integration): a feature that lets WebAssembly call into JavaScript and wait for the result.
  • Lambda: an unnamed function stored in a variable.
  • M130, M131, M132: Chrome milestone numbers, meaning Chrome 130, 131 and 132.
  • Parameters: the values passed into a function call.
  • Proof of concept (PoC): a small, deliberately harmless demonstration that a bug is real.
  • Release build: a version compiled for normal use, without the extra debug checks.
  • Root visitor: the object that receives each live pointer while the garbage collector scans memory.
  • SEGV (segmentation violation): the operating system killing a program because it touched memory it is not allowed to touch.
  • Slot: a small memory location that can hold one pointer.
  • Spill slots: temporary storage a function uses for values it needs to keep.
  • Stack: the area of memory where a program tracks which function called which and what each is doing.
  • StackSwitchInfo: V8's record of a hop between a secondary stack and the central stack.
  • Switch-case: a programming construct that picks one branch out of several based on a value.
  • Tier-up: V8's habit of replacing simple code with a more optimised version once it is used a lot.
  • Turboshaft: the name of one of V8's internal compilers.
  • Type confusion: a vulnerability where a program treats one kind of thing as if it were another kind.
  • V8: the JavaScript engine inside Chrome that executes JavaScript and WebAssembly.
  • Wrapper: small glue code that lets one kind of code call another.
  • WebAssembly: a fast, low-level code format that web pages can load alongside JavaScript.

More by Anonymous

View all

2,270 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.