Skip to content

Commit a72a550

Browse files
ShabbyXmibrunin
authored andcommitted
[Backport] CVE-2024-7532: Out of bounds memory access in ANGLE (1/2)
Cherry-pick of patch originally reviewed on https://chromium-review.googlesource.com/c/angle/angle/+/5735815: Prune switch(constant) with no matching case Bug: chromium:350528343 Change-Id: Iabb475b230f22086de482bbdcf2fa00b0d986622 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5735815 Auto-Submit: Shahbaz Youssefi <[email protected]> Commit-Queue: Geoff Lang <[email protected]> Reviewed-by: Geoff Lang <[email protected]> Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/582140 Reviewed-by: Allan Sandfeld Jensen <[email protected]>
1 parent c91c781 commit a72a550

File tree

2 files changed

+68
-8
lines changed

2 files changed

+68
-8
lines changed

chromium/third_party/angle/src/compiler/translator/tree_ops/PruneNoOps.cpp

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@
33
// Use of this source code is governed by a BSD-style license that can be
44
// found in the LICENSE file.
55
//
6-
// PruneNoOps.cpp: The PruneNoOps function prunes:
7-
// 1. Empty declarations "int;". Empty declarators will be pruned as well, so for example:
8-
// int , a;
9-
// is turned into
10-
// int a;
11-
// 2. Literal statements: "1.0;". The ESSL output doesn't define a default precision for float,
12-
// so float literal statements would end up with no precision which is invalid ESSL.
13-
// 3. Statements after discard, return, break and continue.
6+
// PruneNoOps.cpp: The PruneNoOps function prunes no-op statements.
147

158
#include "compiler/translator/tree_ops/PruneNoOps.h"
169

@@ -22,6 +15,67 @@ namespace sh
2215

2316
namespace
2417
{
18+
uint32_t GetSwitchConstantAsUInt(const TConstantUnion *value)
19+
{
20+
TConstantUnion asUInt;
21+
if (value->getType() == EbtYuvCscStandardEXT)
22+
{
23+
asUInt.setUConst(value->getYuvCscStandardEXTConst());
24+
}
25+
else
26+
{
27+
bool valid = asUInt.cast(EbtUInt, *value);
28+
ASSERT(valid);
29+
}
30+
return asUInt.getUConst();
31+
}
32+
33+
bool IsNoOpSwitch(TIntermSwitch *node)
34+
{
35+
if (node == nullptr)
36+
{
37+
return false;
38+
}
39+
40+
TIntermConstantUnion *expr = node->getInit()->getAsConstantUnion();
41+
if (expr == nullptr)
42+
{
43+
return false;
44+
}
45+
46+
const uint32_t exprValue = GetSwitchConstantAsUInt(expr->getConstantValue());
47+
48+
// See if any block matches the constant value
49+
const TIntermSequence &statements = *node->getStatementList()->getSequence();
50+
51+
for (TIntermNode *statement : statements)
52+
{
53+
TIntermCase *caseLabel = statement->getAsCaseNode();
54+
if (caseLabel == nullptr)
55+
{
56+
continue;
57+
}
58+
59+
// Default matches everything, consider it not a no-op.
60+
if (!caseLabel->hasCondition())
61+
{
62+
return false;
63+
}
64+
65+
TIntermConstantUnion *condition = caseLabel->getCondition()->getAsConstantUnion();
66+
ASSERT(condition != nullptr);
67+
68+
// If any case matches the value, it's not a no-op.
69+
const uint32_t caseValue = GetSwitchConstantAsUInt(condition->getConstantValue());
70+
if (caseValue == exprValue)
71+
{
72+
return false;
73+
}
74+
}
75+
76+
// No case matched the constant value the switch was used on, so the entire switch is a no-op.
77+
return true;
78+
}
2579

2680
bool IsNoOp(TIntermNode *node)
2781
{
@@ -32,6 +86,11 @@ bool IsNoOp(TIntermNode *node)
3286
return true;
3387
}
3488

89+
if (IsNoOpSwitch(node->getAsSwitchNode()))
90+
{
91+
return true;
92+
}
93+
3594
if (node->getAsTyped() == nullptr || node->getAsFunctionPrototypeNode() != nullptr)
3695
{
3796
return false;

chromium/third_party/angle/src/compiler/translator/tree_ops/PruneNoOps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// 2. Literal statements: "1.0;". The ESSL output doesn't define a default precision for float,
1212
// so float literal statements would end up with no precision which is invalid ESSL.
1313
// 3. Statements after discard, return, break and continue.
14+
// 4. Switch statements over a constant, where no case matches the constant
1415

1516
#ifndef COMPILER_TRANSLATOR_TREEOPS_PRUNENOOPS_H_
1617
#define COMPILER_TRANSLATOR_TREEOPS_PRUNENOOPS_H_

0 commit comments

Comments
 (0)