Skip to content

Commit c16b63e

Browse files
Andi KleenAndi Kleen
authored andcommitted
[PATCH] i386/x86-64: Don't randomize stack top when no randomization personality is set
Based on patch from Frank van Maarseveen <frankvm@frankvm.com>, but extended. Signed-off-by: Andi Kleen <ak@suse.de>
1 parent d5d9ca6 commit c16b63e

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

arch/i386/kernel/process.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/kallsyms.h>
3838
#include <linux/ptrace.h>
3939
#include <linux/random.h>
40+
#include <linux/personality.h>
4041

4142
#include <asm/uaccess.h>
4243
#include <asm/pgtable.h>
@@ -905,7 +906,7 @@ asmlinkage int sys_get_thread_area(struct user_desc __user *u_info)
905906

906907
unsigned long arch_align_stack(unsigned long sp)
907908
{
908-
if (randomize_va_space)
909+
if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
909910
sp -= get_random_int() % 8192;
910911
return sp & ~0xf;
911912
}

arch/x86_64/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
845845

846846
unsigned long arch_align_stack(unsigned long sp)
847847
{
848-
if (randomize_va_space)
848+
if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
849849
sp -= get_random_int() % 8192;
850850
return sp & ~0xf;
851851
}

fs/binfmt_elf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
515515
{
516516
unsigned int random_variable = 0;
517517

518-
if (current->flags & PF_RANDOMIZE) {
518+
if ((current->flags & PF_RANDOMIZE) &&
519+
!(current->personality & ADDR_NO_RANDOMIZE)) {
519520
random_variable = get_random_int() & STACK_RND_MASK;
520521
random_variable <<= PAGE_SHIFT;
521522
}

0 commit comments

Comments
 (0)