diff options
author | Anton Blanchard <anton@samba.org> | 2009-02-21 20:50:03 -0500 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2009-02-22 23:53:20 -0500 |
commit | d839088caec6891a5070f0b1ce61031e458533a9 (patch) | |
tree | a0489611eb3edce545f7aed98764220e195ef941 /arch/powerpc | |
parent | 2dadb987e09995b2910c419cdfe2307e66537649 (diff) |
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: Anton Blanchard <anton@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc')
-rw-r--r-- | arch/powerpc/include/asm/system.h | 2 | ||||
-rw-r--r-- | arch/powerpc/kernel/process.c | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h index 2a4be19a92c4..f612798e1c93 100644 --- a/arch/powerpc/include/asm/system.h +++ b/arch/powerpc/include/asm/system.h | |||
@@ -531,7 +531,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new, | |||
531 | #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n)) | 531 | #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n)) |
532 | #endif | 532 | #endif |
533 | 533 | ||
534 | #define arch_align_stack(x) (x) | 534 | extern unsigned long arch_align_stack(unsigned long sp); |
535 | 535 | ||
536 | /* Used in very early kernel initialization. */ | 536 | /* Used in very early kernel initialization. */ |
537 | extern unsigned long reloc_offset(void); | 537 | extern unsigned long reloc_offset(void); |
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index 8ede428e76c0..69b9d2d3cb84 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c | |||
@@ -35,6 +35,8 @@ | |||
35 | #include <linux/utsname.h> | 35 | #include <linux/utsname.h> |
36 | #include <linux/ftrace.h> | 36 | #include <linux/ftrace.h> |
37 | #include <linux/kernel_stat.h> | 37 | #include <linux/kernel_stat.h> |
38 | #include <linux/personality.h> | ||
39 | #include <linux/random.h> | ||
38 | 40 | ||
39 | #include <asm/pgtable.h> | 41 | #include <asm/pgtable.h> |
40 | #include <asm/uaccess.h> | 42 | #include <asm/uaccess.h> |
@@ -1138,3 +1140,10 @@ void thread_info_cache_init(void) | |||
1138 | } | 1140 | } |
1139 | 1141 | ||
1140 | #endif /* THREAD_SHIFT < PAGE_SHIFT */ | 1142 | #endif /* THREAD_SHIFT < PAGE_SHIFT */ |
1143 | |||
1144 | unsigned long arch_align_stack(unsigned long sp) | ||
1145 | { | ||
1146 | if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space) | ||
1147 | sp -= get_random_int() & ~PAGE_MASK; | ||
1148 | return sp & ~0xf; | ||
1149 | } | ||