Use after free in V8 (CVE-2026-14426)
A use-after-free in V8's inspector allows a dangling pointer to an InspectedContext to be used after it is freed, because a JavaScript setter can trigger context destruction during addBinding. An attacker with a DevTools session or debugger permission could achieve an arbitrary address write outside the V8 sandbox.
Originally disclosed on Chrome VRP
- Fix shipped in 32 days
Steps to reproduce the problem
Environment
- V8 source: 15.0.0 (Chromium-tracked)
- Tested commit:
6ac60d22f45(HEAD as of 2026-05-30) - Platform: Linux x86_64
Required builds
Build A (ASan + sandbox + memory-corruption-api): out_asan/inspector-test
args.gn:
is_debug = false
dcheck_always_on = true
v8_enable_sandbox = true
v8_enable_memory_corruption_api = true
v8_enable_test_features = true
v8_enable_verify_heap = true
is_asan = true
target_cpu = "x64"
Build B (Non-ASan, sandbox + memory-corruption-api): out_sandbox/inspector-test
Same args.gn but is_asan = false.
Build commands:
gn gen out_asan
gn gen out_sandbox
autoninja -C out_asan inspector-test
autoninja -C out_sandbox inspector-test
Attached PoCs
poc-asan.js(ASan UAF reproduction)poc-sandbox-violation.js(sandbox bypass with WRITE classification)
Step 1: ASan UAF reproduction
Command (from V8 source root):
ASAN_OPTIONS='abort_on_error=0:halt_on_error=1:detect_leaks=0' \
./out_asan/inspector-test \
test/inspector/protocol-test.js \
poc-asan.js
Expected stderr (key sections):
==XXXXX==ERROR: AddressSanitizer: heap-use-after-free
on address 0xXXXX...
READ of size 8 at 0xXXXX thread T7 (Task Runner)
#0 in std::__Cr::__hash_table<int, ...>::__emplace_unique<...>
lambda at __hash_table:531:67
#1 in v8_inspector::InspectedContext::setReported
try_key_extraction.h:44:10
#2 in v8_inspector::V8RuntimeAgentImpl::reportExecutionContextCreated
src/inspector/v8-runtime-agent-impl.cc:1190:12
#3 in v8_inspector::V8InspectorImpl::forEachSession
#4 in v8_inspector::V8InspectorImpl::contextCreated
src/inspector/v8-inspector-impl.cc:308:3
...
0xXXXX is located 144 bytes inside of 232-byte region [0xXXXX, 0xXXXX)
freed by thread T7:
#0 operator delete(void*, unsigned long)
#1 V8InspectorImpl::contextCollected
...
previously allocated by thread T7:
#0 operator new(unsigned long)
#1 V8InspectorImpl::contextCreated
src/inspector/v8-inspector-impl.cc:288
...
Verification: ASan reports heap-use-after-free on a 232-byte region; the freed object is the InspectedContext allocated at v8-inspector-impl.cc:288; the read is at offset +144 reached from setReported → reportExecutionContextCreated.
Step 2: WRITE-classification sandbox violation
Command:
UBSAN_OPTIONS='print_stacktrace=0:halt_on_error=0:abort_on_error=0:handle_segv=0:handle_sigbus=0:handle_sigill=0' \
setarch -R \
./out_sandbox/inspector-test \
--sandbox-testing \
test/inspector/protocol-test.js \
poc-sandbox-violation.js
Flag notes:
setarch -Rdisables ASLR so the target binary loads at the fixed PIE base0x555555554000+. A small r--p mapping at file offset0x07f03000(memory0x55555d45a000-0x55555d45b000) whose first 16 bytes are zero is used as the WRITE target.--sandbox-testingenables the V8 sandbox crash filter (src/sandbox/testing.cc).UBSAN_OPTIONS handle_segv=0prevents UBSan's signal handler from preempting the sandbox crash filter so the filter can classify the access type.
Expected stderr:
Sandbox testing mode is enabled. Only sandbox violations will be
reported, all other crashes will be ignored.
Sandbox bounds: [0xXXXXXXXXXXXX, 0xXXXXXXXXXXXX)
...
## V8 sandbox violation detected!
(Process exits with signal 11 / SIGSEGV)
Verification: The crash filter prints ## V8 sandbox violation detected! with NO "read access" caveat following. Per src/sandbox/testing.cc:1209-1213, that caveat is added only for read access; its absence confirms WRITE access classification via the SIGSEGV error code's kWriteAccessBit checked at testing.cc:898-907 GetAccessType. This satisfies docs/security/triaging.md's requirement: "A successful bypass must show write access outside of the sandbox."
Step 3: Determinism check
Command (bash):
for i in 1 2 3 4 5; do
echo "--- Attempt $i ---"
UBSAN_OPTIONS='print_stacktrace=0:halt_on_error=0:abort_on_error=0:handle_segv=0:handle_sigbus=0:handle_sigill=0' \
timeout 15 setarch -R \
./out_sandbox/inspector-test --sandbox-testing \
test/inspector/protocol-test.js \
poc-sandbox-violation.js 2>&1 \
| grep -A2 "V8 sandbox" | head -5
done
Problem Description
Summary
Use-after-free on InspectedContext (sizeof=232) allocated on the libc C++ heap OUTSIDE the V8 sandbox cage. The freed object is dereferenced inside the contextCreated lambda's call to reportExecutionContextCreated. The attached PoCs demonstrate the bug and show that successful exploitation yields an Arbitrary Address Write (AAW) primitive outside the V8 sandbox cage.
Affected code
src/inspector/v8-inspector-impl.cc:308-312(contextCreated lambda)src/inspector/v8-runtime-agent-impl.cc:1187-1207(reportExecutionContextCreated)src/inspector/inspected-context.cc:128-134(setReported)
Attacker model
web-content. Reachable from:
- Any user-attached DevTools session sending
Runtime.addBinding+Runtime.evaluate. - Any Chrome extension with the
debuggerpermission viachrome.debugger.attach()+Runtime.addBinding({name:"x"})+Runtime.evaluate().
No pre-existing memory primitive is assumed.
Fix-sibling
Commit 5a7de4a07b0128358a40117a51c5bfacf7f76c99 ("Fix Use-After-Free in Runtime.addBinding()") added an internal re-validation inside addBinding after global->Set(), but did NOT protect the immediate-next call site reportExecutionContextCreated inside the contextCreated lambda. This is the classic fix-sibling pattern: the leaf function is patched but the caller scope still ferries the dangling pointer.
Root cause
v8-inspector-impl.cc:308-312:
forEachSession(info.contextGroupId,
[&context](V8InspectorSessionImpl* s) {
s->runtimeAgent()->addBindings(context);
s->runtimeAgent()->reportExecutionContextCreated(context);
});
The lambda captures raw InspectedContext* context and uses it twice:
addBindings(ctx)ultimately callsaddBinding(ctx, name)which performsglobal->Set(localContext, v8Name, fn)at line 996. This is JS-reentrant: a setter installed onObject.prototype[name]fires here.reportExecutionContextCreated(ctx)immediately after.
Inside the Set() trap, attacker JS calls inspector.fireContextDestroyed() (mimics the production frame-detach path). This drives:
V8Inspector::contextDestroyed
-> V8InspectorImpl::contextCollected
-> discardInspectedContext
which erases the only shared_ptr<InspectedContext> from m_contexts. The local shared_ptr in contextCollected goes out of scope at function exit; ~InspectedContext runs inline, freeing the 232-byte slot via operator delete (libc malloc allocator — this is OUTSIDE the V8 sandbox cage).
Control returns to addBindings. The 5a7de4a07b0 inner-fix check at line 1001 returns early. addBindings's loop exits cleanly. Then the OUTER LAMBDA continues to reportExecutionContextCreated(freed_ctx) — UAF.
Impact
The attached PoCs achieve the following:
-
ASan-confirmed
heap-use-after-freeread on the freedInspectedContext(seepoc-asan.log). -
Under
--sandbox-testing, the V8 sandbox crash filter reports## V8 sandbox violation detected!classified as WRITE access (no "read access" caveat). This empirically demonstrates an Arbitrary Address Write (AAW) primitive: attacker-controlled bytes sprayed into the freed slot dictate the target address of a WRITE instruction executed at a canonical address outside the V8 sandbox cage. Seepoc-sandbox-violation.log.
Evidence
Two attached PoCs:
(1) poc-asan.js + poc-asan.log — reproduces the UAF under AddressSanitizer.
Signature: heap-use-after-free READ of size 8 at +144 bytes of freed InspectedContext inside libc++ __hash_table, called from InspectedContext::setReported reached via V8RuntimeAgentImpl::reportExecutionContextCreated at v8-runtime-agent-impl.cc:1190. The free site is V8InspectorImpl::contextCollected; the allocation site is V8InspectorImpl::contextCreated at v8-inspector-impl.cc:288.
(2) poc-sandbox-violation.js + poc-sandbox-violation.log — demonstrates the AAW primitive under --sandbox-testing.
Output: ## V8 sandbox violation detected! with NO "read access" caveat. The absence of that caveat (added at src/sandbox/testing.cc:1209-1213 only for read access) confirms WRITE access classification via the SIGSEGV error code's kWriteAccessBit (testing.cc:898-907 GetAccessType).
ASLR / production notes
The sandbox-violation PoC uses setarch -R to fix the target address at a known mapped read-only location so the WRITE classification is deterministically observable. The AAW primitive itself (attacker-controlled write target via heap spray) is independent of ASLR; production attacks would defeat ASLR through standard exploitation techniques.
Summary
Use-After-Free in V8 Inspector InspectedContext yields Arbitrary Write Outside V8 Sandbox Cage
Custom Questions
Type of crash:
tab
Reporter credit:
ywatanabee
Additional Data
Category: Security
Chrome Channel: Not sure
Regression: N/A \
Context
V8 is the JavaScript engine used by Chrome, and its Inspector component is what backs the DevTools protocol: the Runtime domain, execution context tracking, and bindings that let a debugger or extension inject functions into page JavaScript. The InspectedContext object is the inspector's bookkeeping record for a single JavaScript execution context. It is allocated on the libc C++ heap, which is outside the V8 sandbox cage.
This report describes a use-after-free on that object. The freed InspectedContext is dereferenced inside the contextCreated lambda's call to reportExecutionContextCreated, and the reporter shows that successful exploitation yields an arbitrary address write primitive outside the V8 sandbox cage.
Setup
The reporter used V8 source 15.0.0 (Chromium-tracked), tested at commit 6ac60d22f45 (HEAD as of 2026-05-30), on Linux x86_64.
Two builds are required.
Build A (ASan + sandbox + memory-corruption-api): out_asan/inspector-test, with this args.gn:
is_debug = false
dcheck_always_on = true
v8_enable_sandbox = true
v8_enable_memory_corruption_api = true
v8_enable_test_features = true
v8_enable_verify_heap = true
is_asan = true
target_cpu = "x64"
Build B (Non-ASan, sandbox + memory-corruption-api): out_sandbox/inspector-test, using the same args.gn but with is_asan = false.
Build commands:
gn gen out_asan
gn gen out_sandbox
autoninja -C out_asan inspector-test
autoninja -C out_sandbox inspector-test
Two proof-of-concept scripts are attached: poc-asan.js (ASan UAF reproduction) and poc-sandbox-violation.js (sandbox bypass with WRITE classification).
Finding it
The starting point is a fix-sibling pattern. Commit [redacted] ("Fix Use-After-Free in Runtime.addBinding()") added an internal re-validation inside addBinding after global->Set(), but did not protect the immediate-next call site, reportExecutionContextCreated, inside the contextCreated lambda. The leaf function was patched while the caller scope still ferries the dangling pointer.
The affected code is:
src/inspector/v8-inspector-impl.cc:308-312(contextCreated lambda)src/inspector/v8-runtime-agent-impl.cc:1187-1207(reportExecutionContextCreated)src/inspector/inspected-context.cc:128-134(setReported)
The attacker model is web-content. The path is reachable from any user-attached DevTools session sending Runtime.addBinding plus Runtime.evaluate, or from any Chrome extension with the debugger permission via chrome.debugger.attach() plus Runtime.addBinding({name:"x"}) plus Runtime.evaluate(). No pre-existing memory primitive is assumed.
Exploitation
Step 1: ASan UAF reproduction
Run from the V8 source root:
ASAN_OPTIONS='abort_on_error=0:halt_on_error=1:detect_leaks=0' \
./out_asan/inspector-test \
test/inspector/protocol-test.js \
poc-asan.js
The expected stderr, in its key sections:
==XXXXX==ERROR: AddressSanitizer: heap-use-after-free
on address 0xXXXX...
READ of size 8 at 0xXXXX thread T7 (Task Runner)
#0 in std::__Cr::__hash_table<int, ...>::__emplace_unique<...>
lambda at __hash_table:531:67
#1 in v8_inspector::InspectedContext::setReported
try_key_extraction.h:44:10
#2 in v8_inspector::V8RuntimeAgentImpl::reportExecutionContextCreated
src/inspector/v8-runtime-agent-impl.cc:1190:12
#3 in v8_inspector::V8InspectorImpl::forEachSession
#4 in v8_inspector::V8InspectorImpl::contextCreated
src/inspector/v8-inspector-impl.cc:308:3
...
0xXXXX is located 144 bytes inside of 232-byte region [0xXXXX, 0xXXXX)
freed by thread T7:
#0 operator delete(void*, unsigned long)
#1 V8InspectorImpl::contextCollected
...
previously allocated by thread T7:
#0 operator new(unsigned long)
#1 V8InspectorImpl::contextCreated
src/inspector/v8-inspector-impl.cc:288
...
ASan reports heap-use-after-free on a 232-byte region. The freed object is the InspectedContext allocated at v8-inspector-impl.cc:288; the read is at offset +144, reached from setReported through reportExecutionContextCreated.
Step 2: WRITE-classification sandbox violation
UBSAN_OPTIONS='print_stacktrace=0:halt_on_error=0:abort_on_error=0:handle_segv=0:handle_sigbus=0:handle_sigill=0' \
setarch -R \
./out_sandbox/inspector-test \
--sandbox-testing \
test/inspector/protocol-test.js \
poc-sandbox-violation.js
Flag notes from the report:
setarch -Rdisables ASLR so the target binary loads at the fixed PIE base0x555555554000+. A small r--p mapping at file offset0x07f03000(memory0x55555d45a000-0x55555d45b000) whose first 16 bytes are zero is used as the WRITE target.--sandbox-testingenables the V8 sandbox crash filter (src/sandbox/testing.cc).UBSAN_OPTIONS handle_segv=0prevents UBSan's signal handler from preempting the sandbox crash filter, so the filter can classify the access type.
Expected stderr:
Sandbox testing mode is enabled. Only sandbox violations will be
reported, all other crashes will be ignored.
Sandbox bounds: [0xXXXXXXXXXXXX, 0xXXXXXXXXXXXX)
...
## V8 sandbox violation detected!
(Process exits with signal 11 / SIGSEGV)
The crash filter prints ## V8 sandbox violation detected! with no "read access" caveat following it. Per src/sandbox/testing.cc:1209-1213, that caveat is added only for read access; its absence confirms WRITE access classification via the SIGSEGV error code's kWriteAccessBit, checked at testing.cc:898-907 GetAccessType. This satisfies the requirement in docs/security/triaging.md: "A successful bypass must show write access outside of the sandbox."
Step 3: Determinism check
for i in 1 2 3 4 5; do
echo "--- Attempt $i ---"
UBSAN_OPTIONS='print_stacktrace=0:halt_on_error=0:abort_on_error=0:handle_segv=0:handle_sigbus=0:handle_sigill=0' \
timeout 15 setarch -R \
./out_sandbox/inspector-test --sandbox-testing \
test/inspector/protocol-test.js \
poc-sandbox-violation.js 2>&1 \
| grep -A2 "V8 sandbox" | head -5
done
This repeats the sandbox run five times, filtering the output for the violation banner.
Root cause
The contextCreated lambda at v8-inspector-impl.cc:308-312:
forEachSession(info.contextGroupId,
[&context](V8InspectorSessionImpl* s) {
s->runtimeAgent()->addBindings(context);
s->runtimeAgent()->reportExecutionContextCreated(context);
});
The lambda captures a raw InspectedContext* context and uses it twice:
addBindings(ctx)ultimately callsaddBinding(ctx, name), which performsglobal->Set(localContext, v8Name, fn)at line 996. This is JS-reentrant: a setter installed onObject.prototype[name]fires here.reportExecutionContextCreated(ctx)runs immediately after.
Inside the Set() trap, attacker JavaScript calls inspector.fireContextDestroyed(), mimicking the production frame-detach path. This drives:
V8Inspector::contextDestroyed
-> V8InspectorImpl::contextCollected
-> discardInspectedContext
which erases the only shared_ptr<InspectedContext> from m_contexts. The local shared_ptr in contextCollected goes out of scope at function exit; ~InspectedContext runs inline, freeing the 232-byte slot via operator delete (libc malloc allocator, outside the V8 sandbox cage).
Control returns to addBindings. The inner-fix check from 5a7de4a07b0 at line 1001 returns early, and addBindings's loop exits cleanly. Then the outer lambda continues to reportExecutionContextCreated(freed_ctx), which is the use-after-free.
Impact
The attached PoCs achieve the following.
- An ASan-confirmed
heap-use-after-freeread on the freedInspectedContext(seepoc-asan.log). - Under
--sandbox-testing, the V8 sandbox crash filter reports## V8 sandbox violation detected!classified as WRITE access (no "read access" caveat). This empirically demonstrates an arbitrary address write primitive: attacker-controlled bytes sprayed into the freed slot dictate the target address of a WRITE instruction executed at a canonical address outside the V8 sandbox cage (seepoc-sandbox-violation.log).
The evidence is summarised as follows.
(1) poc-asan.js + poc-asan.log reproduces the UAF under AddressSanitizer. Signature: heap-use-after-free READ of size 8 at +144 bytes of freed InspectedContext inside libc++ __hash_table, called from InspectedContext::setReported reached via V8RuntimeAgentImpl::reportExecutionContextCreated at v8-runtime-agent-impl.cc:1190. The free site is V8InspectorImpl::contextCollected; the allocation site is V8InspectorImpl::contextCreated at v8-inspector-impl.cc:288.
(2) poc-sandbox-violation.js + poc-sandbox-violation.log demonstrates the arbitrary write primitive under --sandbox-testing. Output: ## V8 sandbox violation detected! with no "read access" caveat. The absence of that caveat (added at src/sandbox/testing.cc:1209-1213 only for read access) confirms WRITE access classification via the SIGSEGV error code's kWriteAccessBit (testing.cc:898-907 GetAccessType).
On ASLR: the sandbox-violation PoC uses setarch -R to fix the target address at a known mapped read-only location so the WRITE classification is deterministically observable. The arbitrary write primitive itself (attacker-controlled write target via heap spray) is independent of ASLR; production attacks would defeat ASLR through standard exploitation techniques.
Fix
The report does not describe a fix. It identifies the gap left by commit [redacted] ("Fix Use-After-Free in Runtime.addBinding()"): that commit added an internal re-validation inside addBinding after global->Set(), but did not protect the immediate-next call site reportExecutionContextCreated inside the contextCreated lambda.
Variants to test
- Look for other call sites that hold a raw
InspectedContext*across a JS-reentrant call such asglobal->Set(). A positive result is an ASanheap-use-after-freewhose free site isV8InspectorImpl::contextCollectedand whose allocation site isV8InspectorImpl::contextCreated. - Audit other leaf functions patched for a UAF and check whether their callers still use the same pointer afterwards, the fix-sibling pattern seen here. A positive result is a crash that survives the leaf-level re-validation.
- Exercise
inspector.fireContextDestroyed()from inside property setters installed onObject.prototypeduring binding installation. A positive result is a freedInspectedContextbeing dereferenced after the setter returns. - Run the sandbox PoC under
--sandbox-testingwithsetarch -Rand check for## V8 sandbox violation detected!without the "read access" caveat, which indicates a write outside the cage. - Repeat the sandbox run several times as in the determinism loop. A positive result is the same WRITE classification on each attempt.
What happened, in plain words
Chrome runs web pages with a program called V8, which is the part that understands and executes JavaScript (the language most websites use to make pages interactive). V8 has a helper component called the Inspector. The Inspector is what lets Chrome's built-in developer tools, and browser extensions that ask for debugging powers, look inside a running page: pause it, run small snippets of code in it, and add little helper functions to it.
To keep track of each separate JavaScript environment on a page, the Inspector keeps a small record for each one. That record is an object called InspectedContext. Think of it as a paper file card in a filing cabinet: one card per environment, holding notes the Inspector needs.
This report is about a bug where that file card gets thrown in the bin, and then a piece of code that still holds a pointer to the card reads from it anyway. In security terms that is called a use-after-free: using something after it has been freed. The reporter shows that this mistake can be turned into something serious: the ability to make the program write data to an address of the attacker's choosing, even outside the protective boundary V8 puts around itself (the V8 sandbox).
Background: the pieces involved
Before the steps, a few words that come up constantly.
- V8: the JavaScript engine inside Chrome. An engine is the program that reads code and actually runs it.
- Inspector: the part of V8 that speaks the DevTools protocol. A protocol here just means an agreed set of messages two programs exchange. The Inspector's messages are grouped into named areas called domains; the one in this report is the
Runtimedomain, which deals with running JavaScript. - Execution context: one separate JavaScript world. A page can have several (for example, a page and an embedded frame from another site each get their own). The Inspector keeps one
InspectedContextrecord per execution context. - Binding: a function the debugger or an extension injects into the page's JavaScript so the page can call back out to the debugger.
Runtime.addBindingis the protocol command that installs one. - Heap: the area of memory a program uses for objects it creates while running. When an object is no longer needed, the program frees that memory so it can be reused. A use-after-free happens when code keeps using the memory after it has been freed.
- Sandbox: a protective boundary. V8 keeps its own objects inside a reserved region of memory (the "cage") and checks that code cannot reach outside it. The
InspectedContextrecord, however, lives on the ordinary C++ heap, which is outside that cage. That detail matters later. - ASan (AddressSanitizer): a debugging tool built into a special test build of a program. It watches memory and shouts loudly when code reads or writes memory that has been freed. It is like a smoke alarm for memory mistakes.
- ASLR (Address Space Layout Randomisation): an operating-system feature that shuffles where things sit in memory each time a program starts, so an attacker cannot rely on a fixed address.
setarch -Ris a command that turns this shuffling off for one run, which makes tests repeatable. - SIGSEGV: the signal (a low-level notification from the operating system) a program receives when it touches memory it is not allowed to touch. It usually means the program is about to crash.
Setting up the test builds
The reporter worked with V8 source version 15.0.0 (the version Chrome tracks), at a specific saved snapshot of the code called a commit, 6ac60d22f45 (the newest code as of 2026-05-30), on Linux on a 64-bit x86 processor (written x86_64).
Two separate builds of the test program are needed, because each one is good at showing a different thing.
Build A is the smoke-alarm build: it includes ASan, the sandbox, and the memory-corruption test API (a set of testing hooks that let a test deliberately poke at memory). Its output lives in out_asan/inspector-test. Its settings file, args.gn, is:
is_debug = false
dcheck_always_on = true
v8_enable_sandbox = true
v8_enable_memory_corruption_api = true
v8_enable_test_features = true
v8_enable_verify_heap = true
is_asan = true
target_cpu = "x64"
Line by line:
is_debug = false: build an optimised (release-style) program rather than a slow debug one.dcheck_always_on = true: keep V8's internal consistency checks switched on even in this optimised build, so mistakes are caught early.v8_enable_sandbox = true: turn on the V8 sandbox boundary.v8_enable_memory_corruption_api = true: include the testing hooks that let a test simulate memory corruption.v8_enable_test_features = true: include features that exist only for testing.v8_enable_verify_heap = true: have V8 check its own heap for damage.is_asan = true: include AddressSanitizer, the memory smoke alarm.target_cpu = "x64": build for 64-bit x86.
Build B is the same but without the smoke alarm: it is the non-ASan build, with the sandbox and the memory-corruption API still on, in out_sandbox/inspector-test. It uses the same args.gn with is_asan = false.
The commands that produce both builds are:
gn gen out_asan
gn gen out_sandbox
autoninja -C out_asan inspector-test
autoninja -C out_sandbox inspector-test
Line by line:
gn gen out_asan:gnis the tool that reads the settings and generates the build files for the first build directory.gn gen out_sandbox: the same for the second build directory.autoninja -C out_asan inspector-test:autoninjais the tool that actually compiles the code;-C out_asansays "work in this directory", andinspector-testis the test program being built.autoninja -C out_sandbox inspector-test: the same for the second build.
Two proof-of-concept scripts are attached to the report: poc-asan.js (a small JavaScript file that triggers the use-after-free so ASan can catch it) and poc-sandbox-violation.js (a script that shows the sandbox being crossed with a write). A proof of concept is a minimal demonstration that a bug is real.
Finding it: the fix that missed a spot
The reporter did not stumble on this by accident. They started from a previous fix. Commit [redacted], titled "Fix Use-After-Free in Runtime.addBinding()", had already patched a use-after-free in the addBinding function. That patch added an internal re-check inside addBinding after a particular call, global->Set(), but it did not protect the very next thing that runs: the call to reportExecutionContextCreated inside a piece of code called the contextCreated lambda.
A lambda is a small unnamed function written inline inside another function. Here the outer function walks through all debugging sessions and, for each one, runs a little block of code. The previous fix patched the inner function (the "leaf") but left the surrounding code still carrying a pointer to an object that may already have been freed. Security researchers call this the fix-sibling pattern: you fix one sibling and forget the one standing next to it.
The affected code is listed as:
src/inspector/v8-inspector-impl.cc:308-312(thecontextCreatedlambda)src/inspector/v8-runtime-agent-impl.cc:1187-1207(reportExecutionContextCreated)src/inspector/inspected-context.cc:128-134(setReported)
These are file names with line numbers: src/inspector/v8-inspector-impl.cc is a source file, and 308-312 means lines 308 to 312 in it.
The attacker model is web-content: the assumption is that the attacker is ordinary web content, meaning a web page. The path is reachable in two ways:
- Any DevTools session a user attaches, sending
Runtime.addBindingandRuntime.evaluate(the command that runs a snippet of JavaScript in the page). - Any Chrome extension that holds the
debuggerpermission, usingchrome.debugger.attach()to attach to a tab, thenRuntime.addBinding({name:"x"})to install a binding calledx, thenRuntime.evaluate()to run code.
No pre-existing memory primitive is assumed. A memory primitive is a small, reliable ability to do something with memory (like read or write at a chosen address) that an attacker builds up step by step; here the reporter assumes the attacker starts with none.
Exploitation
Step 1: catching the use-after-free with ASan
The first run uses the smoke-alarm build. It is launched from the root of the V8 source tree:
ASAN_OPTIONS='abort_on_error=0:halt_on_error=1:detect_leaks=0' \
./out_asan/inspector-test \
test/inspector/protocol-test.js \
poc-asan.js
Line by line:
ASAN_OPTIONS='...': settings passed to AddressSanitizer for this run.abort_on_error=0means do not abort the whole process on the first error;halt_on_error=1means stop at the first error;detect_leaks=0means do not also report memory leaks (memory that was never freed), so the output stays focused../out_asan/inspector-test: run the test program built in the first build directory.test/inspector/protocol-test.js: a test harness script that sets up the Inspector test environment.poc-asan.js: the proof-of-concept script that triggers the bug.
The expected error output, in its key sections, is:
==XXXXX==ERROR: AddressSanitizer: heap-use-after-free
on address 0xXXXX...
READ of size 8 at 0xXXXX thread T7 (Task Runner)
#0 in std::__Cr::__hash_table<int, ...>::__emplace_unique<...>
lambda at __hash_table:531:67
#1 in v8_inspector::InspectedContext::setReported
try_key_extraction.h:44:10
#2 in v8_inspector::V8RuntimeAgentImpl::reportExecutionContextCreated
src/inspector/v8-runtime-agent-impl.cc:1190:12
#3 in v8_inspector::V8InspectorImpl::forEachSession
#4 in v8_inspector::V8InspectorImpl::contextCreated
src/inspector/v8-inspector-impl.cc:308:3
...
0xXXXX is located 144 bytes inside of 232-byte region [0xXXXX, 0xXXXX)
freed by thread T7:
#0 operator delete(void*, unsigned long)
#1 V8InspectorImpl::contextCollected
...
previously allocated by thread T7:
#0 operator new(unsigned long)
#1 V8InspectorImpl::contextCreated
src/inspector/v8-inspector-impl.cc:288
...
Line by line:
==XXXXX==ERROR: AddressSanitizer: heap-use-after-free: the smoke alarm has gone off. TheXXXXXis a placeholder for a process number.on address 0xXXXX...: the memory address where the problem happened. The0xprefix means the number is written in hexadecimal (base 16), the usual way addresses are shown.READ of size 8 at 0xXXXX thread T7 (Task Runner): the program tried to read 8 bytes (a typical pointer size on a 64-bit machine) at that address, on a background thread namedT7(the task runner).- The
#0to#4lines are a stack trace: the chain of function calls that led to the problem, most recent first.#0is the innermost function,#4the outermost shown.#0is inside a C++ standard library hash table (__hash_table), a data structure that stores items by key.#1isInspectedContext::setReported, a method on theInspectedContextrecord.#2isV8RuntimeAgentImpl::reportExecutionContextCreatedat line 1190 ofv8-runtime-agent-impl.cc.#3isV8InspectorImpl::forEachSession, the loop over debugging sessions.#4isV8InspectorImpl::contextCreatedat line 308 ofv8-inspector-impl.cc, the lambda from the report.
0xXXXX is located 144 bytes inside of 232-byte region: the address being read is 144 bytes into a block of memory that is 232 bytes long. That block is theInspectedContextrecord.freed by thread T7:starts the story of how that memory was released:operator deleteis the C++ function that frees memory, and it was called fromV8InspectorImpl::contextCollected.previously allocated by thread T7:starts the story of how it was created:operator newallocates memory, and it was called fromV8InspectorImpl::contextCreatedat line 288 ofv8-inspector-impl.cc.
So ASan confirms a heap-use-after-free on a 232-byte region. The freed object is the InspectedContext allocated at v8-inspector-impl.cc:288; the read is at offset +144, reached from setReported through reportExecutionContextCreated. In plain words: the record was created, later freed, and then read from anyway.
Step 2: showing a write outside the sandbox
The second run uses the non-ASan build and the sandbox testing mode:
UBSAN_OPTIONS='print_stacktrace=0:halt_on_error=0:abort_on_error=0:handle_segv=0:handle_sigbus=0:handle_sigill=0' \
setarch -R \
./out_sandbox/inspector-test \
--sandbox-testing \
test/inspector/protocol-test.js \
poc-sandbox-violation.js
Line by line:
UBSAN_OPTIONS='...': settings for UBSan (UndefinedBehaviorSanitizer), another checking tool.print_stacktrace=0means do not print a stack trace;halt_on_error=0andabort_on_error=0mean do not stop or abort on its findings;handle_segv=0,handle_sigbus=0,handle_sigill=0mean do not let UBSan's own signal handlers take over when the program crashes. That last part matters: we want the sandbox's own crash filter to see the crash first.setarch -R: run the next program with ASLR turned off, so memory addresses are the same on every run../out_sandbox/inspector-test: the second build of the test program.--sandbox-testing: a flag that switches on the V8 sandbox crash filter, the code insrc/sandbox/testing.ccthat inspects crashes and decides whether they crossed the sandbox boundary.test/inspector/protocol-test.js: the same test harness as before.poc-sandbox-violation.js: the proof-of-concept that tries to write outside the sandbox.
The report gives three notes on these flags:
setarch -Rdisables ASLR so the target binary loads at the fixed PIE base0x555555554000+. PIE (position-independent executable) is a program that can be loaded at different addresses; with ASLR off it lands at a predictable base. A small read-only mapping (r--p, meaning readable but not writable) at file offset0x07f03000, occupying memory0x55555d45a000-0x55555d45b000, whose first 16 bytes are zero, is used as the WRITE target. In other words, the test picks a known, harmless spot in memory and tries to write there, so the result is repeatable.--sandbox-testingenables the V8 sandbox crash filter (src/sandbox/testing.cc).UBSAN_OPTIONS handle_segv=0prevents UBSan's signal handler from preempting the sandbox crash filter, so the filter can classify the access type. Classify here means deciding whether the crash was a read or a write.
The expected error output is:
Sandbox testing mode is enabled. Only sandbox violations will be
reported, all other crashes will be ignored.
Sandbox bounds: [0xXXXXXXXXXXXX, 0xXXXXXXXXXXXX)
...
## V8 sandbox violation detected!
(Process exits with signal 11 / SIGSEGV)
Line by line:
Sandbox testing mode is enabled...: the filter announces it is active and will only report crashes that cross the sandbox boundary; other crashes are ignored.Sandbox bounds: [0xXXXXXXXXXXXX, 0xXXXXXXXXXXXX): the start and end addresses of the sandbox region. The square bracket means the start is included and the round bracket means the end is not.## V8 sandbox violation detected!: the filter's verdict: a crash happened outside the sandbox.(Process exits with signal 11 / SIGSEGV): the program died from signal 11, which is SIGSEGV, the "bad memory access" signal.
The important detail is that the banner appears with no "read access" caveat after it. Per src/sandbox/testing.cc:1209-1213, that caveat is added only for read access. Its absence confirms the access was classified as a WRITE, using the SIGSEGV error code's kWriteAccessBit (a single bit in the error code that says "this was a write"), checked at testing.cc:898-907 in a function called GetAccessType. This satisfies the requirement in docs/security/triaging.md: "A successful bypass must show write access outside of the sandbox." In plain words: the test did not just crash; it crashed while trying to write outside the protective boundary, which is exactly what a real attacker would want to do.
Step 3: checking it happens every time
The reporter repeats the sandbox run five times:
for i in 1 2 3 4 5; do
echo "--- Attempt $i ---"
UBSAN_OPTIONS='print_stacktrace=0:halt_on_error=0:abort_on_error=0:handle_segv=0:handle_sigbus=0:handle_sigill=0' \
timeout 15 setarch -R \
./out_sandbox/inspector-test --sandbox-testing \
test/inspector/protocol-test.js \
poc-sandbox-violation.js 2>&1 \
| grep -A2 "V8 sandbox" | head -5
done
Line by line:
for i in 1 2 3 4 5; do ... done: a shell loop that runs the body five times, withicounting from 1 to 5.echo "--- Attempt $i ---": prints a separator with the attempt number, so the output is easy to read.UBSAN_OPTIONS='...': the same UBSan settings as before, so the sandbox filter still gets first look at any crash.timeout 15: kills the command if it has not finished within 15 seconds, so a hang does not stall the loop.setarch -R: ASLR off again, for the same repeatable addresses../out_sandbox/inspector-test --sandbox-testing: the second build in sandbox testing mode.test/inspector/protocol-test.jsandpoc-sandbox-violation.js: the harness and the proof of concept.2>&1: sends the error output (file descriptor 2) to the same place as normal output (file descriptor 1), so both are captured together.| grep -A2 "V8 sandbox":grepsearches text for a pattern;-A2means also show the two lines after each match. Here it looks for the sandbox banner.| head -5:head -5keeps only the first five lines, so the output stays short.
The loop repeats the sandbox run five times, filtering the output for the violation banner.
Root cause
The heart of the bug is this lambda at v8-inspector-impl.cc:308-312:
forEachSession(info.contextGroupId,
[&context](V8InspectorSessionImpl* s) {
s->runtimeAgent()->addBindings(context);
s->runtimeAgent()->reportExecutionContextCreated(context);
});
Line by line:
forEachSession(info.contextGroupId, ...): for every debugging session attached to this execution context group, run the following block. A session is one attached debugger or extension connection.[&context](V8InspectorSessionImpl* s) {: the start of the lambda.[&context]means the lambda capturescontextby reference, so it holds a pointer to theInspectedContextrecord rather than a copy.sis the current session.s->runtimeAgent()->addBindings(context);: install the bindings for this session, passing the context record.s->runtimeAgent()->reportExecutionContextCreated(context);: tell the session that the execution context was created, again passing the same context record.});: close the lambda and the call.
The lambda captures a raw InspectedContext* context (a raw pointer is just a memory address, with no automatic safety net) and uses it twice:
addBindings(ctx)ultimately callsaddBinding(ctx, name), which performsglobal->Set(localContext, v8Name, fn)at line 996. This is JS-reentrant: while the engine is busy setting a property, JavaScript code can run again in the middle of it. Specifically, a setter installed onObject.prototype[name]fires here. A setter is a function that runs automatically when a property is assigned;Object.prototypeis the shared base object that every JavaScript object inherits from, so a setter placed there can catch assignments on many objects.reportExecutionContextCreated(ctx)runs immediately after.
Inside the Set() trap, attacker JavaScript calls inspector.fireContextDestroyed(), mimicking the production frame-detach path (what happens when a frame is removed from the page). This drives:
V8Inspector::contextDestroyed
-> V8InspectorImpl::contextCollected
-> discardInspectedContext
Line by line:
V8Inspector::contextDestroyed: the entry point, called when a context is being destroyed.-> V8InspectorImpl::contextCollected: the next function in the chain, which handles the collected context.-> discardInspectedContext: the function that actually discards the record.
This chain erases the only shared_ptr<InspectedContext> from m_contexts. A shared pointer (shared_ptr) is a smart pointer that keeps a count of how many owners an object has and frees it automatically when the last owner lets go. m_contexts is the map that holds all the records. The local shared_ptr in contextCollected goes out of scope at function exit; ~InspectedContext (the destructor, the function that runs when an object is destroyed) runs inline, freeing the 232-byte slot via operator delete (the libc malloc allocator, outside the V8 sandbox cage).
Control then returns to addBindings. The inner-fix check from 5a7de4a07b0 at line 1001 returns early, and addBindings's loop exits cleanly. Then the outer lambda continues to reportExecutionContextCreated(freed_ctx), which is the use-after-free: the record has been freed, but the lambda still holds its address and uses it.
A simple comparison: you write a note on a card, hand the card to a colleague, the colleague shreds the card, and then you read from the card anyway. The shredding is the free; the reading is the use-after-free.
Impact
The two proof-of-concept scripts achieve the following.
- An ASan-confirmed
heap-use-after-freeread on the freedInspectedContext(seepoc-asan.log). - Under
--sandbox-testing, the V8 sandbox crash filter reports## V8 sandbox violation detected!classified as WRITE access (no "read access" caveat). This empirically demonstrates an arbitrary address write primitive: attacker-controlled bytes sprayed into the freed slot dictate the target address of a WRITE instruction executed at a canonical address outside the V8 sandbox cage (seepoc-sandbox-violation.log).
An arbitrary address write (often shortened to AAW) means the attacker can make the program write data to a memory address of their choosing. A heap spray is a technique where the attacker fills freed memory with chosen bytes so that whatever reuses that memory contains their data. A canonical address is an address in the form the processor expects on x86_64; addresses outside that form are invalid.
The evidence is summarised as follows.
(1) poc-asan.js + poc-asan.log reproduces the use-after-free under AddressSanitizer. The signature is heap-use-after-free READ of size 8 at +144 bytes of freed InspectedContext inside libc++ __hash_table, called from InspectedContext::setReported reached via V8RuntimeAgentImpl::reportExecutionContextCreated at v8-runtime-agent-impl.cc:1190. The free site is V8InspectorImpl::contextCollected; the allocation site is V8InspectorImpl::contextCreated at v8-inspector-impl.cc:288. In plain words: the log shows where the memory was created, where it was freed, and where it was wrongly read.
(2) poc-sandbox-violation.js + poc-sandbox-violation.log demonstrates the arbitrary write primitive under --sandbox-testing. The output is ## V8 sandbox violation detected! with no "read access" caveat. The absence of that caveat (added at src/sandbox/testing.cc:1209-1213 only for read access) confirms WRITE access classification via the SIGSEGV error code's kWriteAccessBit (testing.cc:898-907 GetAccessType).
On ASLR: the sandbox-violation proof of concept uses setarch -R to fix the target address at a known mapped read-only location so the WRITE classification is deterministically observable. The arbitrary write primitive itself (attacker-controlled write target via heap spray) is independent of ASLR; production attacks would defeat ASLR through standard exploitation techniques. In plain words: the test turns off address shuffling only so the result is easy to see; a real attacker would find another way around the shuffling.
Fix
The report does not describe a fix. It identifies the gap left by commit [redacted] ("Fix Use-After-Free in Runtime.addBinding()"): that commit added an internal re-validation inside addBinding after global->Set(), but did not protect the immediate-next call site reportExecutionContextCreated inside the contextCreated lambda. In plain words: after the risky step where JavaScript can run in the middle of things, the code should check that the record still exists (or fetch it again) before using it.
Variants to test
These are follow-up ideas for finding similar bugs elsewhere.
- Look for other call sites that hold a raw
InspectedContext*across a JS-reentrant call such asglobal->Set(). A positive result is an ASanheap-use-after-freewhose free site isV8InspectorImpl::contextCollectedand whose allocation site isV8InspectorImpl::contextCreated. - Audit other leaf functions patched for a use-after-free and check whether their callers still use the same pointer afterwards, the fix-sibling pattern seen here. A positive result is a crash that survives the leaf-level re-validation.
- Exercise
inspector.fireContextDestroyed()from inside property setters installed onObject.prototypeduring binding installation. A positive result is a freedInspectedContextbeing dereferenced after the setter returns. - Run the sandbox proof of concept under
--sandbox-testingwithsetarch -Rand check for## V8 sandbox violation detected!without the "read access" caveat, which indicates a write outside the cage. - Repeat the sandbox run several times as in the determinism loop. A positive result is the same WRITE classification on each attempt.
Glossary
- AddressSanitizer (ASan): a checking tool built into a special test build that reports when a program reads or writes memory it has already freed.
- Arbitrary address write (AAW): the ability to make a program write data to a memory address of the attacker's choosing.
- ASLR (Address Space Layout Randomisation): an operating-system feature that shuffles where things sit in memory each run, to make attacks harder.
- Binding: a function the debugger or an extension injects into page JavaScript so the page can call back out.
- Build: a compiled copy of a program produced from source code.
- Canonical address: a memory address in the form the processor expects on x86_64; other forms are invalid.
- Commit: a saved snapshot of a code repository at a point in time.
- CVE: a public catalogue number for a security flaw.
- Debugger permission: a permission an extension can request that lets it attach to and inspect tabs.
- DevTools protocol: the agreed set of messages Chrome's developer tools use to inspect and control a page.
- Domain: a named group of related protocol messages, such as
Runtime. - Execution context: one separate JavaScript world on a page, for example a page and an embedded frame.
- Fix-sibling pattern: fixing one function for a bug while forgetting the neighbouring function that has the same problem.
- Heap spray: filling freed memory with chosen bytes so that whatever reuses it contains the attacker's data.
- Hexadecimal: base-16 number notation, written with a
0xprefix, commonly used for memory addresses. - InspectedContext: the Inspector's record for one JavaScript execution context.
- JavaScript: the programming language most websites use to make pages interactive.
- JS-reentrant: a call during which JavaScript code can run again in the middle of the operation.
- Lambda: a small unnamed function written inline inside another function.
- Memory primitive: a small, reliable ability to do something with memory, such as read or write at a chosen address.
- Operator delete / operator new: the C++ functions that free and allocate memory.
- PIE (position-independent executable): a program that can be loaded at different memory addresses.
- Proof of concept (PoC): a minimal demonstration that a bug is real.
- Protocol: an agreed set of messages two programs exchange.
- Raw pointer: a plain memory address with no automatic safety net.
- Sandbox: a protective boundary that keeps code from reaching outside a reserved region of memory.
- Session: one attached debugger or extension connection.
- Setter: a function that runs automatically when a JavaScript property is assigned.
- Shared pointer (
shared_ptr): a smart pointer that counts its owners and frees the object when the last owner lets go. - SIGSEGV: the signal a program receives when it touches memory it is not allowed to touch.
- Stack trace: the chain of function calls that led to a point in the program, most recent first.
- UBSan (UndefinedBehaviorSanitizer): a checking tool that reports undefined behaviour in a program.
- Use-after-free: using memory after it has been freed.
- V8: the JavaScript engine inside Chrome.
- V8 sandbox: V8's protective boundary around its own objects.
- Vulnerability Reward Program (VRP): a program that pays people who report security bugs responsibly.
- x86_64: the 64-bit version of the x86 processor family.