House of Lore
This attack is basically the forging chunks attack for small and large bins. However, due to an added protection for large bins in around 2007 (the introduction of fd_nextsize
and bk_nextsize
) it became impractical. Here we shall see the case only for small bins. First, a small chunk will be placed in a small bin. It's bk
pointer will be overwritten to point to a fake small chunk. Note that in the case of small bins, insertion happens at the HEAD
and removal at the TAIL
. A malloc call will first remove the authentic chunk from the bin making the attacker's fake chunk at the TAIL
of the bin. The next malloc will return the attacker's chunk.
Consider this sample code (download the complete version here):
Notice that the steps needed for forging a small chunk are more due to the complicated handling of small chunks. Particular care was needed to ensure that victim->bk->fd
equals victim
for every small chunk that is to be returned from 'malloc', to pass the "malloc(): smallbin double linked list corrupted" security check. Also, extra 'malloc' calls were added in between to ensure that:
The first chunk goes to the unsorted bin instead of merging with the top chunk on freeing.
The first chunk goes to the small bin as it does not satisfy a malloc request for
len + 0x10
.
The state of the unsorted bin and the small bin are shown:
free(ptr). Unsorted bin:
head <-> ptr <-> tail
Small bin:
head <-> tail
malloc(len + 0x10); Unsorted bin:
head <-> tail
Small bin:
head <-> ptr <-> tail
Pointer manipulations Unsorted bin:
head <-> tail
Small bin:
undefined <-> fake_chunk <-> ptr <-> tail
malloc(len) Unsorted bin:
head <-> tail
Small bin:
undefined <-> fake_chunk <-> tail
malloc(len) Unsorted bin:
head <-> tail
Small bin:
undefined <-> tail [ Fake chunk is returned ]
Note that another 'malloc' call for the corresponding small bin will result in a segmentation fault.
Last updated