Skip to content

Commit 1b1453d

Browse files
committed
document NEVER_REUSE_ZONES and make custom zones unusable when destroyed
1 parent 88af20d commit 1b1453d

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ CXX = clang++
99
## FUZZ_MODE - Call verify_all_zones upon alloc/free, never reuse custom zones
1010
## PERM_FREE_REALLOC - Permanently free any realloc'd chunk
1111
## DISABLE_CANARY - Disables the use of canaries, improves performance
12-
SECURITY_FLAGS = -DSANITIZE_CHUNKS=0 -DFUZZ_MODE=0 -DPERM_FREE_REALLOC=0 -DDISABLE_CANARY=0
12+
## NEVER_REUSE_ZONES - Tells IsoAlloc to unmap user and bitmap pages when destroying custom zones
13+
SECURITY_FLAGS = -DSANITIZE_CHUNKS=0 -DFUZZ_MODE=0 -DPERM_FREE_REALLOC=0 -DDISABLE_CANARY=0 \
14+
-DNEVER_REUSE_ZONES=0
1315

1416
## Enable abort() when isoalloc can't gather enough entropy.
1517
ABORT_NO_ENTROPY = -DABORT_NO_ENTROPY=1

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ When enabled, the `CPU_PIN` feature will restrict allocations from a given zone
8282
* By default `NO_ZERO_ALLOCATIONS` will return a pointer to a page marked `PROT_NONE` for all `0` sized allocations.
8383
* When `ABORT_NO_ENTROPY` is enabled IsoAlloc will abort when it can't gather enough entropy.
8484
* When `SHUFFLE_BIT_SLOT_CACHE` is enabled IsoAlloc will shuffle the bit slot cache upon creation (3-4x perf hit)
85+
* When destroying custom zones if `NEVER_REUSE_ZONES` is enabled IsoAlloc won't attempt to repurpose the zone
8586

8687
## Building
8788

src/iso_alloc.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,16 @@ INTERNAL_HIDDEN void _iso_alloc_destroy_zone(iso_alloc_zone *zone) {
463463

464464
if(zone->internally_managed == false) {
465465
#if NEVER_REUSE_ZONES || FUZZ_MODE
466-
_unmap_zone(zone);
467-
zone->user_pages_start = NULL;
468-
zone->bitmap_start = NULL;
466+
memset(zone->bitmap_start, 0x0, zone->bitmap_size);
467+
memset(zone->user_pages_start, 0x0, ZONE_USER_SIZE);
468+
469+
/* This will waste memory because we will never unmap
470+
* these pages, even in the destructor */
471+
mprotect_pages(zone->bitmap_start, zone->bitmap_size, PROT_NONE);
472+
mprotect_pages(zone->user_pages_start, ZONE_USER_SIZE, PROT_NONE);
469473

470-
/* Mark the zone as full so no attempts are made to use it */
474+
/* Make this zone unusable */
475+
memset(zone, 0x0, sizeof(iso_alloc_zone));
471476
zone->is_full = true;
472477
flush_thread_zone_cache();
473478
#else

0 commit comments

Comments
 (0)