support randomizing the lower bits of brk

This adds support for arch_randomize_brk implementations not performing
page alignment in order to randomize the lower bits of the brk heap.

This idea is taken from PaX but the approach is different. This reuses
the existing code and avoids forcing early creation of the heap mapping,
avoiding mapping it if it's not used which is the case with many modern
allocators based solely on mmap.

The malloc implementation can be relied upon to align this as needed to
the requirements it has, so using 16 byte alignment here is unnecessary.

Signed-off-by: Daniel Micay <danielmicay@gmail.com>
Signed-off-by: anupritaisno1 <www.anuprita804@gmail.com>
This commit is contained in:
Daniel Micay 2017-05-30 18:03:30 -04:00 committed by Kreciorek
parent 2994f3aa26
commit e3839126e6

View file

@ -250,6 +250,13 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
newbrk = PAGE_ALIGN(brk); newbrk = PAGE_ALIGN(brk);
oldbrk = PAGE_ALIGN(mm->brk); oldbrk = PAGE_ALIGN(mm->brk);
/* properly handle unaligned min_brk as an empty heap */
if (min_brk & ~PAGE_MASK) {
if (brk == min_brk)
newbrk -= PAGE_SIZE;
if (mm->brk == min_brk)
oldbrk -= PAGE_SIZE;
}
if (oldbrk == newbrk) { if (oldbrk == newbrk) {
mm->brk = brk; mm->brk = brk;
goto success; goto success;