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

s390/kaslr: randomize amode31 base address

When the KASLR is enabled, randomize the base address of the amode31 image
within the first 2 GB, similar to the approach taken for the vmlinux
image. This makes it harder to predict the location of amode31 data
and code.

Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>

+4 -2
+4 -2
arch/s390/boot/startup.c
··· 278 278 { 279 279 unsigned long max_physmem_end; 280 280 unsigned long vmlinux_lma = 0; 281 - unsigned long amode31_lma; 281 + unsigned long amode31_lma = 0; 282 282 unsigned long asce_limit; 283 283 unsigned long safe_addr; 284 284 void *img; ··· 338 338 339 339 /* vmlinux decompression is done, shrink reserved low memory */ 340 340 physmem_reserve(RR_DECOMPRESSOR, 0, (unsigned long)_decompressor_end); 341 - amode31_lma = vmlinux.default_lma - vmlinux.amode31_size; 341 + if (kaslr_enabled()) 342 + amode31_lma = randomize_within_range(vmlinux.amode31_size, PAGE_SIZE, 0, SZ_2G); 343 + amode31_lma = amode31_lma ?: vmlinux.default_lma - vmlinux.amode31_size; 342 344 physmem_reserve(RR_AMODE31, amode31_lma, vmlinux.amode31_size); 343 345 344 346 /*