aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/kernel/syscall.c
diff options
context:
space:
mode:
authorDavid Daney <ddaney@caviumnetworks.com>2010-07-19 16:14:57 -0400
committerRalf Baechle <ralf@linux-mips.org>2010-08-05 08:26:06 -0400
commit652b14aa84961fa391184ccbaf559a537d33b28c (patch)
tree748ba20efa1094728a85fe4d59d01ccbd6e1bfad /arch/mips/kernel/syscall.c
parent1091458d09e1a0788268578001f279250d2c0844 (diff)
MIPS: Enable heap randomization.
Based somewhat on the PPC implementation. 32-bit processes have the heap randomized in an 8MB space, 256MB for 64-bit processes. Signed-off-by: David Daney <ddaney@caviumnetworks.com> To: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/1479/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/kernel/syscall.c')
-rw-r--r--arch/mips/kernel/syscall.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c
index 9824a829f61d..58bab2ef257f 100644
--- a/arch/mips/kernel/syscall.c
+++ b/arch/mips/kernel/syscall.c
@@ -30,6 +30,7 @@
30#include <linux/uaccess.h> 30#include <linux/uaccess.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/random.h> 32#include <linux/random.h>
33#include <linux/elf.h>
33 34
34#include <asm/asm.h> 35#include <asm/asm.h>
35#include <asm/branch.h> 36#include <asm/branch.h>
@@ -153,6 +154,33 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
153 mm->unmap_area = arch_unmap_area; 154 mm->unmap_area = arch_unmap_area;
154} 155}
155 156
157static inline unsigned long brk_rnd(void)
158{
159 unsigned long rnd = get_random_int();
160
161 rnd = rnd << PAGE_SHIFT;
162 /* 8MB for 32bit, 256MB for 64bit */
163 if (TASK_IS_32BIT_ADDR)
164 rnd = rnd & 0x7ffffful;
165 else
166 rnd = rnd & 0xffffffful;
167
168 return rnd;
169}
170
171unsigned long arch_randomize_brk(struct mm_struct *mm)
172{
173 unsigned long base = mm->brk;
174 unsigned long ret;
175
176 ret = PAGE_ALIGN(base + brk_rnd());
177
178 if (ret < mm->brk)
179 return mm->brk;
180
181 return ret;
182}
183
156SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len, 184SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
157 unsigned long, prot, unsigned long, flags, unsigned long, 185 unsigned long, prot, unsigned long, flags, unsigned long,
158 fd, off_t, offset) 186 fd, off_t, offset)