Commit bf57909f authored by Arjan van de Ven's avatar Arjan van de Ven Committed by Linus Torvalds

[PATCH] Randomisation: top-of-stack randomization

In addition to randomisation of the stack pointer within the stack, the stack
itself should be randomized too.  We need both approaches, we can only
randomize the stack itself in pagesize increments.  However randomizing large
ranges with the stackpointer runs into the situation where a huge chunk of the
stack rlimit is used by the randomisation; this is undesirable so we need to
do both.
Signed-off-by: default avatarArjan van de Ven <arjan@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 8ec0defa
......@@ -37,6 +37,7 @@
#include <linux/pagemap.h>
#include <linux/security.h>
#include <linux/syscalls.h>
#include <linux/random.h>
#include <asm/uaccess.h>
#include <asm/param.h>
......@@ -494,6 +495,19 @@ static unsigned long load_aout_interp(struct exec * interp_ex,
#define INTERPRETER_ELF 2
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);
#ifdef CONFIG_STACK_GROWSUP
return PAGE_ALIGN(stack_top + random_variable);
#else
return PAGE_ALIGN(stack_top - random_variable);
#endif
}
static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs)
{
struct file *interpreter = NULL; /* to shut gcc up */
......@@ -761,7 +775,8 @@ static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs)
change some of these later */
current->mm->rss = 0;
current->mm->free_area_cache = current->mm->mmap_base;
retval = setup_arg_pages(bprm, STACK_TOP, executable_stack);
retval = setup_arg_pages(bprm, randomize_stack_top(STACK_TOP),
executable_stack);
if (retval < 0) {
send_sig(SIGKILL, current, 0);
goto out_free_dentry;
......
......@@ -400,7 +400,7 @@ int setup_arg_pages(struct linux_binprm *bprm,
while (i < MAX_ARG_PAGES)
bprm->page[i++] = NULL;
#else
stack_base = arch_align_stack(STACK_TOP - MAX_ARG_PAGES*PAGE_SIZE);
stack_base = arch_align_stack(stack_top - MAX_ARG_PAGES*PAGE_SIZE);
stack_base = PAGE_ALIGN(stack_base);
bprm->p += stack_base;
mm->arg_start = bprm->p;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment