aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fs/binfmt_elf.c13
-rw-r--r--include/asm-x86_64/elf.h4
2 files changed, 13 insertions, 4 deletions
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 4349113881f..537893a1601 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -500,17 +500,22 @@ out:
#define INTERPRETER_AOUT 1
#define INTERPRETER_ELF 2
+#ifndef STACK_RND_MASK
+#define STACK_RND_MASK 0x7ff /* with 4K pages 8MB of VA */
+#endif
static unsigned long randomize_stack_top(unsigned long stack_top)
{
unsigned int random_variable = 0;
- if (current->flags & PF_RANDOMIZE)
- random_variable = get_random_int() % (8*1024*1024);
+ if (current->flags & PF_RANDOMIZE) {
+ random_variable = get_random_int() & STACK_RND_MASK;
+ random_variable <<= PAGE_SHIFT;
+ }
#ifdef CONFIG_STACK_GROWSUP
- return PAGE_ALIGN(stack_top + random_variable);
+ return PAGE_ALIGN(stack_top) + random_variable;
#else
- return PAGE_ALIGN(stack_top - random_variable);
+ return PAGE_ALIGN(stack_top) - random_variable;
#endif
}
diff --git a/include/asm-x86_64/elf.h b/include/asm-x86_64/elf.h
index 43862cd6a56..c98633af07d 100644
--- a/include/asm-x86_64/elf.h
+++ b/include/asm-x86_64/elf.h
@@ -8,6 +8,7 @@
#include <asm/ptrace.h>
#include <asm/user.h>
#include <asm/processor.h>
+#include <asm/compat.h>
/* x86-64 relocation types */
#define R_X86_64_NONE 0 /* No reloc */
@@ -157,6 +158,9 @@ extern int dump_task_fpu (struct task_struct *, elf_fpregset_t *);
#define ELF_CORE_COPY_TASK_REGS(tsk, elf_regs) dump_task_regs(tsk, elf_regs)
#define ELF_CORE_COPY_FPREGS(tsk, elf_fpregs) dump_task_fpu(tsk, elf_fpregs)
+/* 1GB for 64bit, 8MB for 32bit */
+#define STACK_RND_MASK (is_compat_task() ? 0x7ff : 0x3fffff)
+
#endif
#endif