From ee238eb00d68b4f0aa6863ed58d2707746a18770 Mon Sep 17 00:00:00 2001 From: David Mendenhall Date: Mon, 20 Apr 2020 14:24:47 -0700 Subject: Move comment about adding 8 bytes to buffer length to the line where we actually add 8 bytes Remove defunct TODO for posix_memalign as the function now exists Add wrapper for malloc_usable_size --- libdislocator/libdislocator.so.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'libdislocator/libdislocator.so.c') diff --git a/libdislocator/libdislocator.so.c b/libdislocator/libdislocator.so.c index 1fbfe9d6..72d280e6 100644 --- a/libdislocator/libdislocator.so.c +++ b/libdislocator/libdislocator.so.c @@ -183,6 +183,9 @@ static void *__dislocator_alloc(size_t len) { else rlen = len; + /* We will also store buffer length and a canary below the actual buffer, so + let's add 8 bytes for that. */ + tlen = (1 + PG_COUNT(rlen + 8)) * PAGE_SIZE; flags = MAP_PRIVATE | MAP_ANONYMOUS; fd = -1; @@ -200,9 +203,6 @@ static void *__dislocator_alloc(size_t len) { (void)sp; #endif - /* We will also store buffer length and a canary below the actual buffer, so - let's add 8 bytes for that. */ - ret = (u8 *)mmap(NULL, tlen, PROT_READ | PROT_WRITE, flags, fd, 0); #if defined(USEHUGEPAGE) /* We try one more time with regular call */ @@ -296,10 +296,6 @@ void *calloc(size_t elem_len, size_t elem_cnt) { } -/* TODO: add a wrapper for posix_memalign, otherwise apps who use it, - will fail when freeing the memory. -*/ - /* The wrapper for malloc(). Roughly the same, also clobbers the returned memory (unlike calloc(), malloc() is not guaranteed to return zeroed memory). */ @@ -468,6 +464,12 @@ void *reallocarray(void *ptr, size_t elem_len, size_t elem_cnt) { } +size_t malloc_usable_size(void *ptr) { + + return PTR_L(ptr); + +} + __attribute__((constructor)) void __dislocator_init(void) { u8 *tmp = (u8 *)getenv("AFL_LD_LIMIT_MB"); @@ -492,4 +494,3 @@ __attribute__((constructor)) void __dislocator_init(void) { align_allocations = !!getenv("AFL_ALIGNED_ALLOC"); } - -- cgit 1.4.1 From 0aef3b40403848d6a86fca56b0bf520b1851c1d0 Mon Sep 17 00:00:00 2001 From: David Mendenhall Date: Mon, 20 Apr 2020 15:00:48 -0700 Subject: add NULL check to malloc_usable_size --- libdislocator/libdislocator.so.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdislocator/libdislocator.so.c') diff --git a/libdislocator/libdislocator.so.c b/libdislocator/libdislocator.so.c index 72d280e6..19e84d9f 100644 --- a/libdislocator/libdislocator.so.c +++ b/libdislocator/libdislocator.so.c @@ -466,7 +466,7 @@ void *reallocarray(void *ptr, size_t elem_len, size_t elem_cnt) { size_t malloc_usable_size(void *ptr) { - return PTR_L(ptr); + return ptr ? PTR_L(ptr) : 0; } -- cgit 1.4.1 From ce9c6df45639db922feafb55259e20c7e82af0bf Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Tue, 21 Apr 2020 09:17:11 +0100 Subject: libdislocator android build fix. (#327) Fix function signature for bionic libc --- libdislocator/libdislocator.so.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libdislocator/libdislocator.so.c') diff --git a/libdislocator/libdislocator.so.c b/libdislocator/libdislocator.so.c index 19e84d9f..8098de91 100644 --- a/libdislocator/libdislocator.so.c +++ b/libdislocator/libdislocator.so.c @@ -464,7 +464,11 @@ void *reallocarray(void *ptr, size_t elem_len, size_t elem_cnt) { } +#if !defined(__ANDROID__) size_t malloc_usable_size(void *ptr) { +#else +size_t malloc_usable_size(const void *ptr) { +#endif return ptr ? PTR_L(ptr) : 0; -- cgit 1.4.1