Commit 5520e894 authored by Jiri Kosina's avatar Jiri Kosina Committed by Linus Torvalds
Browse files

brk: fix min_brk lower bound computation for COMPAT_BRK

Even if CONFIG_COMPAT_BRK is set in the kernel configuration, it can still
be overriden by randomize_va_space sysctl.

If this is the case, the min_brk computation in sys_brk() implementation
is wrong, as it solely takes into account COMPAT_BRK setting, assuming
that brk start is not randomized.  But that might not be the case if
randomize_va_space sysctl has been set to '2' at the time the binary has
been loaded from disk.

In such case, the check has to be done in a same way as in

In addition to that, the check for the COMPAT_BRK case introduced back in

 ("brk: make sys_brk() honor COMPAT_BRK when computing lower
bound") is slightly wrong -- the lower bound shouldn't be mm->end_code,
but mm->end_data instead, as that's where the legacy applications expect
brk section to start (i.e.  immediately after last global variable).

[ fix comment]
Signed-off-by: default avatarJiri Kosina <>
Cc: Geert Uytterhoeven <>
Cc: Ingo Molnar <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 32d6fead
......@@ -254,7 +254,15 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
min_brk = mm->end_code;
* CONFIG_COMPAT_BRK can still be overridden by setting
* randomize_va_space to 2, which will still cause mm->start_brk
* to be arbitrarily shifted
if (mm->start_brk > PAGE_ALIGN(mm->end_data))
min_brk = mm->start_brk;
min_brk = mm->end_data;
min_brk = mm->start_brk;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment