Skip to content

Commit

Permalink
perform init sanity checks before MPK unsealing
Browse files Browse the repository at this point in the history
  • Loading branch information
thestinger committed Oct 6, 2020
1 parent 2bb1c39 commit b072022
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions h_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1612,9 +1612,9 @@ EXPORT size_t h_malloc_usable_size(H_MALLOC_USABLE_SIZE_CONST void *p) {
return 0;
}

thread_unseal_metadata();

if (p < get_slab_region_end() && p >= ro.slab_region_start) {
thread_unseal_metadata();

memory_corruption_check_small(p);
thread_seal_metadata();

Expand All @@ -1623,6 +1623,8 @@ EXPORT size_t h_malloc_usable_size(H_MALLOC_USABLE_SIZE_CONST void *p) {
}

enforce_init();
thread_unseal_metadata();

struct region_allocator *ra = ro.region_allocator;
mutex_lock(&ra->lock);
struct region_metadata *region = regions_find(p);
Expand All @@ -1641,10 +1643,10 @@ EXPORT size_t h_malloc_object_size(void *p) {
return 0;
}

thread_unseal_metadata();

void *slab_region_end = get_slab_region_end();
if (p < slab_region_end && p >= ro.slab_region_start) {
thread_unseal_metadata();

struct slab_size_class_info size_class_info = slab_size_class(p);
size_t class = size_class_info.class;
size_t size_class = size_classes[class];
Expand Down Expand Up @@ -1681,6 +1683,8 @@ EXPORT size_t h_malloc_object_size(void *p) {
return SIZE_MAX;
}

thread_unseal_metadata();

struct region_allocator *ra = ro.region_allocator;
mutex_lock(&ra->lock);
struct region_metadata *region = regions_find(p);
Expand Down

0 comments on commit b072022

Please sign in to comment.