Skip to content

Commit 59c82b5

Browse files
GeorgNeismibrunin
authored andcommitted
[Backport] CVE-2021-30513: Type Confusion in V8
Cherry-pick of commit originally reviewed on https://chromium-review.googlesource.com/c/v8/v8/+/2883780: Reland "[compiler] Fix more truncation bugs in SimplifiedLowering" This is a reland of 47077d94492cb604e3a7f02c0d7c3c495ff6b713 without changes. The revert was false alarm. [M86]: Resolved simple conflicts. Original change's description: > [compiler] Fix more truncation bugs in SimplifiedLowering > > Bug: chromium:1200490 > Change-Id: I3555b6d99bdb4b4e7c302a43a82c17e8bff84ebe > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2840452 > Reviewed-by: Nico Hartmann <[email protected]> > Commit-Queue: Georg Neis <[email protected]> > Cr-Commit-Position: refs/heads/master@{#74097} (cherry picked from commit e4a580c9104e42968e8e13b8c7d933f0b2eda2a3) (cherry picked from commit 97ad04543438f7b235b21346fdd198f81028cd5e) Bug: chromium:1200490 Tbr: [email protected] No-Try: true No-Presubmit: true No-Tree-Checks: true Change-Id: Iedddcf2d0117fa59dc9d7a3604ef203808ad2903 Reviewed-by: Georg Neis <[email protected]> Commit-Queue: Georg Neis <[email protected]> Cr-Original-Commit-Position: refs/branch-heads/9.0@{#47} Cr-Original-Branched-From: bd0108b4c88e0d6f2350cb79b5f363fbd02f3eb7-refs/heads/9.0.257@{#1} Cr-Original-Branched-From: 349bcc6a075411f1a7ce2d866c3dfeefc2efa39d-refs/heads/master@{#73001} Reviewed-by: Jana Grill <[email protected]> Commit-Queue: Victor-Gabriel Savu <[email protected]> Cr-Commit-Position: refs/branch-heads/8.6@{#95} Cr-Branched-From: a64aed2333abf49e494d2a5ce24bbd14fff19f60-refs/heads/8.6.395@{#1} Cr-Branched-From: a626bc036236c9bf92ac7b87dc40c9e538b087e3-refs/heads/master@{#69472} Reviewed-by: Allan Sandfeld Jensen <[email protected]>
1 parent a7025fe commit 59c82b5

File tree

1 file changed

+43
-26
lines changed

1 file changed

+43
-26
lines changed

chromium/v8/src/compiler/simplified-lowering.cc

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,17 +1398,32 @@ class RepresentationSelector {
13981398
return jsgraph_->simplified();
13991399
}
14001400

