Skip to content

Commit

Permalink
[PATCH] x86_64: Increase the variability of the process stack on 64bi…
Browse files Browse the repository at this point in the history
…t 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: [email protected]
Signed-off-by: Andi Kleen <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Andi Kleen authored and Linus Torvalds committed Mar 25, 2006
1 parent dca99a3 commit 913bd90
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 9 additions & 4 deletions fs/binfmt_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions include/asm-x86_64/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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

0 comments on commit 913bd90

Please sign in to comment.