Exploitation Of CVE-2021-21220 – From Incorrect JIT Behavior To RCE
Published on zerodayinitiative.com
In the second blog in this series, we discussed how CVE-2021-21220 can be used to make the JIT generate code that produces an incorrect numeric result. We now need to explain how this can be leveraged to produce an effect that has a security impact, such as an out-of-bounds memory access.
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
This article follows the third and final post in a ZDI series on CVE-2021-21220, a Chrome bug used at Pwn2Own Vancouver 2021 by Bruno Keith (@bkth_) and Niklas Baumstark (@niklasb) of Dataflow Security (@dfsec_com). The researchers used it to exploit both Chrome and Edge (Chromium) and earned $100,000 at the event. The post, written by ZDI Vulnerability Researcher Hossein Lotfi and published on 16 December 2021, covers the exploitation technique used at the contest rather than the root cause, which was handled in Part Two of the series.
The target is V8, Chrome's JavaScript engine, and specifically its JIT compiler. The feature at the centre of the write-up is the optimiser's handling of numeric types and of built-in array methods. Normally, when a function is hot enough, V8 compiles an optimised version of it and replaces slow built-in calls such as Array.shift with inline assembly-level operations. The optimiser also reasons about the possible values of variables (its typer) and removes checks it believes are redundant. The bug lets the JIT produce an incorrect numeric result, and the exploitation work turns that wrong number into an out-of-bounds memory access and then into code execution.
Setup
The report does not describe a lab setup, browser versions, build flags or debugging tools. What it does state is the context of use: the exploit was demonstrated at Pwn2Own Vancouver 2021 against Chrome and Edge (Chromium), and the write-up reconstructs the technique from that contest. The only precondition it makes explicit is the one that matters technically: the attacker needs a JIT vulnerability that can make the engine compute a wrong numeric value, and then needs a way to turn that wrong value into a memory-safety side effect.
Finding it
The starting point is the observation from Part Two: CVE-2021-21220 can make the JIT generate code that produces an incorrect numeric result. On its own that is not a security bug. The question the post answers is how to convert a wrong number into something with impact, such as an out-of-bounds memory access.
The classic answer was array bounds check elimination. The post gives a simplified sample in which the length of an array arr is 4 and a function returns an element of it. V8 performs run-time bounds checking so that the final statement cannot access memory outside the array. During optimisation, V8 might remove that check if it concludes that typer_index is always zero, or more generally that typer_index * 10 is provably always inside the bounds of the array. This saves CPU cycles in the optimised function. If the JITted code then produces an erroneous numeric result, it may be possible to fool the engine into thinking typer_index must be zero while it is actually set to a different, erroneous value. The array access then triggers an out-of-bounds memory access.
That method was so successful that the V8 developers eventually removed array bounds check elimination. The post links to the V8 commit that did so, to an introduction to Turbofan for background on the technique, and to a second blog on circumventing Chrome's hardening of typer bugs. With that route closed, the contestants needed a new technique.
Exploitation
Step 1: Turn the wrong number into an out-of-bounds array
At Pwn2Own the researchers used a technique that produces out-of-bounds access through ArrayPrototypePop and ArrayPrototypeShift. Lotfi traced the method back to late 2020 by searching the Chromium bug tracker, and notes that it was mitigated a week after the competition by adding a new CheckBounds node.
The mechanism is as follows. When a function undergoing optimisation contains calls to Array.shift, execution flow eventually reaches JSCallReducer::ReduceArrayPrototypeShift in src/compiler/js-call-reducer.cc. Because a call to the built-in shift JavaScript method is relatively slow, the optimiser replaces the call with a series of operations that can be performed at the assembly level. Array.shift removes the first element from an array and returns that removed element. After removing it, the JIT-produced code computes the new array length by subtracting 1 from the original array length, and stores the result as the new length.
The exploit abuses the JIT vulnerability to fool the engine into thinking the array length is zero when it is not. The generated code then blindly subtracts one from zero. The integer underflow sets the array length to -1, and because array bounds checks are unsigned, a subsequent access can reach out of bounds. The post points to a Chromium bug entry for more detail on this underflow path.
The post notes that both techniques described so far, bounds check elimination and the shift underflow, have since been mitigated, but that new methods using JIT vulnerabilities to cause side effects and reach out-of-bounds access are still appearing.
Step 2: The standard V8 exploitation chain
Once an out-of-bounds read/write primitive exists, the post describes the well-known V8 exploitation steps:
- Trigger the vulnerability and the side effect to get a relative out-of-bounds memory access, used to corrupt the length of one or more arrays sitting next to the original array.
- Build
addrofandfakeobjprimitives.addrofleaks the address of an arbitrary JavaScript object.fakeobjdoes the reverse: it injects an arbitrary value into the engine that the engine will interpret as a pointer to a JavaScript object. - Use
fakeobjto forge a JavaScript array object whose data buffer field is an arbitrary attacker-specified address. The forged array can then read or write arbitrary memory addresses, unlike the relative out-of-bounds access of step 1, which only permits access at arbitrary offsets past the start of the original array. - Use
addrofto leak the address of awasmfunction. This is where the shellcode will be copied. Awasmfunction is a good choice because the memory it occupies is marked RWX (Read-Write-Execute). - Use
fakeobjto copy shellcode to the RWX page. To make copying easier, anArrayBufferwith an uncompressedbacking_storepointer is often used. This overwrites thewasmfunction instructions with the shellcode. - Execute the shellcode by calling the
wasmfunction.
Step 3: The actual Pwn2Own exploit
The post describes how this was done in practice and includes short code snippets for the helper functions, the trigger, the wasm setup and the crash handling. It says the exploit starts by defining helper functions to convert between floats and integers, then triggers the JIT vulnerability. After triggering it, the value of the bad variable is huge, so it is passed through a series of Math.max calls to bring it down to a smaller value (1). This confused value is then used to create an array, and a shift on that array produces an array of length -1. That array allows the exploit to access memory at arbitrary offsets past the end of the array.
Setting up the wasm RWX memory is the next step. The contents of the wasm function do not matter, because its instructions will be replaced with shellcode.
The exploit then allocates three arrays in a deliberate order:
- a
PACKED_DOUBLE_ELEMENTSarray (after_dbl); - followed in memory by a
PACKED_ELEMENTSarray (after_obj); - followed in memory by another
PACKED_DOUBLE_ELEMENTSarray (after_dbl2).
Using the out-of-bounds access through the array of length -1, the exploit increases the length of after_dbl and after_obj. After the lengths are altered, some of the data of after_dbl overlaps with some of the data of after_obj, and some of the data of after_obj overlaps with some of the data of after_dbl2. This overlap is what allows type confusions.
Step 4: Building addrof and fakeobj
With the overlapping arrays in place, the primitives are built as follows:
addrof: to leak the address of an object, the exploit first assigns the object into index0x2fof theafter_objarray. Becauseafter_objnow partially overlaps withafter_dbl2, the exploit then reads the pointer fromafter_dbl. It comes back as a double, which lets the exploit learn the numeric value of the object's address.fakeobj: to inject an arbitrary pointer value, the exploit assigns it intoafter_dbl. In a way similar toaddrof, the data is then read as a different type from a different overlapping array, in this caseafter_obj. Fetching it fromafter_objyields a reference to a fake JavaScript object at the specified address.
Step 5: Shellcode and stability
From there, all that remains is to copy the shellcode to the leaked address of the wasm function and execute it. After the shellcode runs, the page is idle and becomes subject to garbage collection, which may crash the renderer process. To handle this, the exploit developers tried to smooth over corruptions as much as possible to prevent a crash. The post includes a demo video of the exploit.

