mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 19:00:25 +00:00
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>
This commit is contained in:
parent
62aacabc13
commit
07a699bc43
1 changed files with 5 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue