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

Type Confusion in V8 (CVE-2024-10230)

A type confusion in V8's WebAssembly-to-JavaScript wrapper tier-up occurs when a function table is exported and re-imported across modules, causing a signature from one module to be used with another module's instance data. An attacker could exploit this to achieve arbitrary memory corruption and potentially bypass the V8 sandbox.

Seunghyun Lee Follow

Originally disclosed on Chrome VRP

  • Fix shipped in 25 days

VULNERABILITY DETAILS

Summary

Arbitrary WASM type confusion due to module confusion in wasm-to-js tier-up.

On Runtime_TierUpWasmToJSWrapper() triggered through function tables, the dispatch table's WasmTrustedInstanceData is used. However, the signature may be referring to another module's signature in case of an imported function that has been exported and re-imported as an element of a table. This results in arbitrary WASM type confusion as the wrapper compilation is using a signature with module-specfic ValueType from a different module.

Details

The following code in Runtime_TierUpWasmToJSWrapper() is triggered on wasm-to-js wrapper tier-up:

C++
RUNTIME_FUNCTION(Runtime_TierUpWasmToJSWrapper) {
  HandleScope scope(isolate);
  DCHECK_EQ(1, args.length());
  DirectHandle<WasmImportData> import_data(Cast<WasmImportData>(args[0]),
                                           isolate);
  // ...
  const auto* sig = import_data->sig();                                           // [!] signature from module A (initial JS function importer, table exporter)
  // ...
  Handle<WasmTrustedInstanceData> trusted_data(import_data->instance_data(),
                                               isolate);
  if (IsTuple2(*origin)) {
    auto tuple = Cast<Tuple2>(origin);
    trusted_data =
        handle(Cast<WasmInstanceObject>(tuple->value1())->trusted_data(isolate),  // [!] module B (table importer)
               isolate);
    origin = direct_handle(tuple->value2(), isolate);
  }
  const wasm::WasmModule* module = trusted_data->module();                        // [!] module B
  // ...
  wasm::NativeModule* native_module = trusted_data->native_module();

  wasm::ResolvedWasmImport resolved({}, -1, callable, sig, canonical_sig_index,
                                    wasm::WellKnownImport::kUninstantiated);
  wasm::ImportCallKind kind = resolved.kind();
  callable = resolved.callable();  // Update to ultimate target.
  // ...
  wasm::WasmImportWrapperCache* cache = wasm::GetWasmImportWrapperCache();
  wasm::WasmCode* wasm_code =
      cache->MaybeGet(kind, canonical_sig_index, expected_arity, suspend);
  if (!wasm_code) {
    wasm_code = cache->CompileWasmImportCallWrapper(                              // [!] miscompilation
        isolate, native_module, kind, sig, canonical_sig_index, false,
        expected_arity, suspend);
  }
  // ...
}

Signature sig is from the following code in InstanceBuilder::InitializeImportedIndirectFunctionTable() in case of imported table:

C++
    FunctionTargetAndImplicitArg entry(isolate_, target_instance_data,
                                       function_index);
    Handle<Object> implicit_arg = entry.implicit_arg();
    if (v8_flags.wasm_generic_wrapper && IsWasmImportData(*implicit_arg)) {
      auto orig_import_data = Cast<WasmImportData>(implicit_arg);
      Handle<WasmImportData> new_import_data =
          isolate_->factory()->NewWasmImportData(orig_import_data);               // [!] using signature from module A (table exporter)
      // TODO(42204563): Avoid crashing if the instance object is not available.
      CHECK(trusted_instance_data->has_instance_object());
      WasmImportData::SetCrossInstanceTableIndexAsCallOrigin(
          isolate_, new_import_data,
          direct_handle(trusted_instance_data->instance_object(), isolate_), i);
      implicit_arg = new_import_data;
    }

Through the following steps, we can cause a cross-module signature (and thus ValueType) confusion:

  1. Module A imports a JS function
  2. Module A creates a function table with imported function as an element
  3. Module A exports the function table
  4. Module B imports the function table from A
    • sig is still from module A, but call origin is set to module B
  5. Module B triggers a tier-up
    • sig is misused as a signature from module B, causing wrapper miscompilation

Exploitation with WASM type confusion primitives is trivial and has been presented multiple times. (Pwn2Own Vancouver 2024, TyphoonPWN 2024, v8CTF submission 8d4d57cb2258, b/360533914, b/365802567, ...)

Bisect

Bug introduced by commit 2109613 in M123 that attempted to fix a similar bug.

Suggested Fix

Apply the v8 sandbox bypass fix for b/354408144 (https://chromium-review.googlesource.com/c/v8/v8/+/589028) to all affected version immediately, as this is not only a v8 sandbox bypass but a full-blown memory corruption bug. Alternatively, do a targeted fix by correctly referencing the module.

VERSION

See bisect commit release info in Chromium Dash for more info: https://chromiumdash.appspot.com/commit/2109613ad4622028778a38fb418956fab8b478b6

Chrome Version: 123.0.6301.0 ~ latest
Operating System: All

REPRODUCTION CASE

Attached as poc.js which exploits the type confusion to write 0x13371447 into tagged address 0x42424242, causing an access violation. Also attached is exp.html which pops shell on Windows x86-64 Chrome builds, tested on 129.0.6668.90 (latest stable) and 131.0.6757.0 (latest canary).

Note that this bug is capable to bypass v8 sandbox on its own without a separate bypass (see also b/354408144), but in exp.html I just opted to reuse the good old b/350292240.

FOR CRASHES, PLEASE INCLUDE THE FOLLOWING ADDITIONAL INFORMATION

Type of crash: Renderer
Crash State: Crashes on JIT-compiled caged_write().

CREDIT INFORMATION

Reporter credit: Seunghyun Lee (@0x10n) of CMU CyLab

The original report as published on the Chromium issue tracker, by Seunghyun Lee (@0x10n). 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 tier-up runtime function uses the signature from the original importing module instead of the module that actually owns the function table, leading to a mismatch between the signature and the instance data.

Impact

An attacker could exploit this type confusion to achieve arbitrary memory corruption, potentially leading to remote code execution and bypassing the V8 sandbox.

What the attacker needed

Ability to run JavaScript in Chrome; Chrome version 123.0.6301.0 or later

How it was found

  1. Module A imports a JavaScript function.
  2. Module A creates a function table containing the imported function.
  3. Module A exports the function table.
  4. Module B imports the function table from Module A.
  5. Module B triggers a tier-up of the wrapper, causing the signature from Module A to be used with Module B's instance data.

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.

WebAssembly (WASM) is a fast, low-level code format for the web. V8, Chrome's JavaScript engine, sometimes confuses the type information of functions from different WASM modules when they are shared via tables. This confusion can let an attacker write to arbitrary memory, which is a serious security issue.

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 Seunghyun Lee

View all

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