Skip to content

Commit 6f4b9a2

Browse files
GeorgNeismibrunin
authored andcommitted
[Backport] CVE-2021-30599: Type Confusion in V8
Manual backport of patch originally reviewed on https://chromium-review.googlesource.com/c/v8/v8/+/3080564: Merged: [compiler] Fix a bug in MachineOperatorReducer's BitfieldCheck Revision: 574ca6b71c6160d38b5fcf4b8e133bc7f6ba2387 BUG=chromium:1234770 NOTRY=true NOPRESUBMIT=true NOTREECHECKS=true [email protected] Change-Id: I15af5a94e89b54c2a540442c3544ed459b832e0a Reviewed-by: Lutz Vahl <[email protected]> Commit-Queue: Georg Neis <[email protected]> Cr-Commit-Position: refs/branch-heads/9.3@{#21} Cr-Branched-From: 7744dce208a555494e4a33e24fadc71ea20b3895-refs/heads/9.3.345@{#1} Cr-Branched-From: 4b6b4cabf3b6a20cdfda72b369df49f3311c4344-refs/heads/master@{#75728} Reviewed-by: Allan Sandfeld Jensen <[email protected]>
1 parent e9fe457 commit 6f4b9a2

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

chromium/v8/src/compiler/machine-operator-reducer.cc

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,11 +1641,20 @@ Reduction MachineOperatorReducer::ReduceWordNAnd(Node* node) {
16411641
namespace {
16421642

16431643
// Represents an operation of the form `(source & mask) == masked_value`.
1644+
// where each bit set in masked_value also has to be set in mask.
16441645
struct BitfieldCheck {
1645-
Node* source;
1646-
uint32_t mask;
1647-
uint32_t masked_value;
1648-
bool truncate_from_64_bit;
1646+
Node* const source;
1647+
uint32_t const mask;
1648+
uint32_t const masked_value;
1649+
bool const truncate_from_64_bit;
1650+
BitfieldCheck(Node* source, uint32_t mask, uint32_t masked_value,
1651+
bool truncate_from_64_bit)
1652+
: source(source),
1653+
mask(mask),
1654+
masked_value(masked_value),
1655+
truncate_from_64_bit(truncate_from_64_bit) {
1656+
CHECK_EQ(masked_value & ~mask, 0);
1657+
}
16491658

16501659
static base::Optional<BitfieldCheck> Detect(Node* node) {
16511660
// There are two patterns to check for here:
@@ -1660,14 +1669,16 @@ struct BitfieldCheck {
16601669
if (eq.left().IsWord32And()) {
16611670
Uint32BinopMatcher mand(eq.left().node());
16621671
if (mand.right().HasValue() && eq.right().HasValue()) {
1663-
BitfieldCheck result{mand.left().node(), mand.right().Value(),
1664-
eq.right().Value(), false};
1672+
uint32_t mask = mand.right().Value();
1673+
uint32_t masked_value = eq.right().Value();
1674+
if ((masked_value & ~mask) != 0) return {};
16651675
if (mand.left().IsTruncateInt64ToInt32()) {
1666-
result.truncate_from_64_bit = true;
1667-
result.source =
1668-
NodeProperties::GetValueInput(mand.left().node(), 0);
1676+
return BitfieldCheck(
1677+
NodeProperties::GetValueInput(mand.left().node(), 0), mask,
1678+
masked_value, true);
1679+
} else {
1680+
return BitfieldCheck(mand.left().node(), mask, masked_value, false);
16691681
}
1670-
return result;
16711682
}
16721683
}
16731684
} else {

0 commit comments

Comments
 (0)