s390/kaslr: generalize and improve random base distribution
authorVasily Gorbik <gor@linux.ibm.com>
Tue, 21 Feb 2023 22:08:42 +0000 (23:08 +0100)
committerVasily Gorbik <gor@linux.ibm.com>
Thu, 13 Apr 2023 15:36:27 +0000 (17:36 +0200)
commit6e259bc5a15ec49693fa3d19fdd4511f7679a20d
tree26adb36a3f3907aa179194e67ff95fa3992a7d76
parent898435203c115b164b96f30be7d9c790bbb50338
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>
arch/s390/boot/boot.h
arch/s390/boot/kaslr.c
arch/s390/boot/physmem_info.c
arch/s390/boot/startup.c