aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Lu <zlu@tilera.com>2013-08-09 15:45:24 -0400
committerChris Metcalf <cmetcalf@tilera.com>2013-08-30 11:56:25 -0400
commitb2eca4274c1813c76291eab4859ca3e86e6fd35b (patch)
treead4e951e630cb4fa4ff5e6cf484ba9cab9e466d1
parent9b5bbf729d2db27ecb477b42c0701c1c97eb5603 (diff)
tile: support ASLR fully
With this change, tile Linux now supports address-space layout randomization for shared objects, stack, heap and vdso. Acked-by: Jiri Kosina <jkosina@suse.cz> Signed-off-by: Tony Lu <zlu@tilera.com> Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
-rw-r--r--arch/tile/include/asm/elf.h4
-rw-r--r--arch/tile/mm/mmap.c24
2 files changed, 26 insertions, 2 deletions
diff --git a/arch/tile/include/asm/elf.h b/arch/tile/include/asm/elf.h
index 31d854f1b83b..e1da88e8aa9f 100644
--- a/arch/tile/include/asm/elf.h
+++ b/arch/tile/include/asm/elf.h
@@ -137,6 +137,10 @@ do { \
137 NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_BASE); \ 137 NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_BASE); \
138} while (0) 138} while (0)
139 139
140struct mm_struct;
141extern unsigned long arch_randomize_brk(struct mm_struct *mm);
142#define arch_randomize_brk arch_randomize_brk
143
140#ifdef CONFIG_COMPAT 144#ifdef CONFIG_COMPAT
141 145
142#define COMPAT_ELF_PLATFORM "tilegx-m32" 146#define COMPAT_ELF_PLATFORM "tilegx-m32"
diff --git a/arch/tile/mm/mmap.c b/arch/tile/mm/mmap.c
index d67d91ebf63e..851a94e6ae58 100644
--- a/arch/tile/mm/mmap.c
+++ b/arch/tile/mm/mmap.c
@@ -58,16 +58,36 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
58#else 58#else
59 int is_32bit = 0; 59 int is_32bit = 0;
60#endif 60#endif
61 unsigned long random_factor = 0UL;
62
63 /*
64 * 8 bits of randomness in 32bit mmaps, 24 address space bits
65 * 12 bits of randomness in 64bit mmaps, 28 address space bits
66 */
67 if (current->flags & PF_RANDOMIZE) {
68 if (is_32bit)
69 random_factor = get_random_int() % (1<<8);
70 else
71 random_factor = get_random_int() % (1<<12);
72
73 random_factor <<= PAGE_SHIFT;
74 }
61 75
62 /* 76 /*
63 * Use standard layout if the expected stack growth is unlimited 77 * Use standard layout if the expected stack growth is unlimited
64 * or we are running native 64 bits. 78 * or we are running native 64 bits.
65 */ 79 */
66 if (!is_32bit || rlimit(RLIMIT_STACK) == RLIM_INFINITY) { 80 if (rlimit(RLIMIT_STACK) == RLIM_INFINITY) {
67 mm->mmap_base = TASK_UNMAPPED_BASE; 81 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
68 mm->get_unmapped_area = arch_get_unmapped_area; 82 mm->get_unmapped_area = arch_get_unmapped_area;
69 } else { 83 } else {
70 mm->mmap_base = mmap_base(mm); 84 mm->mmap_base = mmap_base(mm);
71 mm->get_unmapped_area = arch_get_unmapped_area_topdown; 85 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
72 } 86 }
73} 87}
88
89unsigned long arch_randomize_brk(struct mm_struct *mm)
90{
91 unsigned long range_end = mm->brk + 0x02000000;
92 return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
93}