Skip to content

Commit 453a7d5

Browse files
nwf-msrnwf
authored andcommitted
backend: clobber MetaEntry-s in dealloc_chunk
Otherwise these won't get updated until the small buddy allocator hands them off to the large buddy allocator (when they morph into being rbtree nodes) and so the frontend might get confused in the interim (including risk of UAF on double-free).
1 parent 2ff2cdf commit 453a7d5

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/backend/backend.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,18 @@ namespace snmalloc
305305
{
306306
auto chunk = chunk_record->meta_common.chunk;
307307

308+
/*
309+
* The backend takes possession of these chunks now, by disassociating
310+
* any existing remote allocator and metadata structure. If
311+
* interrogated, the sizeclass reported by the MetaEntry is 0, which has
312+
* size 0.
313+
*/
314+
MetaEntry t(nullptr, MetaEntry::REMOTE_BACKEND_MARKER);
315+
Pagemap::set_metaentry(address_cast(chunk), size, t);
316+
308317
local_state.get_meta_range()->dealloc_range(
309318
capptr::Chunk<void>(chunk_record), PAGEMAP_METADATA_STRUCT_SIZE);
310319

311-
// TODO, should we set the sizeclass to something specific here?
312-
313320
local_state.object_range->dealloc_range(chunk, size);
314321
}
315322

0 commit comments

Comments
 (0)