From da85df9f32b4d5351cd413963c193c3fd8a1c56e Mon Sep 17 00:00:00 2001 From: Andi Kleen Date: Sat, 25 Mar 2006 16:29:09 +0100 Subject: [PATCH] --- yaml --- r: 23793 b: refs/heads/master c: 913bd906019514579b3c7ec5ab9c463e89207a57 h: refs/heads/master i: 23791: c4aeae3bdf203c0749fbb79d3b9601c538fe123b v: v3 --- [refs] | 2 +- trunk/fs/binfmt_elf.c | 13 +++++++++---- trunk/include/asm-x86_64/elf.h | 4 ++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/[refs] b/[refs] index 6d6e4197ac9a..40f23508dce5 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: dca99a38bccceda9e079d4c95abefbd9028605fe +refs/heads/master: 913bd906019514579b3c7ec5ab9c463e89207a57 diff --git a/trunk/fs/binfmt_elf.c b/trunk/fs/binfmt_elf.c index 4349113881fb..537893a16014 100644 --- a/trunk/fs/binfmt_elf.c +++ b/trunk/fs/binfmt_elf.c @@ -500,17 +500,22 @@ static unsigned long load_aout_interp(struct exec * interp_ex, #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/trunk/include/asm-x86_64/elf.h b/trunk/include/asm-x86_64/elf.h index 43862cd6a569..c98633af07d2 100644 --- a/trunk/include/asm-x86_64/elf.h +++ b/trunk/include/asm-x86_64/elf.h @@ -8,6 +8,7 @@ #include #include #include +#include /* 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