Commit b2eca427 authored by Tony Lu's avatar Tony Lu Committed by Chris Metcalf

tile: support ASLR fully

With this change, tile Linux now supports address-space layout
randomization for shared objects, stack, heap and vdso.
Acked-by: default avatarJiri Kosina <jkosina@suse.cz>
Signed-off-by: default avatarTony Lu <zlu@tilera.com>
Signed-off-by: default avatarChris Metcalf <cmetcalf@tilera.com>
parent 9b5bbf72
...@@ -137,6 +137,10 @@ do { \ ...@@ -137,6 +137,10 @@ do { \
NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_BASE); \ NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_BASE); \
} while (0) } while (0)
struct mm_struct;
extern unsigned long arch_randomize_brk(struct mm_struct *mm);
#define arch_randomize_brk arch_randomize_brk
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
#define COMPAT_ELF_PLATFORM "tilegx-m32" #define COMPAT_ELF_PLATFORM "tilegx-m32"
......
...@@ -58,16 +58,36 @@ void arch_pick_mmap_layout(struct mm_struct *mm) ...@@ -58,16 +58,36 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
#else #else
int is_32bit = 0; int is_32bit = 0;
#endif #endif
unsigned long random_factor = 0UL;
/*
* 8 bits of randomness in 32bit mmaps, 24 address space bits
* 12 bits of randomness in 64bit mmaps, 28 address space bits
*/
if (current->flags & PF_RANDOMIZE) {
if (is_32bit)
random_factor = get_random_int() % (1<<8);
else
random_factor = get_random_int() % (1<<12);
random_factor <<= PAGE_SHIFT;
}
/* /*
* Use standard layout if the expected stack growth is unlimited * Use standard layout if the expected stack growth is unlimited
* or we are running native 64 bits. * or we are running native 64 bits.
*/ */
if (!is_32bit || rlimit(RLIMIT_STACK) == RLIM_INFINITY) { if (rlimit(RLIMIT_STACK) == RLIM_INFINITY) {
mm->mmap_base = TASK_UNMAPPED_BASE; mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
mm->get_unmapped_area = arch_get_unmapped_area; mm->get_unmapped_area = arch_get_unmapped_area;
} else { } else {
mm->mmap_base = mmap_base(mm); mm->mmap_base = mmap_base(mm);
mm->get_unmapped_area = arch_get_unmapped_area_topdown; mm->get_unmapped_area = arch_get_unmapped_area_topdown;
} }
} }
unsigned long arch_randomize_brk(struct mm_struct *mm)
{
unsigned long range_end = mm->brk + 0x02000000;
return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
}
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