Skip to content

Commit 5474107

Browse files
committed
Scrub deallocations before reallocation.
1 parent 1077be0 commit 5474107

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ if(NOT SNMALLOC_HEADER_ONLY_LIBRARY)
490490
random_larger_thresholds;
491491
random_initial;
492492
random_preserve;
493-
random_extra_slab)
493+
random_extra_slab;
494+
scrub_free)
494495

495496

496497
foreach (MITIGATION ${MITIGATIONS})

src/snmalloc/ds_core/mitigations.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,18 @@ namespace snmalloc
209209
* model.
210210
*/
211211
static constexpr mitigation::type pal_enforce_access{1 << 13};
212+
/**
213+
* If this mitigation is enabled, then deallocations are
214+
* scrubbed before reallocation. This prevents data leaks
215+
* by looking into uninitialised memory.
216+
*/
217+
static constexpr mitigation::type scrub_free{1 << 14};
212218

213219
constexpr mitigation::type full_checks = random_pagemap +
214220
random_larger_thresholds + freelist_forward_edge + freelist_backward_edge +
215221
freelist_teardown_validate + random_initial + random_preserve +
216222
metadata_protection + random_extra_slab + reuse_LIFO + sanity_checks +
217-
clear_meta + pal_enforce_access;
223+
clear_meta + pal_enforce_access + scrub_free;
218224

219225
constexpr mitigation::type no_checks{0};
220226

src/snmalloc/mem/corealloc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,12 @@ namespace snmalloc
688688
is_start_of_object(entry.get_sizeclass(), address_cast(p)),
689689
"Not deallocating start of an object");
690690

691+
if (mitigations(scrub_free))
692+
{
693+
Config::Pal::zero(
694+
p.unsafe_ptr(), sizeclass_full_to_size(entry.get_sizeclass()));
695+
}
696+
691697
auto cp = p.as_static<freelist::Object::T<>>();
692698

693699
auto& key = entropy.get_free_list_key();

0 commit comments

Comments
 (0)