Skip to content

Commit

Permalink
Add stricter double free checking on large allocs (#550)
Browse files Browse the repository at this point in the history
Although, double frees are generally caught on large allocs.  This is
done very late in the process after many operations more operations have
occurred.

This change brings that check much earlier in the process.
  • Loading branch information
mjp41 authored Sep 2, 2022
1 parent f8efcb7 commit 88a2740
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/snmalloc/mem/localalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ namespace snmalloc

const PagemapEntry& entry =
Config::Backend::get_metaentry(address_cast(p_tame));

if (SNMALLOC_LIKELY(local_cache.remote_allocator == entry.get_remote()))
{
# if defined(__CHERI_PURE_CAPABILITY__) && defined(SNMALLOC_CHECK_CLIENT)
Expand All @@ -647,6 +648,11 @@ namespace snmalloc
# if defined(__CHERI_PURE_CAPABILITY__) && defined(SNMALLOC_CHECK_CLIENT)
dealloc_cheri_checks(p_tame.unsafe_ptr());
# endif

// Detect double free of large allocations here.
snmalloc_check_client(
!entry.is_backend_owned(), "Memory corruption detected");

// Check if we have space for the remote deallocation
if (local_cache.remote_dealloc_cache.reserve_space(entry))
{
Expand Down

0 comments on commit 88a2740

Please sign in to comment.