there is an off-by-null vulnerability in implant_user_memory.
there is also a vulnerability in erase_memory
the slot list will not be initialized if there is memory whole.
exploit flow
heap leak
alloc 0x40
alloc 0x10
free 1
free 2
reallocate 0x40
recollect_memory 2
tcache poisoning
create chunk
create chunk
remove first chunk
reallocate chunk with off by null and rewrite the size of next chunk(0x10 + inuse flag).
create chunk
remove reallocated chunk
reallocate chunk with off by null and rewrite the size of next chunk(0x30 + inuse flag).
the previous operation concat 0x10 chunk and next 0x20 chunk.
remove the next of reallocated chunk
reallocate chunk and overwrite the next by (heap-base>>12 ^ slot-list)
then, tcache will create in the slot-list
reallocate with padding and flag address
Why overwrite the next by (heap-base>>12 ^ slot-list) is safe-linking.
/* Safe-Linking:
Use randomness from ASLR (mmap_base) to protect single-linked lists
of Fast-Bins and TCache. That is, mask the "next" pointers of the
lists' chunks, and also perform allocation alignment checks on them.
This mechanism reduces the risk of pointer hijacking, as was done with
Safe-Unlinking in the double-linked lists of Small-Bins.
It assumes a minimum page size of 4096 bytes (12 bits). Systems with
larger pages provide less entropy, although the pointer mangling
still works. */
#define PROTECT_PTR(pos, ptr) \
((__typeof (ptr)) ((((size_t) pos) >> 12) ^ ((size_t) ptr)))
heap information after rewrite size of chunk (0x21 -> 0x11) by off-by-one vulnerability.
heap information after rewrite size of chunk 0x11 -> 0x31 as you can see, purple area's size is 0x31, but purple area+0x30 is located at the next chunk.