Skip to content

Commit

Permalink
[Backport] CVE-2021-30541: Use after free in V8
Browse files Browse the repository at this point in the history
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 <victorgomes@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#74859}
Commit-Queue: Roger Felipe Zanoni da Silva <rzanoni@google.com>
Reviewed-by: Achuith Bhandarkar <achuith@chromium.org>
Reviewed-by: Jana Grill <janagrill@google.com>
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 <allan.jensen@qt.io>
  • Loading branch information
victorgomes authored and mibrunin committed Sep 3, 2021
1 parent aea2873 commit 95f2f82
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions chromium/v8/src/heap/heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,10 @@ void Heap::CompleteSweepingYoung(GarbageCollector collector) {
array_buffer_sweeper()->EnsureFinished();
}

void Heap::EnsureSweepingCompleted() {
mark_compact_collector()->EnsureSweepingCompleted();
}

void Heap::UpdateCurrentEpoch(GarbageCollector collector) {
if (IsYoungGenerationCollector(collector)) {
epoch_young_ = next_epoch();
Expand Down
2 changes: 2 additions & 0 deletions chromium/v8/src/heap/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,8 @@ class Heap {
void CompleteSweepingFull();
void CompleteSweepingYoung(GarbageCollector collector);

void EnsureSweepingCompleted();

IncrementalMarking* incremental_marking() {
return incremental_marking_.get();
}
Expand Down
5 changes: 5 additions & 0 deletions chromium/v8/src/json/json-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,11 @@ Handle<Object> JsonParser<Char>::BuildJsonObject(
DCHECK_EQ(mutable_double_address, end);
}
#endif
// Before setting the length of mutable_double_buffer back to zero, we
// must ensure that the sweeper is not running or has already swept the
// object's page. Otherwise the GC can add the contents of
// mutable_double_buffer to the free list.
isolate()->heap()->EnsureSweepingCompleted();
mutable_double_buffer->set_length(0);
}
}
Expand Down

0 comments on commit 95f2f82

Please sign in to comment.