Skip to content

Commit f5ed777

Browse files
martinradevsuryasaimadhu
authored andcommitted
x86/sev-es: Check required CPU features for SEV-ES
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
1 parent 39336f4 commit f5ed777

5 files changed

Lines changed: 24 additions & 6 deletions

File tree

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// SPDX-License-Identifier: GPL-2.0
2-
#ifdef CONFIG_RANDOMIZE_BASE
3-
42
#include "../cpuflags.c"
53

64
bool has_cpuflag(int flag)
@@ -9,5 +7,3 @@ bool has_cpuflag(int flag)
97

108
return test_bit(flag, cpu.flags);
119
}
12-
13-
#endif

arch/x86/boot/compressed/misc.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ void choose_random_location(unsigned long input,
8585
unsigned long *output,
8686
unsigned long output_size,
8787
unsigned long *virt_addr);
88-
/* cpuflags.c */
89-
bool has_cpuflag(int flag);
9088
#else
9189
static inline void choose_random_location(unsigned long input,
9290
unsigned long input_size,
@@ -97,6 +95,9 @@ static inline void choose_random_location(unsigned long input,
9795
}
9896
#endif
9997

98+
/* cpuflags.c */
99+
bool has_cpuflag(int flag);
100+
100101
#ifdef CONFIG_X86_64
101102
extern int set_page_decrypted(unsigned long address);
102103
extern int set_page_encrypted(unsigned long address);

arch/x86/boot/compressed/sev-es.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ void sev_es_shutdown_ghcb(void)
145145
if (!boot_ghcb)
146146
return;
147147

148+
if (!sev_es_check_cpu_features())
149+
error("SEV-ES CPU Features missing.");
150+
148151
/*
149152
* GHCB Page must be flushed from the cache and mapped encrypted again.
150153
* Otherwise the running kernel will see strange cache effects when

arch/x86/kernel/sev-es-shared.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99
* and is included directly into both code-bases.
1010
*/
1111

12+
#ifndef __BOOT_COMPRESSED
13+
#define error(v) pr_err(v)
14+
#define has_cpuflag(f) boot_cpu_has(f)
15+
#endif
16+
17+
static bool __init sev_es_check_cpu_features(void)
18+
{
19+
if (!has_cpuflag(X86_FEATURE_RDRAND)) {
20+
error("RDRAND instruction not supported - no trusted source of randomness available\n");
21+
return false;
22+
}
23+
24+
return true;
25+
}
26+
1227
static void sev_es_terminate(unsigned int reason)
1328
{
1429
u64 val = GHCB_SEV_TERMINATE;

arch/x86/kernel/sev-es.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,9 @@ void __init sev_es_init_vc_handling(void)
665665
if (!sev_es_active())
666666
return;
667667

668+
if (!sev_es_check_cpu_features())
669+
panic("SEV-ES CPU Features missing");
670+
668671
/* Enable SEV-ES special handling */
669672
static_branch_enable(&sev_es_enable_key);
670673

0 commit comments

Comments
 (0)