[MIPS] User stack pointer randomisation
authorFranck Bui-Huu <fbuihuu@gmail.com>
Thu, 19 Jul 2007 12:04:21 +0000 (14:04 +0200)
committerRalf Baechle <ralf@linux-mips.org>
Fri, 20 Jul 2007 17:57:40 +0000 (18:57 +0100)
Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/kernel/process.c
include/asm-mips/system.h

index 8f4cf27c7157e634cd7b4b226410868352a81862..bd05f5a927eaac4c7983f19100353876cc34aed9 100644 (file)
@@ -25,7 +25,9 @@
 #include <linux/init.h>
 #include <linux/completion.h>
 #include <linux/kallsyms.h>
+#include <linux/random.h>
 
+#include <asm/asm.h>
 #include <asm/bootinfo.h>
 #include <asm/cpu.h>
 #include <asm/dsp.h>
@@ -460,3 +462,15 @@ unsigned long get_wchan(struct task_struct *task)
 out:
        return pc;
 }
+
+/*
+ * Don't forget that the stack pointer must be aligned on a 8 bytes
+ * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
+ */
+unsigned long arch_align_stack(unsigned long sp)
+{
+       if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
+               sp -= get_random_int() & ~PAGE_MASK;
+
+       return sp & ALMASK;
+}
index eba2e3da9abe6195143cbffc960bd290511313a6..8d0b1cd4a45e837989ced15e273b1aef9efb9db9 100644 (file)
@@ -470,6 +470,6 @@ extern int stop_a_enabled;
  */
 #define __ARCH_WANT_UNLOCKED_CTXSW
 
-#define arch_align_stack(x) (x)
+extern unsigned long arch_align_stack(unsigned long sp);
 
 #endif /* _ASM_SYSTEM_H */