Skip to content

Commit 9955a4a

Browse files
jakobkummerowmibrunin
authored andcommitted
[Backport] CVE-2025-0291: Type Confusion in V8 (1/2)
Cherry-pick of patch originally reviewed on https://chromium-review.googlesource.com/c/v8/v8/+/6097632: Merged: [turboshaft][wasm] WasmGCTypeAnalyzer: Fix phi input for single-block loops Fixed: 383356864 (cherry picked from commit f231d83cb3c08754413b3ee1aa249cebd4d5445f) Change-Id: I3247f6071a9a27eaef49ae8981b7eea93f83dc55 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6097632 Reviewed-by: Eva Herencsárová <[email protected]> Auto-Submit: Jakob Kummerow <[email protected]> Commit-Queue: Eva Herencsárová <[email protected]> Commit-Queue: Jakob Kummerow <[email protected]> Cr-Commit-Position: refs/branch-heads/13.0@{#45} Cr-Branched-From: 4be854bd71ea878a25b236a27afcecffa2e29360-refs/heads/13.0.245@{#1} Cr-Branched-From: 1f5183f7ad6cca21029fd60653d075730c644432-refs/heads/main@{#96103} Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/615722 Reviewed-by: Anu Aliyas <[email protected]>
1 parent 5c94c92 commit 9955a4a

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

chromium/v8/src/compiler/turboshaft/wasm-gc-typed-optimization-reducer.cc

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,28 @@ void WasmGCTypeAnalyzer::ProcessAllocateStruct(
269269
wasm::ValueType::Ref(type_index));
270270
}
271271

272+
wasm::ValueType WasmGCTypeAnalyzer::GetTypeForPhiInput(const PhiOp& phi,
273+
int input_index) {
274+
OpIndex phi_id = graph_.Index(phi);
275+
OpIndex input = ResolveAliases(phi.input(input_index));
276+
// If the input of the phi is in the same block as the phi and appears
277+
// before the phi, don't use the predecessor value.
278+
279+
if (current_block_->begin().id() <= input.id() && input.id() < phi_id.id()) {
280+
// Phi instructions have to be at the beginning of the block, so this can
281+
// only happen for inputs that are also phis. Furthermore, this is only
282+
// possible in loop headers of loops with a single block (endless loops) and
283+
// only for the backedge-input.
284+
DCHECK(graph_.Get(input).Is<PhiOp>());
285+
DCHECK(current_block_->IsLoop());
286+
DCHECK(current_block_->HasBackedge(graph_));
287+
DCHECK_EQ(current_block_->LastPredecessor(), current_block_);
288+
DCHECK_EQ(input_index, 1);
289+
return types_table_.Get(input);
290+
}
291+
return types_table_.GetPredecessorValue(input, input_index);
292+
}
293+
272294
void WasmGCTypeAnalyzer::ProcessPhi(const PhiOp& phi) {
273295
// The result type of a phi is the union of all its input types.
274296
// If any of the inputs is the default value ValueType(), there isn't any type
@@ -281,12 +303,10 @@ void WasmGCTypeAnalyzer::ProcessPhi(const PhiOp& phi) {
281303
RefineTypeKnowledge(graph_.Index(phi), GetResolvedType((phi.input(0))));
282304
return;
283305
}
284-
wasm::ValueType union_type =
285-
types_table_.GetPredecessorValue(ResolveAliases(phi.input(0)), 0);
306+
wasm::ValueType union_type = GetTypeForPhiInput(phi, 0);
286307
if (union_type == wasm::ValueType()) return;
287308
for (int i = 1; i < phi.input_count; ++i) {
288-
wasm::ValueType input_type =
289-
types_table_.GetPredecessorValue(ResolveAliases(phi.input(i)), i);
309+
wasm::ValueType input_type = GetTypeForPhiInput(phi, i);
290310
if (input_type == wasm::ValueType()) return;
291311
// <bottom> types have to be skipped as an unreachable predecessor doesn't
292312
// change our type knowledge.

chromium/v8/src/compiler/turboshaft/wasm-gc-typed-optimization-reducer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class WasmGCTypeAnalyzer {
8080
void ProcessPhi(const PhiOp& phi);
8181
void ProcessTypeAnnotation(const WasmTypeAnnotationOp& type_annotation);
8282

83+
wasm::ValueType GetTypeForPhiInput(const PhiOp& phi, int input_index);
84+
8385
void CreateMergeSnapshot(const Block& block);
8486
bool CreateMergeSnapshot(base::Vector<const Snapshot> predecessors,
8587
base::Vector<const bool> reachable);

0 commit comments

Comments
 (0)