]> Git Repo - linux.git/commitdiff
x86/espfix: Use get_random_long() rather than archrandom
authorJason A. Donenfeld <[email protected]>
Sat, 29 Oct 2022 00:26:13 +0000 (02:26 +0200)
committerBorislav Petkov <[email protected]>
Mon, 31 Oct 2022 19:12:50 +0000 (20:12 +0100)
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 <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
arch/x86/kernel/espfix_64.c

index 9417d5aa73057588a80b390fa4a6ed759619b068..16f9814c9be02ccfb963b9581485de041427e2d2 100644 (file)
@@ -94,17 +94,7 @@ static inline unsigned long espfix_base_addr(unsigned int cpu)
 
 static void init_espfix_random(void)
 {
-       unsigned long rand;
-
-       /*
-        * This is run before the entropy pools are initialized,
-        * but this is hopefully better than nothing.
-        */
-       if (!arch_get_random_longs(&rand, 1)) {
-               /* The constant is an arbitrary large prime */
-               rand = rdtsc();
-               rand *= 0xc345c6b72fd16123UL;
-       }
+       unsigned long rand = get_random_long();
 
        slot_random = rand % ESPFIX_STACKS_PER_PAGE;
        page_random = (rand / ESPFIX_STACKS_PER_PAGE)
This page took 0.055393 seconds and 4 git commands to generate.