Skip to contentSkip to conversation

i386/x86-64: Don't randomize stack top when no randomization personality is set

PATCH In review Andi Kleen 2 participants 2 messages Jul 24, 2006

Subsystems (2)
lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/7 i386/x86-64: Don't randomize stack top when no randomization personality is set

Based on patch from Frank van Maarseveen <[email protected]>, but extended.

---
 arch/i386/kernel/process.c   |    3 ++-
 arch/x86_64/kernel/process.c |    2 +-
 fs/binfmt_elf.c              |    3 ++-
 3 files changed, 5 insertions(+), 3 deletions(-)
arch/x86_64/kernel/process.c +1 -1
Index: linux/arch/x86_64/kernel/process.c
===================================================================
@@ -845,7 +845,7 @@ int dump_task_regs(struct task_struct *t
 
 unsigned long arch_align_stack(unsigned long sp)
 {
-	if (randomize_va_space)
+	if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
 		sp -= get_random_int() % 8192;
 	return sp & ~0xf;
 }
arch/i386/kernel/process.c +2 -1
Index: linux/arch/i386/kernel/process.c
===================================================================
@@ -37,6 +37,7 @@
 #include <linux/kallsyms.h>
 #include <linux/ptrace.h>
 #include <linux/random.h>
+#include <linux/personality.h>
 
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
@@ -905,7 +906,7 @@ asmlinkage int sys_get_thread_area(struc
 
 unsigned long arch_align_stack(unsigned long sp)
 {
-	if (randomize_va_space)
+	if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
 		sp -= get_random_int() % 8192;
 	return sp & ~0xf;
 }
fs/binfmt_elf.c +2 -1
Index: linux/fs/binfmt_elf.c
===================================================================
@@ -515,7 +515,8 @@ static unsigned long randomize_stack_top
 {
 	unsigned int random_variable = 0;
 
-	if (current->flags & PF_RANDOMIZE) {
+	if ((current->flags & PF_RANDOMIZE) &&
+		!(current->personality & ADDR_NO_RANDOMIZE)) {
 		random_variable = get_random_int() & STACK_RND_MASK;
 		random_variable <<= PAGE_SHIFT;
 	}
#1 lore raw

fs/binfmt_elf.c static unsigned long randomize_stack_top · line 519

Quoted 5 lines
fs/binfmt_elf.c +2 -1
-	if (current->flags & PF_RANDOMIZE) {
+	if ((current->flags & PF_RANDOMIZE) &&
+		!(current->personality & ADDR_NO_RANDOMIZE)) {

these should be exclusive anyway, isn't the right solution to clear PF_RANDOMIZE on ADDR_NO_RANDOMIZE personality ?