1401-
void LowerToCheckedInt32Mul(Node* node, Truncation truncation,
1402-
Type input0_type, Type input1_type) {
1403-
// If one of the inputs is positive and/or truncation is being applied,
1404-
// there is no need to return -0.
1405-
CheckForMinusZeroMode mz_mode =
1406-
truncation.IdentifiesZeroAndMinusZero() ||
1407-
IsSomePositiveOrderedNumber(input0_type) ||
1408-
IsSomePositiveOrderedNumber(input1_type)
1409-
? CheckForMinusZeroMode::kDontCheckForMinusZero
1410-
: CheckForMinusZeroMode::kCheckForMinusZero;
1411-
NodeProperties::ChangeOp(node, simplified()->CheckedInt32Mul(mz_mode));
1401+
template <Phase T>
1402+
void VisitForCheckedInt32Mul(Node* node, Truncation truncation,
1403+
Type input0_type, Type input1_type,
1404+
UseInfo input_use) {
1405+
DCHECK_EQ(node->opcode(), IrOpcode::kSpeculativeNumberMultiply);
1406+
// A -0 input is impossible or will cause a deopt.
1407+
DCHECK(BothInputsAre(node, Type::Signed32()) ||
1408+
!input_use.truncation().IdentifiesZeroAndMinusZero());
1409+
1410+
CheckForMinusZeroMode mz_mode;
1411+
Type restriction;
1412+
if (IsSomePositiveOrderedNumber(input0_type) ||
1413+
IsSomePositiveOrderedNumber(input1_type)) {
1414+
mz_mode = CheckForMinusZeroMode::kDontCheckForMinusZero;
1415+
restriction = Type::Signed32();
1416+
} else if (truncation.IdentifiesZeroAndMinusZero()) {
1417+
mz_mode = CheckForMinusZeroMode::kDontCheckForMinusZero;
1418+
restriction = Type::Signed32OrMinusZero();
1419+
} else {
1420+
mz_mode = CheckForMinusZeroMode::kCheckForMinusZero;
1421+
restriction = Type::Signed32();
1422+
}
1423+
1424+
VisitBinop<T>(node, input_use, MachineRepresentation::kWord32, restriction);
1425+
if (lower<T>())
1426+
NodeProperties::ChangeOp(node, simplified()->CheckedInt32Mul(mz_mode));
14121427
}
14131428

14141429
void ChangeToInt32OverflowOp(Node* node) {
@@ -1600,12 +1615,22 @@ class RepresentationSelector {
16001615
VisitBinop<T>(node, lhs_use, rhs_use, MachineRepresentation::kWord32);
16011616
if (lower<T>()) DeferReplacement(node, lowering->Int32Mod(node));
16021617
} else if (BothInputsAre(node, Type::Unsigned32OrMinusZeroOrNaN())) {
1618+
Type const restriction =
1619+
truncation.IdentifiesZeroAndMinusZero() &&
1620+
TypeOf(node->InputAt(0)).Maybe(Type::MinusZero())
1621+
? Type::Unsigned32OrMinusZero()
1622+
: Type::Unsigned32();
16031623
VisitBinop<T>(node, lhs_use, rhs_use, MachineRepresentation::kWord32,
1604-
Type::Unsigned32());
1624+
restriction);
16051625
if (lower<T>()) ChangeToUint32OverflowOp(node);
16061626
} else {
1627+
Type const restriction =
1628+
truncation.IdentifiesZeroAndMinusZero() &&
1629+
TypeOf(node->InputAt(0)).Maybe(Type::MinusZero())
1630+
? Type::Signed32OrMinusZero()
1631+
: Type::Signed32();
16071632
VisitBinop<T>(node, lhs_use, rhs_use, MachineRepresentation::kWord32,
1608-
Type::Signed32());
1633+
restriction);
16091634
if (lower<T>()) ChangeToInt32OverflowOp(node);
16101635
}
16111636
return;
@@ -2165,23 +2190,17 @@ class RepresentationSelector {
21652190
// If both inputs and feedback are int32, use the overflow op.
21662191
if (hint == NumberOperationHint::kSignedSmall ||
21672192
hint == NumberOperationHint::kSigned32) {
2168-
VisitBinop<T>(node, UseInfo::TruncatingWord32(),
2169-
MachineRepresentation::kWord32, Type::Signed32());
2170-
if (lower<T>()) {
2171-
LowerToCheckedInt32Mul(node, truncation, input0_type,
2172-
input1_type);
2173-
}
2193+
VisitForCheckedInt32Mul<T>(node, truncation, input0_type,
2194+
input1_type,
2195+
UseInfo::TruncatingWord32());
21742196
return;
21752197
}
21762198
}
21772199

21782200
if (hint == NumberOperationHint::kSignedSmall ||
21792201
hint == NumberOperationHint::kSigned32) {
2180-
VisitBinop<T>(node, CheckedUseInfoAsWord32FromHint(hint),
2181-
MachineRepresentation::kWord32, Type::Signed32());
2182-
if (lower<T>()) {
2183-
LowerToCheckedInt32Mul(node, truncation, input0_type, input1_type);
2184-
}
2202+
VisitForCheckedInt32Mul<T>(node, truncation, input0_type, input1_type,
2203+
CheckedUseInfoAsWord32FromHint(hint));
21852204
return;
21862205
}
21872206

@@ -3901,7 +3920,6 @@ template <>
39013920
void RepresentationSelector::SetOutput<RETYPE>(
39023921
Node* node, MachineRepresentation representation, Type restriction_type) {
39033922
NodeInfo* const info = GetInfo(node);
3904-
DCHECK(info->restriction_type().Is(restriction_type));
39053923
DCHECK(restriction_type.Is(info->restriction_type()));
39063924
info->set_output(representation);
39073925
}
@@ -3911,7 +3929,6 @@ void RepresentationSelector::SetOutput<LOWER>(
39113929
Node* node, MachineRepresentation representation, Type restriction_type) {
39123930
NodeInfo* const info = GetInfo(node);
39133931
DCHECK_EQ(info->representation(), representation);
3914-
DCHECK(info->restriction_type().Is(restriction_type));
39153932
DCHECK(restriction_type.Is(info->restriction_type()));
39163933
USE(info);
39173934
}

0 commit comments

Comments
 (0)