Skip to content

Commit d2679df

Browse files
victorgomesmibrunin
authored andcommitted
[Backport] CVE-2021-30541: Use after free in V8
Manual backport of patch originally reviewed on https://chromium-review.googlesource.com/c/v8/v8/+/2993033: Merged: [JSON] 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. Change-Id: If0fc7617acdb6690f0567215b78f8728e1643ec0 No-Try: true No-Presubmit: true No-Tree-Checks: true Bug: v8:11837, chromium:1214842 Reviewed-by: Michael Lippautz <[email protected]> Reviewed-by: Toon Verwaest <[email protected]> Commit-Queue: Victor Gomes <[email protected]> Cr-Commit-Position: refs/branch-heads/9.1@{#75} Cr-Branched-From: 0e4ac64a8cf298b14034a22f9fe7b085d2cb238d-refs/heads/9.1.269@{#1} Cr-Branched-From: f565e72d5ba88daae35a59d0f978643e2343e912-refs/heads/master@{#73847} Reviewed-by: Michal Klocek <[email protected]>
1 parent c49a1b4 commit d2679df

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
@@ -2222,6 +2222,10 @@ void Heap::RecomputeLimits(GarbageCollector collector) {
22222222
}
22232223
}
22242224

2225+
void Heap::EnsureSweepingCompleted() {
2226+
mark_compact_collector()->EnsureSweepingCompleted();
2227+
}
2228+
22252229
void Heap::CallGCPrologueCallbacks(GCType gc_type, GCCallbackFlags flags) {
22262230
RuntimeCallTimerScope runtime_timer(
22272231
isolate(), RuntimeCallCounterId::kGCPrologueCallback);

chromium/v8/src/heap/heap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,8 @@ class Heap {
10651065
Reservation* reservations, const std::vector<HeapObject>& large_objects,
10661066
const std::vector<Address>& maps);
10671067

1068+
void EnsureSweepingCompleted();
1069+
10681070
IncrementalMarking* incremental_marking() {
10691071
return incremental_marking_.get();
10701072
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,11 @@ Handle<Object> JsonParser<Char>::BuildJsonObject(
633633
DCHECK_EQ(mutable_double_address, end);
634634
}
635635
#endif
636+
// Before setting the length of mutable_double_buffer back to zero, we
637+
// must ensure that the sweeper is not running or has already swept the
638+
// object's page. Otherwise the GC can add the contents of
639+
// mutable_double_buffer to the free list.
640+
isolate()->heap()->EnsureSweepingCompleted();
636641
mutable_double_buffer->set_length(0);
637642
}
638643
}

0 commit comments

Comments
 (0)