Re: [GIT pull] x86/urgent for 5.3-rc5

From: Borislav Petkov
Date: Sun Aug 25 2019 - 16:20:34 EST


On Sun, Aug 25, 2019 at 12:59:25PM -0700, Linus Torvalds wrote:
> I think WARN_ONCE() is good. It's big enough that it will show up in
> dmesg if anybody looks, and if nobody looks I think distros still have
> logging for things like that, don't they?

Probably. Lemme research that.

> Hopefully this never actually triggers in practice, thanks to rdrand
> being turned off on known-bad machines now, and Zen 2 being fixed.

Right. Here's v2, will do a proper patch tomorrow:

---
diff --git a/arch/x86/kernel/cpu/rdrand.c b/arch/x86/kernel/cpu/rdrand.c
index 5c900f9527ff..00a9d13c0a92 100644
--- a/arch/x86/kernel/cpu/rdrand.c
+++ b/arch/x86/kernel/cpu/rdrand.c
@@ -29,7 +29,8 @@ __setup("nordrand", x86_rdrand_setup);
#ifdef CONFIG_ARCH_RANDOM
void x86_init_rdrand(struct cpuinfo_x86 *c)
{
- unsigned long tmp;
+ unsigned int changed = 0;
+ unsigned long tmp, prev;
int i;

if (!cpu_has(c, X86_FEATURE_RDRAND))
@@ -42,5 +43,24 @@ void x86_init_rdrand(struct cpuinfo_x86 *c)
return;
}
}
+
+ /*
+ * Stupid sanity-check whether RDRAND does *actually* generate
+ * some at least random-looking data.
+ */
+ prev = tmp;
+ for (i = 0; i < SANITY_CHECK_LOOPS; i++) {
+ if (rdrand_long(&tmp)) {
+ if (prev != tmp)
+ changed++;
+
+ prev = tmp;
+ }
+ }
+
+ if (!changed)
+ WARN_ONCE(1,
+"RDRAND gives funky smelling output, might consider not using it by booting with \"nordrand\"");
+
}
#endif


--
Regards/Gruss,
Boris.

SUSE Software Solutions Germany GmbH, GF: Felix ImendÃrffer, HRB 247165, AG MÃnchen