Inappropriate implementation in V8 (CVE-2024-6772)
A bug in V8's garbage collector (GC) stack scanning for WebAssembly-to-JavaScript wrappers could cause memory corruption when JSPI stack switching is used. An attacker could potentially exploit this to corrupt memory, though the report does not demonstrate a full exploit.
5fceb6172bbf7e2c5a948183b53565b9 Follow
Originally disclosed on Chrome VRP
- Fix shipped in 35 days
TITLE
A security issue related to jspi stack switching
VULNERABILITY DETAILS
During GC, TypedFrame::Iterate may be executed to visit those params on stack.
And when JSPI is used, wasm runs on a secondary stack. But during running js imports, it switches to the central stack.
The flags to decide whether it switches to the central stack are the value of is_wasm_to_js and the value at offset WasmToJSWrapperConstants::kCentralStackSPOffset.
In TypedFrame::Iterate:
void TypedFrame::Iterate(RootVisitor* v) const {
...
bool is_wasm_to_js =
code->is_builtin() && code->builtin_id() == Builtin::kWasmToJsWrapperCSA;
...
#if V8_ENABLE_WEBASSEMBLY
// Load the central stack SP value from the fixed slot.
// If it is null, the import wrapper didn't switch and the layout is the same
// as regular typed frames: the outgoing stack parameters end where the spill
// area begins.
// Otherwise, it holds the address in the central stack where the import
// wrapper switched to before pushing the outgoing stack parameters and
// calling the target. It marks the limit of the stack param area, and is
// distinct from the beginning of the spill area.
Address central_stack_sp =
Memory<Address>(fp() + WasmToJSWrapperConstants::kCentralStackSPOffset);
FullObjectSlot parameters_limit(
is_wasm_to_js && central_stack_sp != kNullAddress
? central_stack_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()));
...
}
We calculate the parameters_limit in different ways under stack switching, and then the parameters_base.
Then, params between parameters_base and parameters_limit gets visited.
// Visit the rest of the parameters.
if (HasTaggedOutgoingParams(code)) {
v->VisitRootPointers(Root::kStackRoots, nullptr, parameters_base,
parameters_limit);
}
However, I found that in a specific situation, during running gc in js imports, the fp() points to the secondary stack, while is_wasm_to_js is false and the value at offset WasmToJSWrapperConstants::kCentralStackSPOffset is kNullAddress.
Thus, parameters_limit points to the secondary stack, and the parameters_base points to the central stack. VisitRootPointers will then trigger memory corruptions during the for loop.
void VisitRootPointers(Root root, const char* description,
FullObjectSlot start, FullObjectSlot end) override {
for (FullObjectSlot p = start; p < end; ++p) {
ClearLeftTrimmedOrForward(root, description, p);
}
}
Here is the situation:
The StackFrameIterator judges the frame type with function StackFrameIterator::ComputeStackFrameType. And for wasm wrappers:
// If the {pc} does not point into WebAssembly code we can rely on the
// returned {wasm_code} to be null and fall back to {GetContainingCode}.
if (wasm::WasmCode* wasm_code =
wasm::GetWasmCodeManager()->LookupCode(isolate(), pc)) {
switch (wasm_code->kind()) {
case wasm::WasmCode::kWasmFunction:
return StackFrame::WASM;
case wasm::WasmCode::kWasmToCapiWrapper:
return StackFrame::WASM_EXIT;
case wasm::WasmCode::kWasmToJsWrapper:
return StackFrame::WASM_TO_JS;
default:
UNREACHABLE();
}
}
However, for WasmToJSWrapper with origin of type WasmFuncRef, the compiled code will not be added to the code manager of the module.
RUNTIME_FUNCTION(Runtime_TierUpWasmToJSWrapper) {
...
if (IsWasmFuncRef(*origin)) {
...
Handle<Code> wasm_to_js_wrapper_code =
compiler::CompileWasmToJSWrapper(
isolate, &sig, kind, static_cast<int>(expected_arity),
static_cast<wasm::Suspend>(ref->suspend()))
.ToHandleChecked();
// We have to install the optimized wrapper as `code`, as the generated
// code may move. `call_target` would become stale then.
Handle<WasmInternalFunction> internal_function{
WasmFuncRef::cast(*origin)->internal(isolate), isolate};
ref->set_code(*wasm_to_js_wrapper_code);
internal_function->set_call_target(
Builtins::EntryOf(Builtin::kWasmToOnHeapWasmToJsTrampoline, isolate));
return ReadOnlyRoots(isolate).undefined_value();
}
Therefore, it does not get the frame type WASM_TO_JS and only keeps the TypedFrame. However, TypedFrame::Iterate dose not work for this situation.
I construct a POC to prove it.
You can run it at the latest version of v8 (commit 0ba42aeb3a431168a13f0a456b8e878d511afde9)
You should use python3 tools\dev\gm.py x64.debug to build v8.
or just use the one from https://www.googleapis.com/download/storage/v1/b/v8-asan/o/win64-debug%2Fd8-asan-win64-debug-v8-component-94385.zip?generation=1718138752805769&alt=media
commond line:
out\x64.debug\d8.exe --expose-gc --wasm-wrapper-tiering-budget=1 --experimental-wasm-jspi poc.js
VERSION
Chrome Version: V8 12.8.0
Operating System: Windows
Context
V8 is Chrome's JavaScript and WebAssembly engine. One of its newer WebAssembly features is JSPI (JavaScript Promise Integration), which lets WebAssembly code suspend and resume around JavaScript promises. To make that work, WebAssembly code can run on a secondary stack, and when it calls into JavaScript it switches to the central stack.
Garbage collection in V8 has to walk the stack and visit every tagged pointer it finds in stack frames. For frames produced by the WebAssembly-to-JavaScript import wrapper, the layout of the outgoing parameters depends on whether the wrapper switched to the central stack. The report describes a case where that layout is misjudged, so the collector walks a range of memory that spans two different stacks.
The issue was tracked as CVE-2024-6772, an inappropriate implementation in V8, rated high severity, with a bounty of 10,000 USD, disclosed on 16 July 2024.
Setup
The researcher built V8 at commit [redacted] (reported as V8 12.8.0) on Windows, using the debug configuration:
python3 tools\dev\gm.py x64.debug
A prebuilt ASan Windows debug build of d8 was also referenced. The proof of concept is run with the following command line:
out\x64.debug\d8.exe --expose-gc --wasm-wrapper-tiering-budget=1 --experimental-wasm-jspi poc.js
The command line uses --expose-gc, --experimental-wasm-jspi and --wasm-wrapper-tiering-budget=1; the report does not explain each flag.
Finding it
During GC, TypedFrame::Iterate visits the outgoing parameters held on the stack. When JSPI is in use, WebAssembly runs on a secondary stack, but while a JavaScript import is running it switches to the central stack. Two things decide whether the switch happened: the value of is_wasm_to_js, and the value stored at offset WasmToJSWrapperConstants::kCentralStackSPOffset.
The relevant code in TypedFrame::Iterate is:
void TypedFrame::Iterate(RootVisitor* v) const {
...
bool is_wasm_to_js =
code->is_builtin() && code->builtin_id() == Builtin::kWasmToJsWrapperCSA;
...
#if V8_ENABLE_WEBASSEMBLY
// Load the central stack SP value from the fixed slot.
// If it is null, the import wrapper didn't switch and the layout is the same
// as regular typed frames: the outgoing stack parameters end where the spill
// area begins.
// Otherwise, it holds the address in the central stack where the import
// wrapper switched to before pushing the outgoing stack parameters and
// calling the target. It marks the limit of the stack param area, and is
// distinct from the beginning of the spill area.
Address central_stack_sp =
Memory<Address>(fp() + WasmToJSWrapperConstants::kCentralStackSPOffset);
FullObjectSlot parameters_limit(
is_wasm_to_js && central_stack_sp != kNullAddress
? central_stack_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()));
...
}
So parameters_limit is computed differently when the stack was switched, and parameters_base is taken from the current stack pointer. The parameters between the two are then visited:
// Visit the rest of the parameters.
if (HasTaggedOutgoingParams(code)) {
v->VisitRootPointers(Root::kStackRoots, nullptr, parameters_base,
parameters_limit);
}
The researcher found a specific situation during GC inside a JavaScript import where fp() points to the secondary stack, while is_wasm_to_js is false and the value at WasmToJSWrapperConstants::kCentralStackSPOffset is kNullAddress. In that state parameters_limit points into the secondary stack and parameters_base points into the central stack. VisitRootPointers then iterates over that range:
void VisitRootPointers(Root root, const char* description,
FullObjectSlot start, FullObjectSlot end) override {
for (FullObjectSlot p = start; p < end; ++p) {
ClearLeftTrimmedOrForward(root, description, p);
}
}
Because the two ends of the range belong to different stacks, the loop walks memory that is not a contiguous parameter area, which the report describes as triggering memory corruption.
The question is how is_wasm_to_js can be false for a frame that really is a WebAssembly-to-JavaScript wrapper. StackFrameIterator decides the frame type in StackFrameIterator::ComputeStackFrameType, and for wasm wrappers it relies on the code manager:
// If the {pc} does not point into WebAssembly code we can rely on the
// returned {wasm_code} to be null and fall back to {GetContainingCode}.
if (wasm::WasmCode* wasm_code =
wasm::GetWasmCodeManager()->LookupCode(isolate(), pc)) {
switch (wasm_code->kind()) {
case wasm::WasmCode::kWasmFunction:
return StackFrame::WASM;
case wasm::WasmCode::kWasmToCapiWrapper:
return StackFrame::WASM_EXIT;
case wasm::WasmCode::kWasmToJsWrapper:
return StackFrame::WASM_TO_JS;
default:
UNREACHABLE();
}
}
For a WasmToJSWrapper whose origin is a WasmFuncRef, however, the compiled code is never added to the module's code manager. The tier-up runtime function shows the path:
RUNTIME_FUNCTION(Runtime_TierUpWasmToJSWrapper) {
...
if (IsWasmFuncRef(*origin)) {
...
Handle<Code> wasm_to_js_wrapper_code =
compiler::CompileWasmToJSWrapper(
isolate, &sig, kind, static_cast<int>(expected_arity),
static_cast<wasm::Suspend>(ref->suspend()))
.ToHandleChecked();
// We have to install the optimized wrapper as `code`, as the generated
// code may move. `call_target` would become stale then.
Handle<WasmInternalFunction> internal_function{
WasmFuncRef::cast(*origin)->internal(isolate), isolate};
ref->set_code(*wasm_to_js_wrapper_code);
internal_function->set_call_target(
Builtins::EntryOf(Builtin::kWasmToOnHeapWasmToJsTrampoline, isolate));
return ReadOnlyRoots(isolate).undefined_value();
}
Since the code is not registered with the code manager, LookupCode does not return a kWasmToJsWrapper entry for it, the frame is not classified as WASM_TO_JS, and it stays a plain TypedFrame. TypedFrame::Iterate was not written to handle this combination, which is the mismatch the researcher set out to prove.
Exploitation
Step 1: build a debug V8
The researcher built V8 at the stated commit with the debug configuration shown above, or used the published ASan Windows debug build of d8.
Step 2: run the proof of concept with the required flags
The PoC is executed as:
out\x64.debug\d8.exe --expose-gc --wasm-wrapper-tiering-budget=1 --experimental-wasm-jspi poc.js
The report gives the command line but does not explain how the flag reaches the tier-up path.
The report does not include the contents of poc.js or the observed crash output; it states only that the PoC proves the situation.
Root cause
The frame type classification and the frame iteration logic disagree about what a wrapper frame looks like. StackFrameIterator::ComputeStackFrameType identifies a WebAssembly-to-JavaScript wrapper by asking the wasm code manager about the program counter. Wrapper code compiled for a WasmFuncRef origin during tier-up is installed directly on the internal function and is never added to the code manager, so the lookup misses and the frame is treated as an ordinary TypedFrame.
TypedFrame::Iterate then assumes that a frame which is not is_wasm_to_js has its outgoing parameters ending at the spill area on the same stack. Under JSPI the frame is on the secondary stack while the parameters base is read from the current stack pointer on the central stack, so the computed range crosses from one stack to the other. The visitor loop then walks and clears or forwards slots over memory that is not a parameter area.
Impact
In the reported situation, garbage collection visits an invalid range of stack memory, which the researcher describes as memory corruption. The corruption happens inside the engine during GC, in a build with JSPI enabled and after wrapper tier-up has produced code for a WasmFuncRef origin. The report does not describe a concrete exploitation primitive, a sandbox escape, or which process the corruption affects beyond V8 itself.
Fix
Variants to test
- A positive result is a wrapper frame that
ComputeStackFrameTypeclassifies as something other thanWASM_TO_JSwhile it is executing. - A positive result is a GC that runs while the wrapper frame is on the secondary stack and the central stack slot is null.
- A positive result is a
parameters_baseandparameters_limitthat fall on different stacks. - A positive result is a report from the collector's visit loop over the mismatched range.
What happened, in plain words
Chrome runs JavaScript and WebAssembly using a piece of software called V8. V8 is the engine under the bonnet: it reads the code on a web page and executes it. A newer WebAssembly feature called JSPI lets WebAssembly code pause and resume around JavaScript promises (a promise is JavaScript's way of saying "this result will arrive later"). To make that work, V8 sometimes runs WebAssembly code on a second, separate stack.
A stack is a region of memory used like a pile of notes: each function call puts a note on top, and when the function finishes the note is removed. V8 normally has one main stack, called the central stack here. JSPI adds a secondary stack so that suspended WebAssembly work can be parked without blocking the main one.
V8 also has a garbage collector. It periodically tidies up memory, freeing objects nobody uses any more. To do that safely it walks the stack and looks at every slot that might hold a pointer to an object, so it can update or clear those pointers. The report is about a case where the collector walks a range of memory that starts on one stack and ends on the other. That range is not a real list of parameters, so the collector reads and writes memory it should not touch. The report calls this memory corruption.
The issue was tracked as CVE-2024-6772, described as an inappropriate implementation in V8, rated high severity, with a bounty of 10,000 USD, disclosed on 16 July 2024.
Setup
The researcher built V8 from source at commit [redacted], reported as V8 12.8.0, on Windows, in the debug configuration. A debug build keeps extra checks and symbols, which makes problems easier to see.
python3 tools\dev\gm.py x64.debug
Line by line:
python3runs the Python interpreter, version 3.tools\dev\gm.pyis a helper script inside the V8 source tree that drives the build. The backslashes are Windows path separators.x64.debugasks for a 64-bit debug build.
A prebuilt Windows debug build of d8 with AddressSanitizer (ASan, a tool that detects memory errors) was also referenced. d8 is V8's own command-line shell: a small program that runs JavaScript and WebAssembly without a browser around it, which is handy for testing the engine directly.
The proof of concept is run with this command line:
out\x64.debug\d8.exe --expose-gc --wasm-wrapper-tiering-budget=1 --experimental-wasm-jspi poc.js
Line by line:
out\x64.debug\d8.exeis the built shell executable.poc.jsis the script that demonstrates the problem.
Finding it
During garbage collection, a function called TypedFrame::Iterate visits the outgoing parameters held on the stack. A frame is one function call's slice of the stack; outgoing parameters are the values a caller is passing to the function it is about to call. When JSPI is in use, WebAssembly runs on the secondary stack, but while a JavaScript import is running it switches to the central stack. An import here means WebAssembly calling out to a JavaScript function.
Two things decide whether the switch happened: the value of is_wasm_to_js, a true or false flag saying whether this frame is a WebAssembly-to-JavaScript wrapper, and the value stored at offset WasmToJSWrapperConstants::kCentralStackSPOffset, a fixed slot in the frame that records where on the central stack the switch happened.
The relevant code in TypedFrame::Iterate is:
void TypedFrame::Iterate(RootVisitor* v) const {
...
bool is_wasm_to_js =
code->is_builtin() && code->builtin_id() == Builtin::kWasmToJsWrapperCSA;
...
#if V8_ENABLE_WEBASSEMBLY
// Load the central stack SP value from the fixed slot.
// If it is null, the import wrapper didn't switch and the layout is the same
// as regular typed frames: the outgoing stack parameters end where the spill
// area begins.
// Otherwise, it holds the address in the central stack where the import
// wrapper switched to before pushing the outgoing stack parameters and
// calling the target. It marks the limit of the stack param area, and is
// distinct from the beginning of the spill area.
Address central_stack_sp =
Memory<Address>(fp() + WasmToJSWrapperConstants::kCentralStackSPOffset);
FullObjectSlot parameters_limit(
is_wasm_to_js && central_stack_sp != kNullAddress
? central_stack_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()));
...
}
Line by line:
void TypedFrame::Iterate(RootVisitor* v) const {starts the function that walks a typed frame during collection.RootVisitoris the object that receives each pointer found.bool is_wasm_to_js = code->is_builtin() && code->builtin_id() == Builtin::kWasmToJsWrapperCSA;sets the flag to true only if the frame's code is a built-in and specifically the WebAssembly-to-JavaScript wrapper built-in.#if V8_ENABLE_WEBASSEMBLYincludes the following lines only in builds with WebAssembly support.Address central_stack_sp = Memory<Address>(fp() + WasmToJSWrapperConstants::kCentralStackSPOffset);reads the saved central stack pointer from a fixed slot relative to the frame pointerfp().FullObjectSlot parameters_limit(...)computes the end of the parameter range. If the frame is a WebAssembly-to-JavaScript wrapper and the saved central stack pointer is not null, the limit is that saved pointer. Otherwise the limit is the start of the frame header minus the spill area size, meaning the parameters end where the spill area begins on the same stack.#elseand the following lines give the same fallback limit for builds without WebAssembly.FullObjectSlot parameters_base(&Memory<Address>(sp()));sets the start of the parameter range from the current stack pointersp().
So parameters_limit is computed differently when the stack was switched, and parameters_base is taken from the current stack pointer. The parameters between the two are then visited:
// Visit the rest of the parameters.
if (HasTaggedOutgoingParams(code)) {
v->VisitRootPointers(Root::kStackRoots, nullptr, parameters_base,
parameters_limit);
}
Line by line:
if (HasTaggedOutgoingParams(code)) {checks whether this kind of code passes pointers as outgoing parameters at all.v->VisitRootPointers(Root::kStackRoots, nullptr, parameters_base, parameters_limit);asks the visitor to process every slot fromparameters_baseup toparameters_limit, telling it these are stack roots, meaning pointers the collector must keep alive.
The researcher found a specific situation during collection inside a JavaScript import where fp() points to the secondary stack, while is_wasm_to_js is false and the value at WasmToJSWrapperConstants::kCentralStackSPOffset is kNullAddress (null). In that state parameters_limit points into the secondary stack and parameters_base points into the central stack. VisitRootPointers then iterates over that range:
void VisitRootPointers(Root root, const char* description,
FullObjectSlot start, FullObjectSlot end) override {
for (FullObjectSlot p = start; p < end; ++p) {
ClearLeftTrimmedOrForward(root, description, p);
}
}
Line by line:
void VisitRootPointers(Root root, const char* description, FullObjectSlot start, FullObjectSlot end) override {declares the visitor's handler for a range of slots, fromstarttoend.for (FullObjectSlot p = start; p < end; ++p) {walks slot by slot from start to end.ClearLeftTrimmedOrForward(root, description, p);processes each slot, either clearing it or forwarding it to the object's new location after collection.
Because the two ends of the range belong to different stacks, the loop walks memory that is not a contiguous parameter area. The report describes this as triggering memory corruption.
The question is how is_wasm_to_js can be false for a frame that really is a WebAssembly-to-JavaScript wrapper. StackFrameIterator decides the frame type in StackFrameIterator::ComputeStackFrameType, and for wasm wrappers it relies on the code manager, a registry of compiled WebAssembly code:
// If the {pc} does not point into WebAssembly code we can rely on the
// returned {wasm_code} to be null and fall back to {GetContainingCode}.
if (wasm::WasmCode* wasm_code =
wasm::GetWasmCodeManager()->LookupCode(isolate(), pc)) {
switch (wasm_code->kind()) {
case wasm::WasmCode::kWasmFunction:
return StackFrame::WASM;
case wasm::WasmCode::kWasmToCapiWrapper:
return StackFrame::WASM_EXIT;
case wasm::WasmCode::kWasmToJsWrapper:
return StackFrame::WASM_TO_JS;
default:
UNREACHABLE();
}
}
Line by line:
- The comment explains that if the program counter
pcdoes not point into WebAssembly code, the lookup returns null and the code falls back to another way of finding the containing code. if (wasm::WasmCode* wasm_code = wasm::GetWasmCodeManager()->LookupCode(isolate(), pc)) {asks the code manager which compiled WebAssembly code contains the current program counter.switch (wasm_code->kind()) {branches on the kind of that code.case wasm::WasmCode::kWasmFunction: return StackFrame::WASM;a normal WebAssembly function gives a WebAssembly frame.case wasm::WasmCode::kWasmToCapiWrapper: return StackFrame::WASM_EXIT;a wrapper calling out to C gives an exit frame.case wasm::WasmCode::kWasmToJsWrapper: return StackFrame::WASM_TO_JS;a wrapper calling out to JavaScript gives the WebAssembly-to-JavaScript frame type.default: UNREACHABLE();any other kind is treated as impossible.
For a WasmToJSWrapper whose origin is a WasmFuncRef, however, the compiled code is never added to the module's code manager. A WasmFuncRef is a reference to a WebAssembly function held as a value. The tier-up runtime function shows the path:
RUNTIME_FUNCTION(Runtime_TierUpWasmToJSWrapper) {
...
if (IsWasmFuncRef(*origin)) {
...
Handle<Code> wasm_to_js_wrapper_code =
compiler::CompileWasmToJSWrapper(
isolate, &sig, kind, static_cast<int>(expected_arity),
static_cast<wasm::Suspend>(ref->suspend()))
.ToHandleChecked();
// We have to install the optimized wrapper as `code`, as the generated
// code may move. `call_target` would become stale then.
Handle<WasmInternalFunction> internal_function{
WasmFuncRef::cast(*origin)->internal(isolate), isolate};
ref->set_code(*wasm_to_js_wrapper_code);
internal_function->set_call_target(
Builtins::EntryOf(Builtin::kWasmToOnHeapWasmToJsTrampoline, isolate));
return ReadOnlyRoots(isolate).undefined_value();
}
Line by line:
RUNTIME_FUNCTION(Runtime_TierUpWasmToJSWrapper) {declares a runtime function, a helper the engine can call from generated code, whose job is to upgrade a WebAssembly-to-JavaScript wrapper to an optimised version.if (IsWasmFuncRef(*origin)) {checks whether the wrapper's origin is aWasmFuncRef.Handle<Code> wasm_to_js_wrapper_code = compiler::CompileWasmToJSWrapper(...)compiles the optimised wrapper. The arguments pass the isolate (the engine instance), the signature, the kind, the expected number of arguments, and whether the wrapper can suspend.- The comment explains why the code is stored on the function object: the generated code may move, so a stored call target would become stale.
Handle<WasmInternalFunction> internal_function{...}gets the internal function object behind theWasmFuncRef.ref->set_code(*wasm_to_js_wrapper_code);installs the new code directly on the wrapper reference.internal_function->set_call_target(Builtins::EntryOf(Builtin::kWasmToOnHeapWasmToJsTrampoline, isolate));points the call target at a trampoline built-in, a small piece of code that jumps to the real target.return ReadOnlyRoots(isolate).undefined_value();returns JavaScript'sundefinedto signal completion.
Since the code is not registered with the code manager, LookupCode does not return a kWasmToJsWrapper entry for it, the frame is not classified as WASM_TO_JS, and it stays a plain TypedFrame. TypedFrame::Iterate was not written to handle this combination, which is the mismatch the researcher set out to prove.
Exploitation
Step 1: build a debug V8
The researcher built V8 at the stated commit with the debug configuration shown above, or used the published ASan Windows debug build of d8.
Step 2: run the proof of concept with the required flags
The PoC is executed as:
out\x64.debug\d8.exe --expose-gc --wasm-wrapper-tiering-budget=1 --experimental-wasm-jspi poc.js
The report does not include the contents of poc.js or the observed crash output; it states only that the PoC proves the situation.
Root cause
The frame type classification and the frame iteration logic disagree about what a wrapper frame looks like. StackFrameIterator::ComputeStackFrameType identifies a WebAssembly-to-JavaScript wrapper by asking the wasm code manager about the program counter. Wrapper code compiled for a WasmFuncRef origin during tier-up is installed directly on the internal function and is never added to the code manager, so the lookup misses and the frame is treated as an ordinary TypedFrame.
TypedFrame::Iterate then assumes that a frame which is not is_wasm_to_js has its outgoing parameters ending at the spill area on the same stack. The spill area is the part of a frame where values are saved temporarily. Under JSPI the frame is on the secondary stack while the parameters base is read from the current stack pointer on the central stack, so the computed range crosses from one stack to the other. The visitor loop then walks and clears or forwards slots over memory that is not a parameter area.
Impact
In the reported situation, garbage collection visits an invalid range of stack memory, which the researcher describes as memory corruption. The corruption happens inside the engine during collection, in a build with JSPI enabled and after wrapper tier-up has produced code for a WasmFuncRef origin. The report does not describe a concrete exploitation primitive, a sandbox escape, or which process the corruption affects beyond V8 itself.
Fix
The report does not describe the fix that was applied.
Variants to test
- A positive result is a wrapper frame that
ComputeStackFrameTypeclassifies as something other thanWASM_TO_JSwhile it is executing. - A positive result is a collection that runs while the wrapper frame is on the secondary stack and the central stack slot is null.
- A positive result is a
parameters_baseandparameters_limitthat fall on different stacks. - A positive result is a report from the collector's visit loop over the mismatched range.
Glossary
- API: a defined way for one piece of software to ask another to do something, like a menu of allowed requests.
- ASan (AddressSanitizer): a tool built into a program that detects invalid memory reads and writes and reports them.
- Built-in: a piece of code that ships inside the engine itself rather than being compiled from a page's script.
- Central stack: the main stack V8 normally uses for function calls.
- Code manager: V8's registry of compiled WebAssembly code, used to look up which code a program counter belongs to.
- Commit: a fixed snapshot of a source code repository, identified by a long hexadecimal string.
- CVE: a public identifier for a known security vulnerability.
- d8: V8's command-line shell for running JavaScript and WebAssembly outside a browser.
- Debug build: a version of a program compiled with extra checks and symbols to make problems easier to find.
- Frame: one function call's slice of the stack, holding its saved state and parameters.
- Frame pointer (
fp()): a register or value pointing at the current frame on the stack. - Garbage collection (GC): the automatic process of finding and freeing memory no longer in use.
- Import: a call from WebAssembly code out to a JavaScript function.
- Inappropriate implementation: a vulnerability category meaning the code does not implement its intended behaviour correctly, leading to a security problem.
- Isolate: one independent instance of the V8 engine.
- JSPI (JavaScript Promise Integration): a WebAssembly feature that lets WebAssembly code pause and resume around JavaScript promises.
- Memory corruption: a bug where a program reads or writes memory it should not, potentially changing data or crashing.
- Null (
kNullAddress): a value of zero, used here to mean "no address recorded". - Offset: a fixed distance from a starting point, used to locate a particular slot in memory.
- Outgoing parameters: the values a caller passes to the function it is about to call.
- Program counter (pc): the address of the instruction currently executing.
- Promise: JavaScript's mechanism for a result that will arrive later.
- Proof of concept (PoC): a small script or program that demonstrates a bug really happens.
- Root: a pointer the garbage collector treats as a starting point, keeping the object it points to alive.
- Secondary stack: an extra stack used by JSPI so suspended WebAssembly work can be parked.
- Spill area: the part of a frame where values are saved temporarily.
- Stack: a region of memory used like a pile of notes, where each function call adds a note and each return removes one.
- Stack pointer (
sp()): a value pointing at the current top of the stack. - Tier-up: upgrading code from a simple version to an optimised one while the program runs.
- Trampoline: a small piece of code that jumps to the real target.
- V8: the JavaScript and WebAssembly engine inside Chrome.
- Visitor: an object that receives each pointer the collector finds so it can process it.
- WasmFuncRef: a WebAssembly value that refers to a WebAssembly function.
- WebAssembly: a fast, low-level language that runs in browsers alongside JavaScript.
- Wrapper: code that adapts a call from one environment to another, here from WebAssembly to JavaScript.