Skip to content

Commit b04d998

Browse files
committedMay 26, 2018
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>
1 parent c00c934 commit b04d998

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed
 

‎mm/mmap.c

+7
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
220220

221221
newbrk = PAGE_ALIGN(brk);
222222
oldbrk = PAGE_ALIGN(mm->brk);
223+
/* properly handle unaligned min_brk as an empty heap */
224+
if (min_brk & ~PAGE_MASK) {
225+
if (brk == min_brk)
226+
newbrk -= PAGE_SIZE;
227+
if (mm->brk == min_brk)
228+
oldbrk -= PAGE_SIZE;
229+
}
223230
if (oldbrk == newbrk)
224231
goto set_brk;
225232

0 commit comments

Comments
 (0)
Please sign in to comment.