diff options
author | Andi Kleen <ak@suse.de> | 2006-03-25 10:29:09 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-25 12:10:52 -0500 |
commit | 913bd906019514579b3c7ec5ab9c463e89207a57 (patch) | |
tree | 8f73c66bf2b30afb2807814d97f9307af0508454 | |
parent | dca99a38bccceda9e079d4c95abefbd9028605fe (diff) |
[PATCH] x86_64: Increase the variability of the process stack on 64bit architectures
8MB is not really very random, use 1GB (or more with larger page sizes)
instead.
Also use the low bits of the random generator output now instead of
throwing them away.
Only enabled on x86-64 right now. Other architectures need to add
a suitable STACK_RND_MASK
Cc: mingo@elte.hu
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | fs/binfmt_elf.c | 13 | ||||
-rw-r--r-- | include/asm-x86_64/elf.h | 4 |
2 files changed, 13 insertions, 4 deletions
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 4349113881fb..537893a16014 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c | |||
@@ -500,17 +500,22 @@ out: | |||
500 | #define INTERPRETER_AOUT 1 | 500 | #define INTERPRETER_AOUT 1 |
501 | #define INTERPRETER_ELF 2 | 501 | #define INTERPRETER_ELF 2 |
502 | 502 | ||
503 | #ifndef STACK_RND_MASK | ||
504 | #define STACK_RND_MASK 0x7ff /* with 4K pages 8MB of VA */ | ||
505 | #endif | ||
503 | 506 | ||
504 | static unsigned long randomize_stack_top(unsigned long stack_top) | 507 | static unsigned long randomize_stack_top(unsigned long stack_top) |
505 | { | 508 | { |
506 | unsigned int random_variable = 0; | 509 | unsigned int random_variable = 0; |
507 | 510 | ||
508 | if (current->flags & PF_RANDOMIZE) | 511 | if (current->flags & PF_RANDOMIZE) { |
509 | random_variable = get_random_int() % (8*1024*1024); | 512 | random_variable = get_random_int() & STACK_RND_MASK; |
513 | random_variable <<= PAGE_SHIFT; | ||
514 | } | ||
510 | #ifdef CONFIG_STACK_GROWSUP | 515 | #ifdef CONFIG_STACK_GROWSUP |
511 | return PAGE_ALIGN(stack_top + random_variable); | 516 | return PAGE_ALIGN(stack_top) + random_variable; |
512 | #else | 517 | #else |
513 | return PAGE_ALIGN(stack_top - random_variable); | 518 | return PAGE_ALIGN(stack_top) - random_variable; |
514 | #endif | 519 | #endif |
515 | } | 520 | } |
516 | 521 | ||
diff --git a/include/asm-x86_64/elf.h b/include/asm-x86_64/elf.h index 43862cd6a569..c98633af07d2 100644 --- a/include/asm-x86_64/elf.h +++ b/include/asm-x86_64/elf.h | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <asm/ptrace.h> | 8 | #include <asm/ptrace.h> |
9 | #include <asm/user.h> | 9 | #include <asm/user.h> |
10 | #include <asm/processor.h> | 10 | #include <asm/processor.h> |
11 | #include <asm/compat.h> | ||
11 | 12 | ||
12 | /* x86-64 relocation types */ | 13 | /* x86-64 relocation types */ |
13 | #define R_X86_64_NONE 0 /* No reloc */ | 14 | #define R_X86_64_NONE 0 /* No reloc */ |
@@ -157,6 +158,9 @@ extern int dump_task_fpu (struct task_struct *, elf_fpregset_t *); | |||
157 | #define ELF_CORE_COPY_TASK_REGS(tsk, elf_regs) dump_task_regs(tsk, elf_regs) | 158 | #define ELF_CORE_COPY_TASK_REGS(tsk, elf_regs) dump_task_regs(tsk, elf_regs) |
158 | #define ELF_CORE_COPY_FPREGS(tsk, elf_fpregs) dump_task_fpu(tsk, elf_fpregs) | 159 | #define ELF_CORE_COPY_FPREGS(tsk, elf_fpregs) dump_task_fpu(tsk, elf_fpregs) |
159 | 160 | ||
161 | /* 1GB for 64bit, 8MB for 32bit */ | ||
162 | #define STACK_RND_MASK (is_compat_task() ? 0x7ff : 0x3fffff) | ||
163 | |||
160 | #endif | 164 | #endif |
161 | 165 | ||
162 | #endif | 166 | #endif |