Commit d839088c authored by Anton Blanchard's avatar Anton Blanchard Committed by Benjamin Herrenschmidt

powerpc: Randomise lower bits of stack address

Randomise the lower bits of the stack address. More randomisation is good for
security but the scatter can also help with SMT threads that share an L1. A
quick test case shows this working:

int main()
{
	int sp;
	printf("%x\n", (unsigned long)&sp & 4095);
}

before:
80
80
80
80
80

after:
610
490
300
6b0
d80
Signed-off-by: default avatarAnton Blanchard <anton@samba.org>
Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
parent 2dadb987
...@@ -531,7 +531,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new, ...@@ -531,7 +531,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n)) #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
#endif #endif
#define arch_align_stack(x) (x) extern unsigned long arch_align_stack(unsigned long sp);
/* Used in very early kernel initialization. */ /* Used in very early kernel initialization. */
extern unsigned long reloc_offset(void); extern unsigned long reloc_offset(void);
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include <linux/utsname.h> #include <linux/utsname.h>
#include <linux/ftrace.h> #include <linux/ftrace.h>
#include <linux/kernel_stat.h> #include <linux/kernel_stat.h>
#include <linux/personality.h>
#include <linux/random.h>
#include <asm/pgtable.h> #include <asm/pgtable.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
...@@ -1138,3 +1140,10 @@ void thread_info_cache_init(void) ...@@ -1138,3 +1140,10 @@ void thread_info_cache_init(void)
} }
#endif /* THREAD_SHIFT < PAGE_SHIFT */ #endif /* THREAD_SHIFT < PAGE_SHIFT */
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 & ~0xf;
}
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