diff options
author | Jiri Kosina <jkosina@suse.cz> | 2011-01-13 18:47:23 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-13 20:32:48 -0500 |
commit | 5520e89485252c759ee60d313e9422447659947b (patch) | |
tree | cae55e5e44e86a19af4103ec129d887004d26b5b /mm/mmap.c | |
parent | 32d6feadf4e17ea9b98071be9bbf402a74a4f818 (diff) |
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
!CONFIG_COMPAT_BRK case.
In addition to that, the check for the COMPAT_BRK case introduced back in
a5b4592c ("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).
[akpm@linux-foundation.org: fix comment]
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/mmap.c')
-rw-r--r-- | mm/mmap.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -254,7 +254,15 @@ SYSCALL_DEFINE1(brk, unsigned long, brk) | |||
254 | down_write(&mm->mmap_sem); | 254 | down_write(&mm->mmap_sem); |
255 | 255 | ||
256 | #ifdef CONFIG_COMPAT_BRK | 256 | #ifdef CONFIG_COMPAT_BRK |
257 | min_brk = mm->end_code; | 257 | /* |
258 | * CONFIG_COMPAT_BRK can still be overridden by setting | ||
259 | * randomize_va_space to 2, which will still cause mm->start_brk | ||
260 | * to be arbitrarily shifted | ||
261 | */ | ||
262 | if (mm->start_brk > PAGE_ALIGN(mm->end_data)) | ||
263 | min_brk = mm->start_brk; | ||
264 | else | ||
265 | min_brk = mm->end_data; | ||
258 | #else | 266 | #else |
259 | min_brk = mm->start_brk; | 267 | min_brk = mm->start_brk; |
260 | #endif | 268 | #endif |