Skip to contentSkip to conversation

random: remove "nordrand" flag in favor of "random.trust_cpu"

PATCH Superseded Jason A. Donenfeld 3 participants 6 messages Jul 7, 2022 – Jul 17, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 random: remove "nordrand" flag in favor of "random.trust_cpu"

The decision of whether or not to trust RDRAND is controlled by the "random.trust_cpu" boot time parameter or the CONFIG_RANDOM_TRUST_CPU compile time default. The "nordrand" flag was added during the early days of RDRAND, when there were worries that merely using its values could compromise the RNG. However, these days, RDRAND values are not used directly but always go through the RNG's hash function, making "nordrand" no longer useful.

Rather, the correct switch is "random.trust_cpu", which not only handles the relevant trust issue directly, but also is general to multiple CPU types, not just x86.

However, x86 RDRAND does have a history of being occassionally problematic. Prior, when the kernel would notice something strange, it'd warn in dmesg and suggest enabling "nordrand". We can improve on that by making the test a little bit better and then taking the step of automatically disabling "nordrand" if we detect it's problematic.

Also extend the basic sanity test to RDSEED in addition to RDRAND, and disable both if either one fails.

---
This patch builds on top of v4 of "random: remove CONFIG_ARCH_RANDOM":
https://lore.kernel.org/lkml/[email protected]/

 .../admin-guide/kernel-parameters.txt         |  5 --
 arch/x86/kernel/cpu/amd.c                     |  2 +-
 arch/x86/kernel/cpu/rdrand.c                  | 73 +++++++++----------
 3 files changed, 36 insertions(+), 44 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +0 -5
index 2522b11e593f..a1dc4dbf74f6 100644
@@ -3733,11 +3733,6 @@
 	noreplace-smp	[X86-32,SMP] Don't replace SMP instructions
 			with UP alternatives
 
-	nordrand	[X86] Disable kernel use of the RDRAND and
-			RDSEED instructions even if they are supported
-			by the processor.  RDRAND and RDSEED are still
-			available to user space applications.
-
 	noresume	[SWSUSP] Disables resume and restores original swap
 			space.
 
arch/x86/kernel/cpu/amd.c +1 -1
index 0c0b09796ced..216fc2f53cbe 100644
@@ -808,7 +808,7 @@ static void clear_rdrand_cpuid_bit(struct cpuinfo_x86 *c)
 		return;
 
 	/*
-	 * The nordrand option can clear X86_FEATURE_RDRAND, so check for
+	 * The self test can clear X86_FEATURE_RDRAND, so check for
 	 * RDRAND support using the CPUID function directly.
 	 */
 	if (!(cpuid_ecx(1) & BIT(30)) || rdrand_force)
arch/x86/kernel/cpu/rdrand.c +35 -38

89 lines not on this page · raw message

Signature · 1 line
2.35.1
reviewer
#1 lore raw

Hi Jason,

Quoted 8 lines · Jason A. Donenfeld

The decision of whether or not to trust RDRAND is controlled by the "random.trust_cpu" boot time parameter or the CONFIG_RANDOM_TRUST_CPU compile time default. The "nordrand" flag was added during the early days of RDRAND, when there were worries that merely using its values could compromise the RNG. However, these days, RDRAND values are not used directly but always go through the RNG's hash function, making "nordrand" no longer useful.

Quoted 5 lines

Rather, the correct switch is "random.trust_cpu", which not only handles the relevant trust issue directly, but also is general to multiple CPU types, not just x86.

However, x86 RDRAND does have a history of being occassionally

occasionally

Quoted 4 lines

problematic. Prior, when the kernel would notice something strange, it'd warn in dmesg and suggest enabling "nordrand". We can improve on that by making the test a little bit better and then taking the step of automatically disabling "nordrand" if we detect it's problematic.

enabling
? I.e., disabling RDRAND and RDSEED.

Quoted 23 lines

Also extend the basic sanity test to RDSEED in addition to RDRAND, and disable both if either one fails.

---
This patch builds on top of v4 of "random: remove CONFIG_ARCH_RANDOM":
https://lore.kernel.org/lkml/[email protected]/

 .../admin-guide/kernel-parameters.txt         |  5 --
 arch/x86/kernel/cpu/amd.c                     |  2 +-
 arch/x86/kernel/cpu/rdrand.c                  | 73 +++++++++----------
 3 files changed, 36 insertions(+), 44 deletions(-)
