Race condition in V8 (CVE-2026-78901)
A static-analysis report claims that V8's Code::SetMarkedForDeoptimization updates a JSDispatchTable entry without running the required write barrier, so a concurrent marker's mark bit can be erased by a blind store. If true, the entry could be swept and reused, giving trusted-space type confusion and a possible V8 sandbox bypass, though the authors did not dynamically verify it.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 2 months
Project Fortify, an experimental security project, has identified the following potential security issue. If you're a feature owner CC-ed on this bug, please do your best to review these reports. Please see https://chromium.googlesource.com/chromium/src/+/main/docs/security/ai-generated-security-bugs-faq.md for more information.
Overview: A potential race condition exists in V8's concurrent marking and deoptimization logic where Code::SetMarkedForDeoptimization updates a dispatch table entry without running a write barrier. During concurrent marking, a background thread's CAS mark can be overwritten by the mutator's blind store, leading to a live entry being swept. This could result in trusted-space type confusion and a potential V8 sandbox bypass.
Affected files:
v8/src/objects/code.ccv8/src/sandbox/js-dispatch-table-inl.h
Estimated timestamp from git blame: 2024-12-05
Root Cause Analysis
In V8's sandbox design, the JSDispatchTable acts as a protected control-flow integrity (CFI) table mapping JSDispatchHandles to (entrypoint, parameter_count) pairs. To ensure garbage collection correctness during concurrent marking, the table's entries must be marked.
JSDispatchEntry::Mark() is implemented as a single-shot, non-looping CAS:
void JSDispatchEntry::Mark() {
Address old_value = encoded_word_.load(std::memory_order_relaxed);
Address new_value = old_value | kMarkingBit;
static_assert(JSDispatchTable::kWriteBarrierSetsEntryMarkBit);
encoded_word_.compare_exchange_strong(old_value, new_value,
std::memory_order_relaxed);
}
Conversely, modifying an entry via SetCodeAndEntrypointPointer() performs a relaxed load, computes the new payload preserving the loaded marking bit, and writes it back via a blind store:
void JSDispatchEntry::SetCodeAndEntrypointPointer(Address new_object,
Address new_entrypoint) {
Address old_payload = encoded_word_.load(std::memory_order_relaxed);
Address marking_bit = old_payload & kMarkingBit;
...
Address new_payload = object | marking_bit | parameter_count;
entrypoint_.store(new_entrypoint, std::memory_order_relaxed);
encoded_word_.store(new_payload, std::memory_order_release);
}
Because of this design, if concurrent marking sets the mark bit (using Mark()) after the modifier has loaded old_payload but before it executes its blind store, the mark bit will be silently overwritten and erased. To prevent this, V8 enforces an invariant that every modifier must invoke WriteBarrier::ForJSDispatchHandle after modifying an entry, which re-runs jdt.Mark(handle) and restores the mark bit if it was erased.
However, Code::SetMarkedForDeoptimization() in v8/src/objects/code.cc violates this invariant. It updates dispatch table entries using jdt.SetCodeNoWriteBarrier() but fails to execute a follow-up write barrier:
// v8/src/objects/code.cc
jdt.SetCodeNoWriteBarrier(
handle, *BUILTIN_CODE(isolate, InterpreterEntryTrampoline));
...
jdt.SetCodeNoWriteBarrier(handle, *BUILTIN_CODE(isolate, CompileLazy));
Potential Trigger Path
Based on static analysis, the following sequence of events could potentially trigger this vulnerability:
- Optimized Code Creation: A function is compiled into optimized code, and its
Codeobject hasjs_dispatch_handleset. - Concurrent Marking: A major GC cycle begins. A background marking thread visits the
JSFunctionor itsFeedbackCell, callingjdt.Mark(handle)and marking the entry. - Deoptimization & Race: Concurrently, the main thread invalidates a code dependency (e.g., prototype change) and runs
Code::SetMarkedForDeoptimization. - Interleaved Execution:
- The main thread executes
SetCodeAndEntrypointPointer, loading the entry's state withmarking_bit = 0(assuming it is called before the marker's CAS succeeds or during a separate marking sweep where the marker re-evaluates the handle). - The background marking thread successfully executes
Mark(), setting the marking bit to1. - The main thread performs the blind store of
new_payload(withmarking_bit = 0), erasing the mark bit.
- The main thread executes
- Sweeping: Because the update was done via
SetCodeNoWriteBarrierand no follow-up write barrier was executed, the entry remains unmarked. When the GC sweeps theJSDispatchTableviaGenericSweep, it reclaims the entry and adds it to the free list. - Use-After-Free: If the slot is subsequently reallocated for another function, calling the original
JSFunctionwill jump to the new entry point with potentially mismatched signatures, leading to trusted-space type confusion.
Note: These steps are based on static code analysis; our tooling does not currently have the capability to run or dynamically verify this concurrent execution behavior.
Proposed Fix
To resolve this issue, a write barrier should be executed after updating the dispatch table entry in Code::SetMarkedForDeoptimization.
In v8/src/objects/code.cc:
jdt.SetCodeNoWriteBarrier(
handle, *BUILTIN_CODE(isolate, InterpreterEntryTrampoline));
WriteBarrier::ForJSDispatchHandle(this, handle);
And similarly for the CompileLazy path.
Evaluated with Chrome root at commit: 75203b87cbf6681eb7c7dda8e1d0bf781538c76a
Results so far have been promising, but there can be wrong deductions. Feel free to adjust as follows:
- If you are familiar with the severity guidelines, you may adjust the severity.
- If this is a false positive, and there's no work to be done, please close as WAI.
- If there is work to do here but not a vulnerability, please change the issue type to Task/Bug/FR.
Data from false positives will be used to improve accuracy over time. And please feel free to reach out to me directly if you have concerns or feedback on the project.
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 a missing write barrier: Code::SetMarkedForDeoptimization uses SetCodeNoWriteBarrier, so a concurrent marker's CAS-set mark bit can be overwritten by the mutator's blind store and the entry is swept.
Impact
Could lead to trusted-space type confusion and a potential V8 sandbox bypass, but the report is based on static analysis only and was not dynamically verified.
What the attacker needed
Concurrent marking GC cycle; deoptimization of optimised code; precise thread interleaving
The fix
A write barrier should be executed after updating the dispatch table entry in Code::SetMarkedForDeoptimization, for both the interpreter trampoline and CompileLazy paths.
How it was found
- Compile a function into optimized code so its Code object has a js_dispatch_handle.
- Start a major GC so a background marking thread calls jdt.Mark(handle) on the entry.
- Concurrently trigger deoptimization on the main thread, which runs Code::SetMarkedForDeoptimization.
- Interleave so the main thread loads the entry with the mark bit clear, the marker sets it, then the main thread's blind store erases it.
- The GC sweeps the JSDispatchTable and reclaims the unmarked entry into the free list.
- If the slot is reallocated, calling the original function jumps to a mismatched entry point.
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.
V8 is the JavaScript engine in Chrome. It keeps a table of small records that say where each function's code starts, and the garbage collector (the part that frees unused memory) marks records it still needs. This report says one code path changes such a record without telling the collector, so the collector can wrongly free it and later hand the slot to a different function, which could let an attacker confuse the engine about what code is running.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.