Skip to content

Commit 356065b

Browse files
miktcopybara-github
authored andcommitted
[PA] Fix PartitionRoot::CheckMetadataIntegrity
Calling `PartitionRoot::FromAddrInFirstSuperpage` on a pointer to middle of a direct-mapped allocation is not allowed. Bug: 435448631 Change-Id: Ia3a6ecf37350184458c8a18c6a0782338ae75d37 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6821095 Commit-Queue: Mikihito Matsuura <[email protected]> Reviewed-by: Keishi Hattori <[email protected]> Cr-Commit-Position: refs/heads/main@{#1496874} NOKEYCHECK=True GitOrigin-RevId: d6a376f7bc36e3b7a9052d8a4170df09e0cd1fe1
1 parent 659d300 commit 356065b

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/partition_alloc/partition_alloc_unittest.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,6 +2495,29 @@ TEST_P(PartitionAllocTest, LostFreeSlotSpansBug) {
24952495
EXPECT_TRUE(bucket->decommitted_slot_spans_head);
24962496
}
24972497

2498+
TEST_P(PartitionAllocTest, CheckMetadataIntegrityPass) {
2499+
char* const small_ptr =
2500+
static_cast<char*>(allocator.root()->Alloc(kTestAllocSize));
2501+
ASSERT_TRUE(small_ptr);
2502+
2503+
// Should not crash.
2504+
PartitionRoot::CheckMetadataIntegrity(small_ptr);
2505+
PartitionRoot::CheckMetadataIntegrity(small_ptr + kTestAllocSize - 1);
2506+
2507+
allocator.root()->Free(small_ptr);
2508+
2509+
constexpr size_t kDirectMapSize = BucketIndexLookup::kMaxBucketSize + 1;
2510+
char* const large_ptr =
2511+
static_cast<char*>(allocator.root()->Alloc(kDirectMapSize));
2512+
ASSERT_TRUE(large_ptr);
2513+
2514+
// Should not crash.
2515+
PartitionRoot::CheckMetadataIntegrity(large_ptr);
2516+
PartitionRoot::CheckMetadataIntegrity(large_ptr + kDirectMapSize - 1);
2517+
2518+
allocator.root()->Free(large_ptr);
2519+
}
2520+
24982521
#if PA_USE_DEATH_TESTS()
24992522

25002523
// Unit tests that check if an allocation fails in "return null" mode,

src/partition_alloc/partition_root.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,17 +1842,17 @@ void PartitionRoot::CheckMetadataIntegrity(const void* ptr) {
18421842
return;
18431843
}
18441844

1845-
auto* root = FromAddrInFirstSuperpage(address);
1846-
18471845
const internal::ReservationOffsetTable& reservation_offset =
1848-
root->GetReservationOffsetTable();
1846+
internal::ReservationOffsetTable::Get(address);
18491847
if (reservation_offset.IsManagedByDirectMap(address)) {
18501848
// OOB for direct-mapped allocations is likely immediate crash.
18511849
// No extra benefit from additional checks.
18521850
return;
18531851
}
18541852

18551853
PA_CHECK(reservation_offset.IsManagedByNormalBuckets(address));
1854+
1855+
auto* root = FromAddrInFirstSuperpage(address);
18561856
SlotSpanMetadata* slot_span = SlotSpanMetadata::FromAddr(address, root);
18571857
PA_CHECK(PartitionRoot::FromSlotSpanMetadata(slot_span) == root);
18581858

0 commit comments

Comments
 (0)