diff options
author | realmadsci <71108352+realmadsci@users.noreply.github.com> | 2021-03-04 13:33:06 -0500 |
---|---|---|
committer | realmadsci <71108352+realmadsci@users.noreply.github.com> | 2021-03-15 12:07:22 -0700 |
commit | 96574854b34b42650190648014c7ca673cfd31ce (patch) | |
tree | 2119584b6deebcfdfa9d777ce98fdf995e657198 /qemu_mode/libqasan/malloc.c | |
parent | 281cd47c154e7cd642e76482f5f07e9f1584c561 (diff) | |
download | afl++-96574854b34b42650190648014c7ca673cfd31ce.tar.gz |
libqasan/malloc: Additional pointer checks
Add checks to free() and malloc_usable_size() to verify (sort of) that the pointers are actually pointing at valid allocated memory before dereferencing them and using the chunk_begin struct info. This will catch use-after-free and wildly bad pointers a little bit earlier.
Diffstat (limited to 'qemu_mode/libqasan/malloc.c')
-rw-r--r-- | qemu_mode/libqasan/malloc.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/qemu_mode/libqasan/malloc.c b/qemu_mode/libqasan/malloc.c index 5a2d2a0c..6fe6fc8c 100644 --- a/qemu_mode/libqasan/malloc.c +++ b/qemu_mode/libqasan/malloc.c @@ -159,6 +159,9 @@ size_t __libqasan_malloc_usable_size(void *ptr) { char *p = ptr; p -= sizeof(struct chunk_begin); + // Validate that the chunk marker is readable (a crude check + // to verify that ptr is a valid malloc region before we dereference it) + QASAN_LOAD(p, sizeof(struct chunk_begin) - REDZONE_SIZE); return ((struct chunk_begin *)p)->requested_size; } @@ -225,6 +228,9 @@ void __libqasan_free(void *ptr) { struct chunk_begin *p = ptr; p -= 1; + // Validate that the chunk marker is readable (a crude check + // to verify that ptr is a valid malloc region before we dereference it) + QASAN_LOAD(p, sizeof(struct chunk_begin) - REDZONE_SIZE); size_t n = p->requested_size; QASAN_STORE(ptr, n); |