summaryrefslogtreecommitdiff
path: root/arch/s390/boot/startup.c
diff options
context:
space:
mode:
authorVasily Gorbik <gor@linux.ibm.com>2023-02-21 23:08:42 +0100
committerVasily Gorbik <gor@linux.ibm.com>2023-04-13 17:36:27 +0200
commit6e259bc5a15ec49693fa3d19fdd4511f7679a20d (patch)
tree26adb36a3f3907aa179194e67ff95fa3992a7d76 /arch/s390/boot/startup.c
parent898435203c115b164b96f30be7d9c790bbb50338 (diff)
s390/kaslr: generalize and improve random base distribution
Improve the distribution algorithm of random base address to ensure a uniformity among all suitable addresses. To generate a random value once, and to build a continuous range in which every value is suitable, count all the suitable addresses (referred to as positions) that can be used as a base address. The positions are counted by iterating over the usable memory ranges. For each range that is big enough to accommodate the image, count all the suitable addresses where the image can be placed, while taking reserved memory ranges into consideration. A new function "iterate_valid_positions()" has dual purpose. Firstly, it is called to count the positions in a given memory range, and secondly, to convert a random position back to an address. "get_random_base()" has been replaced with more generic "randomize_within_range()" which now could be called for randomizing base addresses not just for the kernel image. Acked-by: Alexander Gordeev <agordeev@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Diffstat (limited to 'arch/s390/boot/startup.c')
-rw-r--r--arch/s390/boot/startup.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/arch/s390/boot/startup.c b/arch/s390/boot/startup.c
index 45c30c2b1a7a..638a6cf8a075 100644
--- a/arch/s390/boot/startup.c
+++ b/arch/s390/boot/startup.c
@@ -316,7 +316,9 @@ void startup_kernel(void)
rescue_initrd(safe_addr, ident_map_size);
if (kaslr_enabled()) {
- vmlinux_lma = get_random_base();
+ vmlinux_lma = randomize_within_range(vmlinux.image_size + vmlinux.bss_size,
+ THREAD_SIZE, vmlinux.default_lma,
+ ident_map_size);
if (vmlinux_lma) {
__kaslr_offset = vmlinux_lma - vmlinux.default_lma;
offset_vmlinux_info(__kaslr_offset);