diff options
Diffstat (limited to 'arch')
-rw-r--r-- | arch/mips/include/asm/elf.h | 5 | ||||
-rw-r--r-- | arch/mips/kernel/syscall.c | 28 |
2 files changed, 33 insertions, 0 deletions
diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h index ea77a42c5f8c..fd1d39eb7431 100644 --- a/arch/mips/include/asm/elf.h +++ b/arch/mips/include/asm/elf.h | |||
@@ -372,4 +372,9 @@ extern const char *__elf_platform; | |||
372 | struct linux_binprm; | 372 | struct linux_binprm; |
373 | extern int arch_setup_additional_pages(struct linux_binprm *bprm, | 373 | extern int arch_setup_additional_pages(struct linux_binprm *bprm, |
374 | int uses_interp); | 374 | int uses_interp); |
375 | |||
376 | struct mm_struct; | ||
377 | extern unsigned long arch_randomize_brk(struct mm_struct *mm); | ||
378 | #define arch_randomize_brk arch_randomize_brk | ||
379 | |||
375 | #endif /* _ASM_ELF_H */ | 380 | #endif /* _ASM_ELF_H */ |
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 | ||
157 | static 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 | |||
171 | unsigned 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 | |||
156 | SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len, | 184 | SYSCALL_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) |