Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x86/x86 Check CPU support of RDRAND before calling ...



details:   https://anonhg.NetBSD.org/src/rev/42c72c2a111c
branches:  trunk
changeset: 460729:42c72c2a111c
user:      taca <taca%NetBSD.org@localhost>
date:      Fri Nov 01 15:01:27 2019 +0000

description:
Check CPU support of RDRAND before calling cpu_rng_rdrand().

cpu_earlyrng() checks CPU support of RDSEED and RDRAND before calling
cpu_rng_rdseed() and cpu_rng_rdrand().

But cpu_rng_rdseed() did not check CPU support of RDRAND and system had
crashed on such an environment.  There is no such case with real CPU but
some VM environment.

Fix kern/54655 and confirmed by msaitoh@.

Needs pullup to netbsd-9.

diffstat:

 sys/arch/x86/x86/cpu_rng.c |  11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diffs (39 lines):

diff -r 68dbfed40d9b -r 42c72c2a111c sys/arch/x86/x86/cpu_rng.c
--- a/sys/arch/x86/x86/cpu_rng.c        Fri Nov 01 14:54:07 2019 +0000
+++ b/sys/arch/x86/x86/cpu_rng.c        Fri Nov 01 15:01:27 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_rng.c,v 1.9 2018/08/22 12:07:43 maxv Exp $ */
+/* $NetBSD: cpu_rng.c,v 1.10 2019/11/01 15:01:27 taca Exp $ */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -53,6 +53,8 @@
        CPU_RNG_VIA
 } cpu_rng_mode __read_mostly = CPU_RNG_NONE;
 
+static bool has_rdrand;
+
 bool
 cpu_rng_init(void)
 {
@@ -131,7 +133,10 @@
         * to be seeded even in this case.
         */
 exhausted:
-       return cpu_rng_rdrand(out);
+       if (has_rdrand)
+               return cpu_rng_rdrand(out);
+       else
+               return 0;
 }
 
 static size_t
@@ -213,7 +218,7 @@
        int i;
 
        bool has_rdseed = (cpu_feature[5] & CPUID_SEF_RDSEED) != 0;
-       bool has_rdrand = (cpu_feature[1] & CPUID2_RDRAND) != 0;
+       has_rdrand = (cpu_feature[1] & CPUID2_RDRAND) != 0;
 
        KASSERT(sz + sizeof(uint64_t) <= SHA512_DIGEST_LENGTH);
 



Home | Main Index | Thread Index | Old Index