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

Type Confusion in V8 (CVE-2024-5837)

A type confusion occurs in V8's JSPI feature when a re-exported imported JavaScript function is called via WebAssembly.promising. The wrong register value is passed to the wasm-to-js wrapper, causing a type confusion that could lead to memory corruption.

Anonymous Follow

Originally disclosed on Chrome VRP

  • Fix shipped in 20 days

TITLE

A security issue when using the JSPI feature.

VULNERABILITY DETAILS

I found that there is a type confusion when using the JSPI feature.

When using a re-exported imported JS function by WebAssembly.promising, the function NewPromisingWasmExportedFunction will construct the WasmExportedFunction object.

It uses the js-to-wasm wrapper here:

C++
  i::Handle<i::Code> wrapper =
      with_suspender_param ? BUILTIN_CODE(i_isolate, WasmPromisingWithSuspender)
                           : BUILTIN_CODE(i_isolate, WasmPromising);

It refers to the macro JSToWasmWrapperHelper in file js-to-wasm.tq,

When the exported function is called, JSToWasmWrapperHelper runs and calls WasmReturnPromiseOnSuspendAsm:

  // Both `trustedInstanceData` and `resultArray` get passed separately as
  // parameters to make them GC-safe. They get passed over the stack so that
  // they get scanned by the GC as part of the outgoing parameters of this
  // Torque builtin.
  let result: JSAny;
  if constexpr (switchStack) {
    result = WasmReturnPromiseOnSuspendAsm(
        wrapperBuffer, trustedInstanceData, resultArray);
  } else {
    result =
        JSToWasmWrapperAsm(wrapperBuffer, trustedInstanceData, resultArray);
  }

WasmReturnPromiseOnSuspendAsm is finished in JSToWasmWrapperHelper in file builtin-x64.c for x64 system. And it will finally call the target.


    __ call(call_target);

For re-exported imported JS function, the target is the wasm-to-js wrapper.

A param ref with type WasmApiFunctionRef should be passed to the wasm-to-js wrapper at the register rsi:


@export
transitioning macro WasmToJSWrapper(ref: WasmApiFunctionRef): WasmToJSResult

However, I found that in WasmReturnPromiseOnSuspendAsm, the value of rsi never changes to a WasmApiFunctionRef before calling the target and keeps the value in JSToWasmWrapperFrameConstants::kInstanceDataParamOffset as a kWasmInstanceRegister.

Thus a type confusion will occur in the WasmToJSWrapper.

I construct a POC to prove it.

You can run it at the least version of v8 (commit 21af1bc9eec78ba8d1d17e6ffd5977b12b581c9e)

You should use python3 tools/dev/gm.py x64.debug to build v8.

commond line:

Shell
out\x64.debug\d8 --experimental-wasm-jspi poc.js

VERSION

Chrome Version: V8 12.7.0

Operating System: Ubuntu

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.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the WasmReturnPromiseOnSuspendAsm builtin fails to set the register holding the WasmApiFunctionRef before calling the wasm-to-js wrapper, leaving a WasmInstanceData value instead.

Impact

A type confusion in the engine could lead to memory corruption and potentially arbitrary code execution.

What the attacker needed

V8 with JSPI enabled; ability to run JavaScript

How it was found

  1. Build V8 in debug mode using the provided command.
  2. Run d8 with the experimental JSPI flag and the proof-of-concept script.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This is a bug in V8, the JavaScript engine used by Chrome. When a particular WebAssembly feature (JSPI) calls a JavaScript function, the engine passes the wrong kind of internal object to a wrapper, confusing the types. This can cause the program to crash or potentially be exploited.

What is Memory corruption?

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

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.