arch/x86/kernel/cpu/amd.c +0 -0
index 0c0b09796ced..216fc2f53cbe 100644

arch/x86/kernel/cpu/amd.c static void clear_rdrand_cpuid_bit(struct cpuinfo_x86 *c) · line 811

Quoted 5 lines
arch/x86/kernel/cpu/amd.c +1 -1
@@ -808,7 +808,7 @@ static void clear_rdrand_cpuid_bit(struct cpuinfo_x86 *c)
 		return;
 
 	/*
-	 * The nordrand option can clear X86_FEATURE_RDRAND, so check for
+	 * The self test can clear X86_FEATURE_RDRAND, so check for

Preferably: self-test

Quoted 3 lines
arch/x86/kernel/cpu/amd.c +0 -0
 	 * RDRAND support using the CPUID function directly.
 	 */
 	if (!(cpuid_ecx(1) & BIT(30)) || rdrand_force)
Signature · 1 line
~Randy
#2 lore raw

Hi Randy,

Quoted 10 lines · Randy Dunlap
Quoted 1 line

However, x86 RDRAND does have a history of being occassionally

occasionally

Quoted 1 line

automatically disabling "nordrand" if we detect it's problematic.

? I.e., disabling RDRAND and RDSEED.

arch/x86/kernel/cpu/amd.c static void clear_rdrand_cpuid_bit(struct cpuinfo_x86 *c) · line 811

Quoted 2 lines
arch/x86/kernel/cpu/amd.c +1 -1
-      * The nordrand option can clear X86_FEATURE_RDRAND, so check for
+      * The self test can clear X86_FEATURE_RDRAND, so check for

Preferably: self-test

Thanks. Fixing all of those.

Jason

#3 lore raw

PATCH v2 1/1 x86/rdrand: Remove "nordrand" flag in favor of "random.trust_cpu"

The decision of whether or not to trust RDRAND is controlled by the "random.trust_cpu" boot time parameter or the CONFIG_RANDOM_TRUST_CPU compile time default. The "nordrand" flag was added during the early days of RDRAND, when there were worries that merely using its values could compromise the RNG. However, these days, RDRAND values are not used directly but always go through the RNG's hash function, making "nordrand" no longer useful.

Rather, the correct switch is "random.trust_cpu", which not only handles the relevant trust issue directly, but also is general to multiple CPU types, not just x86.

However, x86 RDRAND does have a history of being occasionally problematic. Prior, when the kernel would notice something strange, it'd warn in dmesg and suggest enabling "nordrand". We can improve on that by making the test a little bit better and then taking the step of automatically disabling RDRAND if we detect it's problematic.

Also extend the basic sanity test to RDSEED in addition to RDRAND, and disable both if either one fails.

---
This is a tip-ish commit, but it relies on the CONFIG_ARCH_RANDOM commit in the random tree, so I'll take this through the random tree to avoid conflicts.

Changes v1->v2:
- [Borislav] Reformat into tip-style commit to be taken through random tree.
- [Randy] Fix typos.

 .../admin-guide/kernel-parameters.txt         |  5 --
 arch/x86/kernel/cpu/amd.c                     |  2 +-
 arch/x86/kernel/cpu/rdrand.c                  | 73 +++++++++----------
 3 files changed, 36 insertions(+), 44 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +0 -5
index 2522b11e593f..a1dc4dbf74f6 100644
@@ -3733,11 +3733,6 @@
 	noreplace-smp	[X86-32,SMP] Don't replace SMP instructions
 			with UP alternatives
 
-	nordrand	[X86] Disable kernel use of the RDRAND and
-			RDSEED instructions even if they are supported
-			by the processor.  RDRAND and RDSEED are still
-			available to user space applications.
-
 	noresume	[SWSUSP] Disables resume and restores original swap
 			space.
 
arch/x86/kernel/cpu/amd.c +1 -1
index 0c0b09796ced..8baf312e030a 100644
@@ -808,7 +808,7 @@ static void clear_rdrand_cpuid_bit(struct cpuinfo_x86 *c)
 		return;
 
 	/*
-	 * The nordrand option can clear X86_FEATURE_RDRAND, so check for
+	 * The self-test can clear X86_FEATURE_RDRAND, so check for
 	 * RDRAND support using the CPUID function directly.
 	 */
 	if (!(cpuid_ecx(1) & BIT(30)) || rdrand_force)
