Commit 18d98a79 authored by Helge Deller's avatar Helge Deller

parisc: Enable KASLR

Add missing code for userspace executable address randomization, e.g.
applications compiled with the gcc -pie option.
Signed-off-by: default avatarHelge Deller <deller@gmx.de>
parent 69973b83
...@@ -7,6 +7,7 @@ config PARISC ...@@ -7,6 +7,7 @@ config PARISC
select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_GRAPH_TRACER
select HAVE_SYSCALL_TRACEPOINTS select HAVE_SYSCALL_TRACEPOINTS
select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_FRAME_POINTERS
select ARCH_HAS_ELF_RANDOMIZE
select RTC_CLASS select RTC_CLASS
select RTC_DRV_GENERIC select RTC_DRV_GENERIC
select INIT_ALL_POSSIBLE select INIT_ALL_POSSIBLE
......
...@@ -348,9 +348,10 @@ struct pt_regs; /* forward declaration... */ ...@@ -348,9 +348,10 @@ struct pt_regs; /* forward declaration... */
#define ELF_HWCAP 0 #define ELF_HWCAP 0
#define STACK_RND_MASK (is_32bit_task() ? \ /* Masks for stack and mmap randomization */
0x7ff >> (PAGE_SHIFT - 12) : \ #define BRK_RND_MASK (is_32bit_task() ? 0x07ffUL : 0x3ffffUL)
0x3ffff >> (PAGE_SHIFT - 12)) #define MMAP_RND_MASK (is_32bit_task() ? 0x1fffUL : 0x3ffffUL)
#define STACK_RND_MASK MMAP_RND_MASK
struct mm_struct; struct mm_struct;
extern unsigned long arch_randomize_brk(struct mm_struct *); extern unsigned long arch_randomize_brk(struct mm_struct *);
......
...@@ -276,11 +276,7 @@ void *dereference_function_descriptor(void *ptr) ...@@ -276,11 +276,7 @@ void *dereference_function_descriptor(void *ptr)
static inline unsigned long brk_rnd(void) static inline unsigned long brk_rnd(void)
{ {
/* 8MB for 32bit, 1GB for 64bit */ return (get_random_int() & BRK_RND_MASK) << PAGE_SHIFT;
if (is_32bit_task())
return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
else
return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
} }
unsigned long arch_randomize_brk(struct mm_struct *mm) unsigned long arch_randomize_brk(struct mm_struct *mm)
......
...@@ -225,19 +225,17 @@ static unsigned long mmap_rnd(void) ...@@ -225,19 +225,17 @@ static unsigned long mmap_rnd(void)
{ {
unsigned long rnd = 0; unsigned long rnd = 0;
/* if (current->flags & PF_RANDOMIZE)
* 8 bits of randomness in 32bit mmaps, 20 address space bits rnd = get_random_int() & MMAP_RND_MASK;
* 28 bits of randomness in 64bit mmaps, 40 address space bits
*/
if (current->flags & PF_RANDOMIZE) {
if (is_32bit_task())
rnd = get_random_int() % (1<<8);
else
rnd = get_random_int() % (1<<28);
}
return rnd << PAGE_SHIFT; return rnd << PAGE_SHIFT;
} }
unsigned long arch_mmap_rnd(void)
{
return (get_random_int() & MMAP_RND_MASK) << PAGE_SHIFT;
}
static unsigned long mmap_legacy_base(void) static unsigned long mmap_legacy_base(void)
{ {
return TASK_UNMAPPED_BASE + mmap_rnd(); return TASK_UNMAPPED_BASE + mmap_rnd();
......
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