Commit 07a699bc authored by Vasily Gorbik's avatar Vasily Gorbik

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: default avatarPhilipp Rudo <prudo@linux.ibm.com>
Reviewed-by: default avatarAlexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
parent 62aacabc
...@@ -42,7 +42,7 @@ static int check_prng(void) ...@@ -42,7 +42,7 @@ static int check_prng(void)
return PRNG_MODE_TDES; 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 = { struct prng_parm prng = {
/* initial parameter block for tdes mode, copied from libica */ /* initial parameter block for tdes mode, copied from libica */
...@@ -84,9 +84,10 @@ static unsigned long get_random(unsigned long limit) ...@@ -84,9 +84,10 @@ static unsigned long get_random(unsigned long limit)
(u8 *) &random, sizeof(random)); (u8 *) &random, sizeof(random));
break; break;
default: default:
random = 0; return -1;
} }
return random % limit; *value = random % limit;
return 0;
} }
unsigned long get_random_base(unsigned long safe_addr) unsigned long get_random_base(unsigned long safe_addr)
...@@ -143,8 +144,7 @@ unsigned long get_random_base(unsigned long safe_addr) ...@@ -143,8 +144,7 @@ unsigned long get_random_base(unsigned long safe_addr)
return 0; return 0;
} }
base = get_random(block_sum); if (get_random(block_sum, &base))
if (base == 0)
return 0; return 0;
if (base < safe_addr) if (base < safe_addr)
base = safe_addr; base = safe_addr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment