]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
x86/sev-es: Check required CPU features for SEV-ES
authorMartin Radev <martin.b.radev@gmail.com>
Mon, 7 Sep 2020 13:16:13 +0000 (15:16 +0200)
committerBorislav Petkov <bp@suse.de>
Thu, 10 Sep 2020 19:49:25 +0000 (21:49 +0200)
Make sure the machine supports RDRAND, otherwise there is no trusted
source of randomness in the system.

To also check this in the pre-decompression stage, make has_cpuflag()
not depend on CONFIG_RANDOMIZE_BASE anymore.

Signed-off-by: Martin Radev <martin.b.radev@gmail.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lkml.kernel.org/r/20200907131613.12703-73-joro@8bytes.org
arch/x86/boot/compressed/cpuflags.c
arch/x86/boot/compressed/misc.h
arch/x86/boot/compressed/sev-es.c
arch/x86/kernel/sev-es-shared.c
arch/x86/kernel/sev-es.c

index 6448a8196d3298b0fb06f7a31d14dee6086f8978..0cc1323896d19124475f817f574dd6810c4307bb 100644 (file)
@@ -1,6 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
-#ifdef CONFIG_RANDOMIZE_BASE
-
 #include "../cpuflags.c"
 
 bool has_cpuflag(int flag)
@@ -9,5 +7,3 @@ bool has_cpuflag(int flag)
 
        return test_bit(flag, cpu.flags);
 }
-
-#endif
index c0e0ffeee50a7bd790ef4de157aa9bb21e60a2d7..6d31f1b4c4d1085f3bee1d7fc495d29b3409bce0 100644 (file)
@@ -85,8 +85,6 @@ void choose_random_location(unsigned long input,
                            unsigned long *output,
                            unsigned long output_size,
                            unsigned long *virt_addr);
-/* cpuflags.c */
-bool has_cpuflag(int flag);
 #else
 static inline void choose_random_location(unsigned long input,
                                          unsigned long input_size,
@@ -97,6 +95,9 @@ static inline void choose_random_location(unsigned long input,
 }
 #endif
 
+/* cpuflags.c */
+bool has_cpuflag(int flag);
+
 #ifdef CONFIG_X86_64
 extern int set_page_decrypted(unsigned long address);
 extern int set_page_encrypted(unsigned long address);
index 2a6c7c375244f3cfc46dbcdb86e975b142cd54f3..954cb2702e239f856f56c05ef693201667e2675d 100644 (file)
@@ -145,6 +145,9 @@ void sev_es_shutdown_ghcb(void)
        if (!boot_ghcb)
                return;
 
+       if (!sev_es_check_cpu_features())
+               error("SEV-ES CPU Features missing.");
+
        /*
         * GHCB Page must be flushed from the cache and mapped encrypted again.
         * Otherwise the running kernel will see strange cache effects when
index 4be8af2f9c57a3b418e4bce6346e04068850fa40..5f83ccaab877b57c88412c38d7fa8b3532249cfa 100644 (file)
@@ -9,6 +9,21 @@
  * and is included directly into both code-bases.
  */
 
+#ifndef __BOOT_COMPRESSED
+#define error(v)       pr_err(v)
+#define has_cpuflag(f) boot_cpu_has(f)
+#endif
+
+static bool __init sev_es_check_cpu_features(void)
+{
+       if (!has_cpuflag(X86_FEATURE_RDRAND)) {
+               error("RDRAND instruction not supported - no trusted source of randomness available\n");
+               return false;
+       }
+
+       return true;
+}
+
 static void sev_es_terminate(unsigned int reason)
 {
        u64 val = GHCB_SEV_TERMINATE;
index 8cac9f80bfc3ba40a7745b6343939842c11215d2..6fcfdd32769f0efae0ed61ea55a927a2dd32919a 100644 (file)
@@ -665,6 +665,9 @@ void __init sev_es_init_vc_handling(void)
        if (!sev_es_active())
                return;
 
+       if (!sev_es_check_cpu_features())
+               panic("SEV-ES CPU Features missing");
+
        /* Enable SEV-ES special handling */
        static_branch_enable(&sev_es_enable_key);