Skip to content

Commit 14ff5db

Browse files
committed
Actually free memory in free(); use-after-free issues will no longer be discovered
1 parent f7bc9d3 commit 14ff5db

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

libdislocator.so.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void* malloc(size_t len) {
196196
}
197197

198198

199-
/* The wrapper for free(). This simply marks the entire region as PROT_NONE.
199+
/* The wrapper for free().
200200
If the region is already freed, the code will segfault during the attempt to
201201
read the canary. Not very graceful, but works, right? */
202202

@@ -214,15 +214,9 @@ void free(void* ptr) {
214214

215215
total_mem -= len;
216216

217-
/* Protect everything. Note that the extra page at the end is already
218-
set as PROT_NONE, so we don't need to touch that. */
219-
220217
ptr -= PAGE_SIZE * PG_COUNT(len + 8) - len - 8;
221218

222-
if (mprotect(ptr - 8, PG_COUNT(len + 8) * PAGE_SIZE, PROT_NONE))
223-
FATAL("mprotect() failed when freeing memory");
224-
225-
/* Keep the mapping; this is wasteful, but prevents ptr reuse. */
219+
munmap(ptr - 8, (1 + PG_COUNT(len + 8)) * PAGE_SIZE);
226220

227221
}
228222

0 commit comments

Comments
 (0)