arch/x86/kernel/cpu/rdrand.c +35 -38

89 lines not on this page · raw message

Signature · 1 line
2.35.1
Acked-by on v2 1/1
#4 lore raw

Re: [PATCH random v2] x86/rdrand: Remove "nordrand" flag in favor of "random.trust_cpu"

Quoted 26 lines · Jason A. Donenfeld

The decision of whether or not to trust RDRAND is controlled by the "random.trust_cpu" boot time parameter or the CONFIG_RANDOM_TRUST_CPU compile time default. The "nordrand" flag was added during the early days of RDRAND, when there were worries that merely using its values could compromise the RNG. However, these days, RDRAND values are not used directly but always go through the RNG's hash function, making "nordrand" no longer useful.

Rather, the correct switch is "random.trust_cpu", which not only handles the relevant trust issue directly, but also is general to multiple CPU types, not just x86.

However, x86 RDRAND does have a history of being occasionally problematic. Prior, when the kernel would notice something strange, it'd warn in dmesg and suggest enabling "nordrand". We can improve on that by making the test a little bit better and then taking the step of automatically disabling RDRAND if we detect it's problematic.

Also extend the basic sanity test to RDSEED in addition to RDRAND, and disable both if either one fails.

Quoted 4 lines

---
This is a tip-ish commit, but it relies on the CONFIG_ARCH_RANDOM commit in the random tree, so I'll take this through the random tree to avoid conflicts.

Signature · 6 lines
Regards/Gruss,
    Boris.

SUSE Software Solutions Germany GmbH
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Martje Boudien Moerman
(HRB 36809, AG Nürnberg)
#5 lore raw

PATCH v3 1/1 x86/rdrand: Remove "nordrand" flag in favor of "random.trust_cpu"

In reply to Jason A. Donenfeld

The decision of whether or not to trust RDRAND is controlled by the "random.trust_cpu" boot time parameter or the CONFIG_RANDOM_TRUST_CPU compile time default. The "nordrand" flag was added during the early days of RDRAND, when there were worries that merely using its values could compromise the RNG. However, these days, RDRAND values are not used directly but always go through the RNG's hash function, making "nordrand" no longer useful.

Rather, the correct switch is "random.trust_cpu", which not only handles the relevant trust issue directly, but also is general to multiple CPU types, not just x86.

However, x86 RDRAND does have a history of being occasionally problematic. Prior, when the kernel would notice something strange, it'd warn in dmesg and suggest enabling "nordrand". We can improve on that by making the test a little bit better and then taking the step of automatically disabling RDRAND if we detect it's problematic.

Also disable RDSEED if the RDRAND test fails.

---
Changes v2->v3:
- We can't call rdseed in a loop like we can rdrand because it's meant to fail (return false) more often.

 .../admin-guide/kernel-parameters.txt         |  5 --
 arch/x86/kernel/cpu/amd.c                     |  2 +-
 arch/x86/kernel/cpu/rdrand.c                  | 57 +++++++------------
 3 files changed, 22 insertions(+), 42 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +0 -5
index f2d26cb7e853..1e2307f11105 100644
@@ -3733,11 +3733,6 @@
 	noreplace-smp	[X86-32,SMP] Don't replace SMP instructions
 			with UP alternatives
 
-	nordrand	[X86] Disable kernel use of the RDRAND and
-			RDSEED instructions even if they are supported
-			by the processor.  RDRAND and RDSEED are still
-			available to user space applications.
-
 	noresume	[SWSUSP] Disables resume and restores original swap
 			space.
 
arch/x86/kernel/cpu/amd.c +1 -1
index 35d5288394cb..48276c0e479d 100644
@@ -808,7 +808,7 @@ static void clear_rdrand_cpuid_bit(struct cpuinfo_x86 *c)
 		return;
 
 	/*
-	 * The nordrand option can clear X86_FEATURE_RDRAND, so check for
+	 * The self-test can clear X86_FEATURE_RDRAND, so check for
 	 * RDRAND support using the CPUID function directly.
 	 */
 	if (!(cpuid_ecx(1) & BIT(30)) || rdrand_force)
arch/x86/kernel/cpu/rdrand.c +21 -36

75 lines not on this page · raw message

Signature · 1 line
2.35.1