diff options
author | Anton Blanchard <anton@samba.org> | 2009-02-22 02:50:03 +0100 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2009-02-23 05:53:20 +0100 |
commit | d839088caec6891a5070f0b1ce61031e458533a9 (patch) | |
tree | a0489611eb3edce545f7aed98764220e195ef941 /arch/powerpc/kernel/process.c | |
parent | powerpc: More stack randomisation for 64bit binaries (diff) | |
download | linux-d839088caec6891a5070f0b1ce61031e458533a9.tar.xz linux-d839088caec6891a5070f0b1ce61031e458533a9.zip |
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/kernel/process.c')
-rw-r--r-- | arch/powerpc/kernel/process.c | 9 |
1 files changed, 9 insertions, 0 deletions
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 @@ #include <linux/utsname.h> #include <linux/ftrace.h> #include <linux/kernel_stat.h> +#include <linux/personality.h> +#include <linux/random.h> #include <asm/pgtable.h> #include <asm/uaccess.h> @@ -1138,3 +1140,10 @@ void thread_info_cache_init(void) } #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; +} |