Skip to content

Commit 95f2f82

Browse files
victorgomesmibrunin
authored andcommitted
[Backport] CVE-2021-30541: Use after free in V8
Cherry-pick of patch originally reviewed on https://chromium-review.googlesource.com/c/v8/v8/+/3067222: Fix GC issue in BuildJsonObject We must ensure that the sweeper is not running or has already swept mutable_double_buffer. Otherwise the GC can add it to the free list. (cherry picked from commit 81181a8ad80ac978a6a8732d05f615c645df95d2) Bug: v8:11837 Bug: chromium:1214842 No-Try: true No-Presubmit: true No-Tree-Checks: true Change-Id: Ifd9cf15f1c94f664fd6489c70bb38b59730cdd78 Commit-Queue: Victor Gomes <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#74859} Commit-Queue: Roger Felipe Zanoni da Silva <[email protected]> Reviewed-by: Achuith Bhandarkar <[email protected]> Reviewed-by: Jana Grill <[email protected]> Cr-Commit-Position: refs/branch-heads/9.0@{#68} Cr-Branched-From: bd0108b4c88e0d6f2350cb79b5f363fbd02f3eb7-refs/heads/9.0.257@{#1} Cr-Branched-From: 349bcc6a075411f1a7ce2d866c3dfeefc2efa39d-refs/heads/master@{#73001} Reviewed-by: Allan Sandfeld Jensen <[email protected]>
1 parent aea2873 commit 95f2f82

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

chromium/v8/src/heap/heap.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,10 @@ void Heap::CompleteSweepingYoung(GarbageCollector collector) {
21172117
array_buffer_sweeper()->EnsureFinished();
21182118
}
21192119

2120+
void Heap::EnsureSweepingCompleted() {
2121+
mark_compact_collector()->EnsureSweepingCompleted();
2122+
}
2123+
21202124
void Heap::UpdateCurrentEpoch(GarbageCollector collector) {
21212125
if (IsYoungGenerationCollector(collector)) {
21222126
epoch_young_ = next_epoch();

chromium/v8/src/heap/heap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,8 @@ class Heap {
10681068
void CompleteSweepingFull();
10691069
void CompleteSweepingYoung(GarbageCollector collector);
10701070

1071+
void EnsureSweepingCompleted();
1072+
10711073
IncrementalMarking* incremental_marking() {
10721074
return incremental_marking_.get();
10731075
}

chromium/v8/src/json/json-parser.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,11 @@ Handle<Object> JsonParser<Char>::BuildJsonObject(
620620
DCHECK_EQ(mutable_double_address, end);
621621
}
622622
#endif
623+
// Before setting the length of mutable_double_buffer back to zero, we
624+
// must ensure that the sweeper is not running or has already swept the
625+
// object's page. Otherwise the GC can add the contents of
626+
// mutable_double_buffer to the free list.
627+
isolate()->heap()->EnsureSweepingCompleted();
623628
mutable_double_buffer->set_length(0);
624629
}
625630
}

0 commit comments

Comments
 (0)