diff options
author | Vasily Gorbik <gor@linux.ibm.com> | 2020-09-23 09:37:43 +0200 |
---|---|---|
committer | Vasily Gorbik <gor@linux.ibm.com> | 2020-09-29 15:00:58 +0200 |
commit | 07a699bc43d1feb2abe3d47781e2db3d08554bcc (patch) | |
tree | de7a6992d382fbd0fe0d1ab2c7bfe818dd16c230 /arch/s390/boot | |
parent | s390/3215: simplify the return expression of tty3215_open() (diff) | |
download | linux-07a699bc43d1feb2abe3d47781e2db3d08554bcc.tar.xz linux-07a699bc43d1feb2abe3d47781e2db3d08554bcc.zip |
s390/kaslr: avoid mixing valid random value and an error code
0 is a valid random value. To avoid mixing it with error code 0 as an
return code make get_random() take extra argument to output random
value and return an error code.
Reviewed-by: Philipp Rudo <prudo@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Diffstat (limited to 'arch/s390/boot')
-rw-r--r-- | arch/s390/boot/kaslr.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/arch/s390/boot/kaslr.c b/arch/s390/boot/kaslr.c index d4442163ffa9..c8549a0474e1 100644 --- a/arch/s390/boot/kaslr.c +++ b/arch/s390/boot/kaslr.c @@ -42,7 +42,7 @@ static int check_prng(void) return PRNG_MODE_TDES; } -static unsigned long get_random(unsigned long limit) +static int get_random(unsigned long limit, unsigned long *value) { struct prng_parm prng = { /* initial parameter block for tdes mode, copied from libica */ @@ -84,9 +84,10 @@ static unsigned long get_random(unsigned long limit) (u8 *) &random, sizeof(random)); break; default: - random = 0; + return -1; } - return random % limit; + *value = random % limit; + return 0; } unsigned long get_random_base(unsigned long safe_addr) @@ -143,8 +144,7 @@ unsigned long get_random_base(unsigned long safe_addr) return 0; } - base = get_random(block_sum); - if (base == 0) + if (get_random(block_sum, &base)) return 0; if (base < safe_addr) base = safe_addr; |