Skip to content

Commit c9f0953

Browse files
joergroedelsuryasaimadhu
authored andcommitted
x86/head/64: Check SEV encryption before switching to kernel page-table
When SEV is enabled, the kernel requests the C-bit position again from the hypervisor to build its own page-table. Since the hypervisor is an untrusted source, the C-bit position needs to be verified before the kernel page-table is used. Call sev_verify_cbit() before writing the CR3. [ bp: Massage. ] Signed-off-by: Joerg Roedel <jroedel@suse.de> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Link: https://lkml.kernel.org/r/20201028164659.27002-5-joro@8bytes.org
1 parent 86ce43f commit c9f0953

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

arch/x86/kernel/head_64.S

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,21 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL)
161161

162162
/* Setup early boot stage 4-/5-level pagetables. */
163163
addq phys_base(%rip), %rax
164+
165+
/*
166+
* For SEV guests: Verify that the C-bit is correct. A malicious
167+
* hypervisor could lie about the C-bit position to perform a ROP
168+
* attack on the guest by writing to the unencrypted stack and wait for
169+
* the next RET instruction.
170+
* %rsi carries pointer to realmode data and is callee-clobbered. Save
171+
* and restore it.
172+
*/
173+
pushq %rsi
174+
movq %rax, %rdi
175+
call sev_verify_cbit
176+
popq %rsi
177+
178+
/* Switch to new page-table */
164179
movq %rax, %cr3
165180

166181
/* Ensure I am executing from virtual addresses */
@@ -279,6 +294,7 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL)
279294
SYM_CODE_END(secondary_startup_64)
280295

281296
#include "verify_cpu.S"
297+
#include "sev_verify_cbit.S"
282298

283299
#ifdef CONFIG_HOTPLUG_CPU
284300
/*

arch/x86/mm/mem_encrypt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*/
4040
u64 sme_me_mask __section(".data") = 0;
4141
u64 sev_status __section(".data") = 0;
42+
u64 sev_check_data __section(".data") = 0;
4243
EXPORT_SYMBOL(sme_me_mask);
4344
DEFINE_STATIC_KEY_FALSE(sev_enable_key);
4445
EXPORT_SYMBOL_GPL(sev_enable_key);

0 commit comments

Comments
 (0)