Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

powerpc: Simplify and move arch_randomize_brk()

arch_randomize_brk() is only needed for hash on book3s/64, for other
platforms the one provided by the default mmap layout is good enough.

Move it to hash_utils.c and use randomize_page() like the generic one.

And properly opt out the radix case instead of making an assumption
on mmu_highuser_ssize.

Also change to a 32M range like most other architectures instead of 8M.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/eafa4d18ec8ac7b98dd02b40181e61643707cc7c.1649523076.git.christophe.leroy@csgroup.eu

authored by

Christophe Leroy and committed by
Michael Ellerman
3ba4289a 36e5f9ee

+19 -41
-41
arch/powerpc/kernel/process.c
··· 34 34 #include <linux/ftrace.h> 35 35 #include <linux/kernel_stat.h> 36 36 #include <linux/personality.h> 37 - #include <linux/random.h> 38 37 #include <linux/hw_breakpoint.h> 39 38 #include <linux/uaccess.h> 40 - #include <linux/elf-randomize.h> 41 39 #include <linux/pkeys.h> 42 40 #include <linux/seq_buf.h> 43 41 ··· 2311 2313 sp -= get_random_int() & ~PAGE_MASK; 2312 2314 return sp & ~0xf; 2313 2315 } 2314 - 2315 - static inline unsigned long brk_rnd(void) 2316 - { 2317 - unsigned long rnd = 0; 2318 - 2319 - /* 8MB for 32bit, 1GB for 64bit */ 2320 - if (is_32bit_task()) 2321 - rnd = (get_random_long() % (1UL<<(23-PAGE_SHIFT))); 2322 - else 2323 - rnd = (get_random_long() % (1UL<<(30-PAGE_SHIFT))); 2324 - 2325 - return rnd << PAGE_SHIFT; 2326 - } 2327 - 2328 - unsigned long arch_randomize_brk(struct mm_struct *mm) 2329 - { 2330 - unsigned long base = mm->brk; 2331 - unsigned long ret; 2332 - 2333 - #ifdef CONFIG_PPC_BOOK3S_64 2334 - /* 2335 - * If we are using 1TB segments and we are allowed to randomise 2336 - * the heap, we can put it above 1TB so it is backed by a 1TB 2337 - * segment. Otherwise the heap will be in the bottom 1TB 2338 - * which always uses 256MB segments and this may result in a 2339 - * performance penalty. 2340 - */ 2341 - if (!radix_enabled() && !is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T)) 2342 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T); 2343 - #endif 2344 - 2345 - ret = PAGE_ALIGN(base + brk_rnd()); 2346 - 2347 - if (ret < mm->brk) 2348 - return mm->brk; 2349 - 2350 - return ret; 2351 - } 2352 -
+19
arch/powerpc/mm/book3s64/hash_utils.c
··· 37 37 #include <linux/cpu.h> 38 38 #include <linux/pgtable.h> 39 39 #include <linux/debugfs.h> 40 + #include <linux/random.h> 41 + #include <linux/elf-randomize.h> 40 42 41 43 #include <asm/interrupt.h> 42 44 #include <asm/processor.h> ··· 2134 2132 2135 2133 if (htab_hash_mask) 2136 2134 pr_info("htab_hash_mask = 0x%lx\n", htab_hash_mask); 2135 + } 2136 + 2137 + unsigned long arch_randomize_brk(struct mm_struct *mm) 2138 + { 2139 + /* 2140 + * If we are using 1TB segments and we are allowed to randomise 2141 + * the heap, we can put it above 1TB so it is backed by a 1TB 2142 + * segment. Otherwise the heap will be in the bottom 1TB 2143 + * which always uses 256MB segments and this may result in a 2144 + * performance penalty. 2145 + */ 2146 + if (is_32bit_task()) 2147 + return randomize_page(mm->brk, SZ_32M); 2148 + else if (!radix_enabled() && mmu_highuser_ssize == MMU_SEGSIZE_1T) 2149 + return randomize_page(max_t(unsigned long, mm->brk, SZ_1T), SZ_1G); 2150 + else 2151 + return randomize_page(mm->brk, SZ_1G); 2137 2152 }