Skip to content

Commit

Permalink
Actually free memory in free(); use-after-free issues will no longer …
Browse files Browse the repository at this point in the history
…be discovered
  • Loading branch information
Shnatsel committed Aug 29, 2018
1 parent f7bc9d3 commit 14ff5db
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions libdislocator.so.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void* malloc(size_t len) {
}


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

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

total_mem -= len;

/* Protect everything. Note that the extra page at the end is already
set as PROT_NONE, so we don't need to touch that. */

ptr -= PAGE_SIZE * PG_COUNT(len + 8) - len - 8;

if (mprotect(ptr - 8, PG_COUNT(len + 8) * PAGE_SIZE, PROT_NONE))
FATAL("mprotect() failed when freeing memory");

/* Keep the mapping; this is wasteful, but prevents ptr reuse. */
munmap(ptr - 8, (1 + PG_COUNT(len + 8)) * PAGE_SIZE);

}

Expand Down

0 comments on commit 14ff5db

Please sign in to comment.