Skip to content

Commit 00ed1ea

Browse files
zx2c4suryasaimadhu
authored andcommitted
x86/espfix: Use get_random_long() rather than archrandom
A call is made to arch_get_random_longs() and rdtsc(), rather than just using get_random_long(), because this was written during a time when very early boot would give abysmal entropy. These days, a call to get_random_long() at early boot will incorporate RDRAND, RDTSC, and more, without having to do anything bespoke. In fact, the situation is now such that on the majority of x86 systems, the pool actually is initialized at this point, even though it doesn't need to be for get_random_long() to still return something better than what this function currently does. So simplify this to just call get_random_long() instead. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lore.kernel.org/r/20221029002613.143153-1-Jason@zx2c4.com
1 parent a545b48 commit 00ed1ea

1 file changed

Lines changed: 1 addition & 11 deletions

File tree

arch/x86/kernel/espfix_64.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,7 @@ static inline unsigned long espfix_base_addr(unsigned int cpu)
9494

9595
static void init_espfix_random(void)
9696
{
97-
unsigned long rand;
98-
99-
/*
100-
* This is run before the entropy pools are initialized,
101-
* but this is hopefully better than nothing.
102-
*/
103-
if (!arch_get_random_longs(&rand, 1)) {
104-
/* The constant is an arbitrary large prime */
105-
rand = rdtsc();
106-
rand *= 0xc345c6b72fd16123UL;
107-
}
97+
unsigned long rand = get_random_long();
10898

10999
slot_random = rand % ESPFIX_STACKS_PER_PAGE;
110100
page_random = (rand / ESPFIX_STACKS_PER_PAGE)

0 commit comments

Comments
 (0)