Root cause
The post does not re-derive the root cause of CVE-2021-21220 here; it refers readers to Part Two of the series for that. What it does explain is the exploitation-relevant design detail: the optimiser's typer can be made to believe a value is something it is not, and the optimised code then acts on that belief. In the shift path, the optimiser replaces the built-in call with inline operations that subtract one from the array length. When the JIT has been fooled into thinking the length is zero, the subtraction underflows to -1, and because bounds checks are unsigned, the resulting array can be indexed out of bounds.
The reason the older defence did not help is stated directly: array bounds check elimination, the previous standard route from a wrong number to an out-of-bounds access, had already been removed from V8. The shift technique was a replacement route. The post also notes that this route was mitigated a week after Pwn2Own by adding a new CheckBounds node, and that further methods continued to appear afterwards.
Impact
Under the conditions of the contest, the chain gives code execution in the renderer: an out-of-bounds access, then addrof/fakeobj, then arbitrary read/write through a forged array, then shellcode written over a wasm function's RWX memory and executed by calling that function. The researchers demonstrated this against both Chrome and Edge (Chromium) at Pwn2Own Vancouver 2021, earning $100,000. The post does not describe a sandbox escape, so the impact described is code execution in the renderer process, not a full chain out of the browser sandbox. It also notes that the exploit can leave the renderer in a state where garbage collection crashes it, which the authors tried to mitigate.
Fix
The post names two mitigations, both applied by the V8 developers rather than proposed by the researchers:
- Array bounds check elimination was removed from V8, closing the older technique of turning a wrong numeric result into an out-of-bounds access.
- The
shifttechnique was mitigated a week after Pwn2Own by adding a newCheckBoundsnode.
The post's closing argument is broader: JIT vulnerabilities are powerful because they provide strong primitives and reliable exploitation, and the complexity of JIT compilation makes it very hard for engine developers to handle every corner case. Incorrect JIT behaviour only has security impact if a technique exists to turn it into an effect such as an out-of-bounds access, and that is where the author suggests engine developers focus, by introducing additional hardening.
Variants to test
- Other built-in array methods that the optimiser inlines and that adjust the length field, in the same spirit as
ArrayPrototypeShiftandArrayPrototypePop. A positive result is an optimised function in which a JIT-induced wrong length leads to a length field of -1 or another value that passes the unsigned bounds check. - Other places where the typer's belief about a value is used to skip a check that the inlined code then relies on. A positive result is a discrepancy between the type the optimiser assumed and the value produced at run time, observable as an out-of-bounds index.
- The
Math.maxreduction used here to bring a huge confused value down to a small one. A positive result is a value that the optimiser treats as small and in range while the runtime value differs. - The overlapping-array layout used for
addrofandfakeobj(PACKED_DOUBLE_ELEMENTS, thenPACKED_ELEMENTS, thenPACKED_DOUBLE_ELEMENTS). A positive result is that corrupting one array's length produces a readable or writable overlap with its neighbour, giving a pointer leak as a double or a fake object reference. - The
wasmRWX page as a shellcode target, together with anArrayBufferwhosebacking_storepointer is uncompressed. A positive result is that a leakedwasmfunction address can be overwritten with attacker data and then executed by calling the function.
What happened, in plain words
Imagine a very fast but slightly overconfident assistant who reads your shopping list and decides, after seeing it many times, to memorise shortcuts instead of reading it carefully every time. Most of the time the shortcuts are correct and save time. But if you can trick the assistant into believing something false about the list, the shortcut can make it do something dangerous, like reach past the end of the shelf and grab an item that belongs to someone else.
That is roughly what happened with CVE-2021-21220, a bug in Chrome's JavaScript engine, V8. Two researchers, Bruno Keith (@bkth_) and Niklas Baumstark (@niklasb) of Dataflow Security (@dfsec_com), used it at a hacking contest called Pwn2Own Vancouver 2021. They exploited both Chrome and Edge (Chromium) and earned $100,000. The write-up we are reading is the third and final part of a ZDI blog series, written by ZDI Vulnerability Researcher Hossein Lotfi and published on 16 December 2021. It focuses on how the bug was turned into working code execution, not on the underlying cause, which was covered in Part Two.
To follow the story you only need to know a few ideas. A browser is the program you use to visit websites. Inside it, a JavaScript engine is the part that reads and runs the small programs (scripts) that websites send. Chrome's engine is called V8. Because scripts run constantly, V8 uses a JIT compiler (Just-In-Time compiler): a tool that watches which functions run often and rewrites them into faster machine code on the fly. That speed comes with risk, because the faster code makes assumptions, and if an attacker can make those assumptions wrong, the fast code can misbehave.
The bug lets the JIT produce a wrong number. A wrong number by itself is harmless. The interesting part, and the subject of this post, is how to turn that wrong number into an out-of-bounds memory access (reading or writing memory outside the area the program is supposed to touch), and from there into running the attacker's own code. The post walks through the older technique, the newer technique used at the contest, the standard chain from out-of-bounds access to code execution, and the specific steps the researchers took.
Context
This article follows the third and final post in a ZDI series on CVE-2021-21220, a Chrome bug used at Pwn2Own Vancouver 2021 by Bruno Keith (@bkth_) and Niklas Baumstark (@niklasb) of Dataflow Security (@dfsec_com). The researchers used it to exploit both Chrome and Edge (Chromium) and earned $100,000 at the event. The post, written by ZDI Vulnerability Researcher Hossein Lotfi and published on 16 December 2021, covers the exploitation technique used at the contest rather than the root cause, which was handled in Part Two of the series.
The target is V8, Chrome's JavaScript engine, and specifically its JIT compiler. The feature at the centre of the write-up is the optimiser's handling of numeric types and of built-in array methods. Normally, when a function is hot enough, V8 compiles an optimised version of it and replaces slow built-in calls such as Array.shift with inline assembly-level operations. The optimiser also reasons about the possible values of variables (its typer) and removes checks it believes are redundant. The bug lets the JIT produce an incorrect numeric result, and the exploitation work turns that wrong number into an out-of-bounds memory access and then into code execution.
Let us unpack those terms for a complete beginner.
- V8 is the engine inside Chrome (and other Chromium-based browsers such as Edge) that runs JavaScript. Think of it as the kitchen where a website's recipes are cooked.
- JIT compiler stands for Just-In-Time compiler. Instead of interpreting a script line by line forever, V8 notices which functions are used a lot and translates them into machine code, the language the processor speaks directly. It is like a cook who, after making the same dish a hundred times, writes down a faster routine and stops reading the recipe each time.
- Optimiser is the part of the JIT that decides how to make the fast version. It makes assumptions, for example that a variable will always be a whole number, and removes checks that would be unnecessary if those assumptions hold.
- Typer is the optimiser's internal bookkeeper of what type or range of values a variable can have. If the typer believes a value is always zero, the optimiser may skip a check that the value is zero.
- Built-in array methods are ready-made functions that JavaScript gives you for working with lists (arrays).
Array.shiftremoves the first item from a list and returns it.Array.popremoves the last item. Because these are used constantly, V8 has special fast paths for them. - Out-of-bounds memory access means reading or writing memory outside the region a program is allowed to touch. In a browser this is serious, because neighbouring memory may hold data belonging to other objects or to the engine itself.
- Code execution means getting the processor to run instructions the attacker supplied, rather than the program's own instructions.
The bug lets the JIT produce an incorrect numeric result. The exploitation work turns that wrong number into an out-of-bounds memory access and then into code execution. That sentence is the whole arc of the article.
Setup
The report does not describe a lab setup, browser versions, build flags or debugging tools. What it does state is the context of use: the exploit was demonstrated at Pwn2Own Vancouver 2021 against Chrome and Edge (Chromium), and the write-up reconstructs the technique from that contest. The only precondition it makes explicit is the one that matters technically: the attacker needs a JIT vulnerability that can make the engine compute a wrong numeric value, and then needs a way to turn that wrong value into a memory-safety side effect.
In plain words: you do not need a special computer or a particular version to understand the article. The article is not a step-by-step recipe for reproducing the attack at home. It is a description of what the researchers did at a contest, and the only requirement it names is the two-part condition above. First, a bug that makes the fast code compute a wrong number. Second, a trick that turns that wrong number into touching memory it should not touch. Without the second part, the first part is just a wrong answer on a calculator.
Finding it
The starting point is the observation from Part Two: CVE-2021-21220 can make the JIT generate code that produces an incorrect numeric result. On its own that is not a security bug. The question the post answers is how to convert a wrong number into something with impact, such as an out-of-bounds memory access.
The classic answer was array bounds check elimination. The post gives a simplified sample in which the length of an array arr is 4 and a function returns an element of it. V8 performs run-time bounds checking so that the final statement cannot access memory outside the array. During optimisation, V8 might remove that check if it concludes that typer_index is always zero, or more generally that typer_index * 10 is provably always inside the bounds of the array. This saves CPU cycles in the optimised function. If the JITted code then produces an erroneous numeric result, it may be possible to fool the engine into thinking typer_index must be zero while it is actually set to a different, erroneous value. The array access then triggers an out-of-bounds memory access.
That method was so successful that the V8 developers eventually removed array bounds check elimination. The post links to the V8 commit that did so, to an introduction to Turbofan for background on the technique, and to a second blog on circumventing Chrome's hardening of typer bugs. With that route closed, the contestants needed a new technique.
Let us slow this down, because it is the heart of the older technique.
An array is an ordered list. In JavaScript you can write arr[0], arr[1] and so on to get items. The length of the array is how many items it holds. A bounds check is a guard the engine puts around each access: before reading arr[i], it checks that i is at least 0 and less than the length. If not, it throws an error instead of reading memory it should not. Think of a librarian who checks that the shelf number you asked for actually exists before walking over.
Bounds check elimination is an optimisation: if the optimiser can prove that i is always within range, it removes the guard, saving a comparison on every access. The post's simplified sample has an array arr of length 4 and a function that returns an element of it. The optimiser might reason that typer_index is always zero, or more generally that typer_index * 10 is always inside the bounds of the array, and therefore drop the check. That reasoning is sound only if the typer's belief is correct. If the JIT can be made to produce an erroneous numeric result, the belief can be wrong while the optimised code still trusts it. The engine then thinks typer_index must be zero while it is actually a different, erroneous value, and the array access reaches out of bounds.
The post presents a simplified sample to illustrate the technique. What matters is the shape of the trick: a wrong number plus a removed check equals an out-of-bounds access.
That method was so successful that the V8 developers eventually removed array bounds check elimination altogether. The post links to the V8 commit that did so, to an introduction to Turbofan (the optimising compiler inside V8) for background, and to a second blog on circumventing Chrome's hardening of typer bugs. This is a recurring theme in security: a defence closes one door, and researchers look for another.
Exploitation
Step 1: Turn the wrong number into an out-of-bounds array
At Pwn2Own the researchers used a technique that produces out-of-bounds access through ArrayPrototypePop and ArrayPrototypeShift. Lotfi traced the method back to late 2020 by searching the Chromium bug tracker, and notes that it was mitigated a week after the competition by adding a new CheckBounds node.
The mechanism is as follows. When a function undergoing optimisation contains calls to Array.shift, execution flow eventually reaches JSCallReducer::ReduceArrayPrototypeShift in src/compiler/js-call-reducer.cc. Because a call to the built-in shift JavaScript method is relatively slow, the optimiser replaces the call with a series of operations that can be performed at the assembly level. Array.shift removes the first element from an array and returns that removed element. After removing it, the JIT-produced code computes the new array length by subtracting 1 from the original array length, and stores the result as the new length.
The exploit abuses the JIT vulnerability to fool the engine into thinking the array length is zero when it is not. The generated code then blindly subtracts one from zero. The integer underflow sets the array length to -1, and because array bounds checks are unsigned, a subsequent access can reach out of bounds. The post points to a Chromium bug entry for more detail on this underflow path.
The post notes that both techniques described so far, bounds check elimination and the shift underflow, have since been mitigated, but that new methods using JIT vulnerabilities to cause side effects and reach out-of-bounds access are still appearing.
This is dense, so let us take it piece by piece.
Array.shift is a standard JavaScript method. If you have a list [10, 20, 30] and call shift, you get back 10, and the list becomes [20, 30]. It removes the first item and returns it. Array.pop does the same at the other end: it removes the last item and returns it. Both change the length of the list.
Because these methods are used so often, V8 does not want to run a slow general-purpose function every time. When a function is hot (called many times), the optimiser rewrites the call into a short sequence of machine-level operations. The function that performs this rewrite for shift is JSCallReducer::ReduceArrayPrototypeShift, and it lives in the source file src/compiler/js-call-reducer.cc. The name is long but descriptive: it is the part of the compiler that reduces a JavaScript call to a built-in into lower-level operations.
One of those operations is: new length equals old length minus one. That is correct if the old length was, say, 3. It is also correct if the old length was 1, giving 0. But what if the engine has been fooled into thinking the length is 0 when it is not? Then the code subtracts one from zero and stores the result. In ordinary arithmetic that is -1. The post calls this an integer underflow, which sets the array length to -1. Either way, the stored length is no longer a sane small number.
Now the crucial detail: array bounds checks are unsigned. When the engine checks whether an index is valid, it treats the length as an unsigned number. Because array bounds checks are unsigned, a subsequent access can reach out of bounds. The guard that should stop you from reaching past the end of the array now waves you through. That is the out-of-bounds access.
The everyday comparison: a hotel clerk who is told the building has -1 rooms might, if the form only accepts positive numbers, write down a gigantic number instead. A guest asking for room 5000 is then told it exists.
Lotfi traced this method back to late 2020 by searching the Chromium bug tracker, and notes that it was mitigated a week after the competition by adding a new CheckBounds node. A node here means a step in the compiler's internal representation of the program; adding a CheckBounds node means the optimiser now inserts an explicit bounds check in this path, closing the trick. The post also notes that both techniques described so far, bounds check elimination and the shift underflow, have since been mitigated, but that new methods using JIT vulnerabilities to cause side effects and reach out-of-bounds access are still appearing.
Step 2: The standard V8 exploitation chain
Once an out-of-bounds read/write primitive exists, the post describes the well-known V8 exploitation steps:
- Trigger the vulnerability and the side effect to get a relative out-of-bounds memory access, used to corrupt the length of one or more arrays sitting next to the original array.
- Build
addrofandfakeobjprimitives.addrofleaks the address of an arbitrary JavaScript object.fakeobjdoes the reverse: it injects an arbitrary value into the engine that the engine will interpret as a pointer to a JavaScript object. - Use
fakeobjto forge a JavaScript array object whose data buffer field is an arbitrary attacker-specified address. The forged array can then read or write arbitrary memory addresses, unlike the relative out-of-bounds access of step 1, which only permits access at arbitrary offsets past the start of the original array. - Use
addrofto leak the address of awasmfunction. This is where the shellcode will be copied. Awasmfunction is a good choice because the memory it occupies is marked RWX (Read-Write-Execute). - Use
fakeobjto copy shellcode to the RWX page. To make copying easier, anArrayBufferwith an uncompressedbacking_storepointer is often used. This overwrites thewasmfunction instructions with the shellcode. - Execute the shellcode by calling the
wasmfunction.
This numbered list is the general recipe that many V8 exploits follow once they have an out-of-bounds primitive. Let us explain each term before walking the steps.
- A primitive in exploitation means a small, reliable capability that you can reuse, like a single Lego brick that you can snap onto others. An out-of-bounds read/write primitive is the ability to read or write memory outside an array's bounds.
- Relative out-of-bounds access means you can reach memory at some distance past the start of your array, but you do not yet know absolute addresses. It is like being able to walk N steps east from where you stand without knowing your street address.
addrofis short for address-of. It is a helper that, given a JavaScript object, tells you the numeric memory address where that object lives.fakeobjis the reverse: given a number, it makes the engine treat that number as if it were the address of a JavaScript object. The object does not really exist; you have faked a reference to it.- A pointer is a number that means "the memory address of something". If you know a pointer, you know where to look.
wasmstands for WebAssembly, a compact binary format that browsers can run at near-native speed. Awasmfunction's machine code lives in memory that is marked RWX: Readable, Writable and Executable. That is unusual and very useful to an attacker, because it means you can write bytes there and then have the processor execute them.- Shellcode is the small piece of machine code an attacker wants to run, traditionally one that opens a shell (hence the name). In a browser exploit it is whatever the attacker wants the processor to do next.
- An
ArrayBufferis a JavaScript object that represents a raw block of bytes. It has an internal field calledbacking_store, a pointer to where those bytes actually live in memory. Pointer compression is a V8 memory-saving feature that stores some pointers in a compressed form; the post notes that anArrayBufferwith an uncompressedbacking_storepointer is often used, because then the pointer is a full-size address that is easier to overwrite and use.
Now the steps in plain words:
- Use the bug to get a relative out-of-bounds access, and use it to corrupt the length of one or more arrays that sit next to the original array in memory. Arrays are laid out one after another, so reaching past the end of one lands you in the next.
- Build
addrofandfakeobj. These are the two basic tools that turn a relative primitive into an absolute one. - Use
fakeobjto forge an array object whose data buffer points at any address the attacker chooses. Now reading or writing that forged array reads or writes that address. This is stronger than step 1, which could only reach offsets past the original array. - Use
addrofto find the address of awasmfunction. That is where the shellcode will go, because the memory there is RWX. - Use
fakeobjto copy the shellcode into that RWX page. AnArrayBufferwith an uncompressedbacking_storepointer is often used to make the copy easier. This overwrites thewasmfunction's instructions with the shellcode. - Call the
wasmfunction. The processor jumps to that memory and runs the shellcode.
Step 3: The actual Pwn2Own exploit
The post describes how this was done in practice but does not reproduce the exploit source. It says the exploit starts by defining helper functions to convert between floats and integers, then triggers the JIT vulnerability. After triggering it, the value of the bad variable is huge, so it is passed through a series of Math.max calls to bring it down to a smaller value (1). This confused value is then used to create an array, and a shift on that array produces an array of length -1. That array allows the exploit to access memory at arbitrary offsets past the end of the array.
Setting up the wasm RWX memory is the next step. The contents of the wasm function do not matter, because its instructions will be replaced with shellcode.
The exploit then allocates three arrays in a deliberate order:
- a
PACKED_DOUBLE_ELEMENTSarray (after_dbl); - followed in memory by a
PACKED_ELEMENTSarray (after_obj); - followed in memory by another
PACKED_DOUBLE_ELEMENTSarray (after_dbl2).
Using the out-of-bounds access through the array of length -1, the exploit increases the length of after_dbl and after_obj. After the lengths are altered, some of the data of after_dbl overlaps with some of the data of after_obj, and some of the data of after_obj overlaps with some of the data of after_dbl2. This overlap is what allows type confusions.
The post includes short code snippets rather than the full exploit source. We can still explain every idea.
Floats and integers. A float is a number with a decimal point, such as 1.5. An integer is a whole number, such as 7. In memory, the same 8 bytes can be interpreted as either, depending on what the program thinks it is looking at. Exploits often need to convert between the two, because a memory address is naturally an integer but JavaScript arrays of numbers store floats. The helper functions mentioned at the start do exactly this conversion. The post does not show them.
Triggering the JIT vulnerability. The exploit calls the buggy code so that the optimiser produces its wrong result. After triggering it, the value of the bad variable is huge. A huge number is awkward to use directly, so the exploit passes it through a series of Math.max calls to bring it down to a smaller value (1). Math.max returns the larger of its arguments; chaining calls is a way of clamping a value. The result is a confused value: the optimiser believes one thing about it, while at run time it is something else.
Setting up the wasm RWX memory. The exploit creates a WebAssembly function so that there is a page of memory marked RWX to use later. It is a placeholder, like reserving a parking space you intend to repaint.
The three arrays. The exploit allocates three arrays in a deliberate order:
These names describe how V8 stores the contents. PACKED_DOUBLE_ELEMENTS means the array holds numbers stored as doubles (64-bit floating point values) with no gaps. PACKED_ELEMENTS means the array holds general JavaScript values, which can be objects, and stores them as pointers. The order matters because arrays are placed next to each other in memory. By putting a double array, then an object array, then another double array, the exploit arranges for the neighbours it wants.
This overlap is what allows type confusions: the same bytes are read as a number through one array and as a pointer through the other. The everyday comparison is two people reading the same line of text: one reads it as a phone number, the other as a price, because each has a different form in front of them.
Step 4: Building addrof and fakeobj
With the overlapping arrays in place, the primitives are built as follows:
addrof: to leak the address of an object, the exploit first assigns the object into index0x2fof theafter_objarray. Becauseafter_objnow partially overlaps withafter_dbl2, the exploit then reads the pointer fromafter_dbl. It comes back as a double, which lets the exploit learn the numeric value of the object's address.fakeobj: to inject an arbitrary pointer value, the exploit assigns it intoafter_dbl. In a way similar toaddrof, the data is then read as a different type from a different overlapping array, in this caseafter_obj. Fetching it fromafter_objyields a reference to a fake JavaScript object at the specified address.
Let us walk through both, because they are the two tools everything else depends on.
addrof. The exploit wants to know where an object lives. It assigns the object into index 0x2f of the after_obj array. 0x2f is hexadecimal for 47; the exact index is chosen so that the slot lines up with a slot in the neighbouring array. Reading a pointer through a double array gives back a double, which lets the exploit learn the numeric value of the object's address. In other words: put the object in one array, read the same bytes through the other, and the pointer comes out as a number you can do arithmetic on.
fakeobj. The reverse. The exploit assigns a chosen pointer value into after_dbl. In other words: write a number into the double array, read the same bytes through the object array, and the engine now treats your number as a pointer to an object. The object does not exist; you have told the engine to believe it does.
Step 5: Shellcode and stability
From there, all that remains is to copy the shellcode to the leaked address of the wasm function and execute it. After the shellcode runs, the page is idle and becomes subject to garbage collection, which may crash the renderer process. To handle this, the exploit developers tried to smooth over corruptions as much as possible to prevent a crash. The post includes a demo video of the exploit.
Garbage collection is the engine's automatic cleanup. It walks through memory, finds objects nobody is using any more, and frees them. If the exploit has corrupted the bookkeeping that garbage collection relies on, the cleanup can trip over the damage and crash the renderer process, the separate process in which a browser tab runs. A crash is not a security failure in itself, but it is noisy and unreliable, so the researchers tried to smooth over corruptions as much as possible to prevent a crash.

