Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

parisc: Enable KASLR

Add missing code for userspace executable address randomization, e.g.
applications compiled with the gcc -pie option.

Signed-off-by: Helge Deller <deller@gmx.de>

+14 -18
+1
arch/parisc/Kconfig
··· 7 7 select HAVE_FUNCTION_GRAPH_TRACER 8 8 select HAVE_SYSCALL_TRACEPOINTS 9 9 select ARCH_WANT_FRAME_POINTERS 10 + select ARCH_HAS_ELF_RANDOMIZE 10 11 select RTC_CLASS 11 12 select RTC_DRV_GENERIC 12 13 select INIT_ALL_POSSIBLE
+4 -3
arch/parisc/include/asm/elf.h
··· 348 348 349 349 #define ELF_HWCAP 0 350 350 351 - #define STACK_RND_MASK (is_32bit_task() ? \ 352 - 0x7ff >> (PAGE_SHIFT - 12) : \ 353 - 0x3ffff >> (PAGE_SHIFT - 12)) 351 + /* Masks for stack and mmap randomization */ 352 + #define BRK_RND_MASK (is_32bit_task() ? 0x07ffUL : 0x3ffffUL) 353 + #define MMAP_RND_MASK (is_32bit_task() ? 0x1fffUL : 0x3ffffUL) 354 + #define STACK_RND_MASK MMAP_RND_MASK 354 355 355 356 struct mm_struct; 356 357 extern unsigned long arch_randomize_brk(struct mm_struct *);
+1 -5
arch/parisc/kernel/process.c
··· 276 276 277 277 static inline unsigned long brk_rnd(void) 278 278 { 279 - /* 8MB for 32bit, 1GB for 64bit */ 280 - if (is_32bit_task()) 281 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT; 282 - else 283 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT; 279 + return (get_random_int() & BRK_RND_MASK) << PAGE_SHIFT; 284 280 } 285 281 286 282 unsigned long arch_randomize_brk(struct mm_struct *mm)
+8 -10
arch/parisc/kernel/sys_parisc.c
··· 225 225 { 226 226 unsigned long rnd = 0; 227 227 228 - /* 229 - * 8 bits of randomness in 32bit mmaps, 20 address space bits 230 - * 28 bits of randomness in 64bit mmaps, 40 address space bits 231 - */ 232 - if (current->flags & PF_RANDOMIZE) { 233 - if (is_32bit_task()) 234 - rnd = get_random_int() % (1<<8); 235 - else 236 - rnd = get_random_int() % (1<<28); 237 - } 228 + if (current->flags & PF_RANDOMIZE) 229 + rnd = get_random_int() & MMAP_RND_MASK; 230 + 238 231 return rnd << PAGE_SHIFT; 232 + } 233 + 234 + unsigned long arch_mmap_rnd(void) 235 + { 236 + return (get_random_int() & MMAP_RND_MASK) << PAGE_SHIFT; 239 237 } 240 238 241 239 static unsigned long mmap_legacy_base(void)