House of Einherjar
This house is not part of "The Malloc Maleficarum". This heap exploitation technique was given by Hiroki Matsukuma in 2016. This attack also revolves around making 'malloc' return a nearly arbitrary pointer. Unlike other attacks, this requires just a single byte of overflow. There exists much more software vulnerable to a single byte of overflow mainly due to the famous "off by one" error. It overwrites into the 'size' of the next chunk in memory and clears the PREV_IN_USE
flag to 0. Also, it overwrites into prev_size
(already in the previous chunk's data region) a fake size. When the next chunk is freed, it finds the previous chunk to be free and tries to consolidate by going back 'fake size' in memory. This fake size is so calculated so that the consolidated chunk ends up at a fake chunk, which will be returned by subsequent malloc.
Consider this sample code (download the complete version here):
Note the following:
The second chunk's size was given as
0xf8
. This simply ensured that the actual chunk's size has the least significant byte as0
(ignoring the flag bits). Hence, it was a simple matter to set the previous in use bit to0
without changing the size of this chunk.The
allotedSize
was further decreased bysizeof(size_t)
.allotedSize
is equal to the size of the complete chunk. However, the size allowed for data issizeof(size_t)
less, or the equivalent of thesize
parameter in the heap. This is becausesize
andprev_size
of the current chunk cannot be used, but theprev_size
of the next chunk can be used.Fake chunk's forward and backward pointers were adjusted to pass the security check in
unlink
.
Last updated