Root cause
The post does not re-derive the root cause of CVE-2021-21220 here; it refers readers to Part Two of the series for that. What it does explain is the exploitation-relevant design detail: the optimiser's typer can be made to believe a value is something it is not, and the optimised code then acts on that belief. In the shift path, the optimiser replaces the built-in call with inline operations that subtract one from the array length. When the JIT has been fooled into thinking the length is zero, the subtraction underflows to -1, and because bounds checks are unsigned, the resulting array can be indexed out of bounds.
The reason the older defence did not help is stated directly: array bounds check elimination, the previous standard route from a wrong number to an out-of-bounds access, had already been removed from V8. The shift technique was a replacement route. The post also notes that this route was mitigated a week after Pwn2Own by adding a new CheckBounds node, and that further methods continued to appear afterwards.
In plain words: the root cause is a mismatch between what the optimiser believes and what is actually true at run time. The typer is the optimiser's belief system. If the typer can be made to believe a value is something it is not, the optimised code acts on that belief. In the shift path, the optimiser replaces the built-in call with inline operations that subtract one from the array length without a check that the length is actually non-zero.
The older defence, removing bounds check elimination, did not help here because it closed a different route. The pattern is a race between hardening and new tricks.
Impact
Under the conditions of the contest, the chain gives code execution in the renderer: an out-of-bounds access, then addrof/fakeobj, then arbitrary read/write through a forged array, then shellcode written over a wasm function's RWX memory and executed by calling that function. The researchers demonstrated this against both Chrome and Edge (Chromium) at Pwn2Own Vancouver 2021, earning $100,000. The post does not describe a sandbox escape, so the impact described is code execution in the renderer process, not a full chain out of the browser sandbox. It also notes that the exploit can leave the renderer in a state where garbage collection crashes it, which the authors tried to mitigate.
A sandbox is a set of restrictions that keeps a browser tab from touching the rest of the computer. Chrome runs each tab in its own renderer process with limited permissions. Code execution in the renderer means the attacker's code runs inside that restricted box. A sandbox escape would be a further step that breaks out of the box. The post does not describe one, so the impact described is code execution in the renderer process, not a full chain out of the browser sandbox.
Fix
The post names two mitigations, both applied by the V8 developers rather than proposed by the researchers:
- Array bounds check elimination was removed from V8, closing the older technique of turning a wrong numeric result into an out-of-bounds access.
- The
shifttechnique was mitigated a week after Pwn2Own by adding a newCheckBoundsnode.
The post's closing argument is broader: JIT vulnerabilities are powerful because they provide strong primitives and reliable exploitation, and the complexity of JIT compilation makes it very hard for engine developers to handle every corner case. Incorrect JIT behaviour only has security impact if a technique exists to turn it into an effect such as an out-of-bounds access, and that is where the author suggests engine developers focus, by introducing additional hardening.
A mitigation is a change that makes an attack harder or impossible without necessarily fixing the underlying design. Both mitigations here were applied by the V8 developers rather than proposed by the researchers. The first removed array bounds check elimination from V8, closing the older technique of turning a wrong numeric result into an out-of-bounds access. The second mitigated the shift technique a week after Pwn2Own by adding a new CheckBounds node.
Hardening means adding defences that make exploitation harder even when a bug exists, like fitting a second lock on a door.
Variants to test
- Other built-in array methods that the optimiser inlines and that adjust the length field, in the same spirit as
ArrayPrototypeShiftandArrayPrototypePop. A positive result is an optimised function in which a JIT-induced wrong length leads to a length field of -1 or another value that passes the unsigned bounds check. - Other places where the typer's belief about a value is used to skip a check that the inlined code then relies on. A positive result is a discrepancy between the type the optimiser assumed and the value produced at run time, observable as an out-of-bounds index.
- The
Math.maxreduction used here to bring a huge confused value down to a small one. A positive result is a value that the optimiser treats as small and in range while the runtime value differs. - The overlapping-array layout used for
addrofandfakeobj(PACKED_DOUBLE_ELEMENTS, thenPACKED_ELEMENTS, thenPACKED_DOUBLE_ELEMENTS). A positive result is that corrupting one array's length produces a readable or writable overlap with its neighbour, giving a pointer leak as a double or a fake object reference. - The
wasmRWX page as a shellcode target, together with anArrayBufferwhosebacking_storepointer is uncompressed. A positive result is that a leakedwasmfunction address can be overwritten with attacker data and then executed by calling the function.
These are suggestions for further research, not instructions for an attack. Each one names a place to look and a sign that you have found something. The first asks whether other built-in array methods that the optimiser inlines and that adjust the length field behave like shift and pop. The second asks whether other places exist where the typer's belief about a value is used to skip a check that the inlined code then relies on. The third looks at the Math.max reduction used here to bring a huge confused value down to a small one. The fourth looks at the overlapping-array layout used for addrof and fakeobj. The fifth looks at the wasm RWX page as a shellcode target, together with an ArrayBuffer whose backing_store pointer is uncompressed.
Glossary
- Array: an ordered list of values in JavaScript, accessed by index such as
arr[0]. - Array bounds check: a guard that verifies an index is within an array's length before allowing access.
- Array bounds check elimination: an optimisation that removes that guard when the compiler believes the index is always in range.
Array.shift: a built-in JavaScript method that removes the first element of an array and returns it.Array.pop: a built-in JavaScript method that removes the last element of an array and returns it.ArrayBuffer: a JavaScript object representing a raw block of bytes, with an internalbacking_storepointer to where the bytes live.addrof: an exploitation primitive that leaks the memory address of a JavaScript object.fakeobj: an exploitation primitive that makes the engine treat a chosen number as the address of a JavaScript object.backing_store: the internal pointer in anArrayBufferthat points to the actual byte storage.- Bounds check: see array bounds check.
- Built-in: a function that the JavaScript engine provides out of the box, such as
Array.shift. CheckBoundsnode: a step added to the compiler's internal representation that explicitly checks array bounds.- Code execution: getting the processor to run instructions supplied by an attacker.
- Confused value: a value the optimiser believes one thing about while at run time it is something else.
- CVE: Common Vulnerabilities and Exposures, a public identifier for a specific security bug.
- Double: a 64-bit floating point number, used by JavaScript for all numbers.
fakeobj: see above.- Float: a number with a decimal point, stored in floating point format.
- Garbage collection: automatic cleanup of memory that is no longer in use.
- Hardening: defences added to make exploitation harder even when a bug exists.
- Hot function: a function called often enough that the JIT decides to optimise it.
- Integer: a whole number.
- Integer underflow: subtracting from a value so that it wraps around to a very large number when treated as unsigned.
- JIT (Just-In-Time compiler): a component that translates frequently used code into fast machine code while the program runs.
JSCallReducer::ReduceArrayPrototypeShift: the V8 compiler function that rewrites calls toArray.shiftinto lower-level operations.Math.max: a JavaScript function that returns the largest of its arguments.- Mitigation: a change that makes an attack harder or impossible.
- Node: a step in the compiler's internal representation of a program.
- Out-of-bounds memory access: reading or writing memory outside the region a program is allowed to touch.
PACKED_DOUBLE_ELEMENTS: a V8 array representation holding doubles with no gaps.PACKED_ELEMENTS: a V8 array representation holding general JavaScript values as pointers.- Pointer: a number that represents a memory address.
- Pointer compression: a V8 memory-saving feature that stores some pointers in a compressed form.
- Primitive: a small, reusable exploitation capability.
- Pwn2Own: a hacking contest where researchers demonstrate exploits against real products.
- Relative out-of-bounds access: the ability to reach memory at offsets past an array without knowing absolute addresses.
- Renderer process: the separate process in which a browser tab runs.
- RWX: memory marked Readable, Writable and Executable.
- Sandbox: restrictions that keep a browser tab from touching the rest of the computer.
- Sandbox escape: breaking out of those restrictions.
- Shellcode: the small piece of machine code an attacker wants to run.
- Turbofan: the optimising compiler inside V8.
- Typer: the optimiser's internal bookkeeper of what type or range of values a variable can have.
- Type confusion: reading the same bytes as two different types, so that one interpretation is wrong.
- Unsigned: a number interpretation with no negative values, so -1 becomes a very large positive number.
- V8: Chrome's JavaScript engine.
wasm(WebAssembly): a compact binary format browsers can run at near-native speed.- WebAssembly: see
wasm. - ZDI: Zero Day Initiative, the organisation that published the blog series.