Skip to contentSkip to conversation

x86/espfix: Use get_random_long() rather than archrandom

PATCH Applied Jason A. Donenfeld 2 participants 2 messages Oct 29, 2022 – Oct 31, 2022 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc H. Peter Anvin <[email protected]>
---
 arch/x86/kernel/espfix_64.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
arch/x86/kernel/espfix_64.c +1 -11
index 9417d5aa7305..16f9814c9be0 100644
@@ -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)
Signature · 1 line
2.38.1
#1 lore raw
The following commit has been merged into the x86/misc branch of tip:

The following commit has been merged into the x86/misc branch of tip:

Commit-ID:     00ed1eabcc3b785aecf6f6cbb41d7b436bb54d28
Gitweb:        https://git.kernel.org/tip/00ed1eabcc3b785aecf6f6cbb41d7b436bb54d28
Author:        Jason A. Donenfeld <[email protected]>
AuthorDate:    Sat, 29 Oct 2022 02:26:13 +02:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Mon, 31 Oct 2022 20:12:50 +01:00

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.

---
 arch/x86/kernel/espfix_64.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
arch/x86/kernel/espfix_64.c +1 -11
index 9417d5a..16f9814 100644
@@ -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)