Skip to content

Commit 2411cd8

Browse files
joergroedelsuryasaimadhu
authored andcommitted
x86/sev-es: Do not support MMIO to/from encrypted memory
MMIO memory is usually not mapped encrypted, so there is no reason to support emulated MMIO when it is mapped encrypted. Prevent a possible hypervisor attack where a RAM page is mapped as an MMIO page in the nested page-table, so that any guest access to it will trigger a #VC exception and leak the data on that page to the hypervisor via the GHCB (like with valid MMIO). On the read side this attack would allow the HV to inject data into the guest. 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-6-joro@8bytes.org
1 parent c9f0953 commit 2411cd8

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

arch/x86/kernel/sev-es.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ static enum es_result vc_read_mem(struct es_em_ctxt *ctxt,
374374
return ES_EXCEPTION;
375375
}
376376

377-
static bool vc_slow_virt_to_phys(struct ghcb *ghcb, struct es_em_ctxt *ctxt,
378-
unsigned long vaddr, phys_addr_t *paddr)
377+
static enum es_result vc_slow_virt_to_phys(struct ghcb *ghcb, struct es_em_ctxt *ctxt,
378+
unsigned long vaddr, phys_addr_t *paddr)
379379
{
380380
unsigned long va = (unsigned long)vaddr;
381381
unsigned int level;
@@ -394,15 +394,19 @@ static bool vc_slow_virt_to_phys(struct ghcb *ghcb, struct es_em_ctxt *ctxt,
394394
if (user_mode(ctxt->regs))
395395
ctxt->fi.error_code |= X86_PF_USER;
396396

397-
return false;
397+
return ES_EXCEPTION;
398398
}
399399

400+
if (WARN_ON_ONCE(pte_val(*pte) & _PAGE_ENC))
401+
/* Emulated MMIO to/from encrypted memory not supported */
402+
return ES_UNSUPPORTED;
403+
400404
pa = (phys_addr_t)pte_pfn(*pte) << PAGE_SHIFT;
401405
pa |= va & ~page_level_mask(level);
402406

403407
*paddr = pa;
404408

405-
return true;
409+
return ES_OK;
406410
}
407411

408412
/* Include code shared with pre-decompression boot stage */
@@ -731,6 +735,7 @@ static enum es_result vc_do_mmio(struct ghcb *ghcb, struct es_em_ctxt *ctxt,
731735
{
732736
u64 exit_code, exit_info_1, exit_info_2;
733737
unsigned long ghcb_pa = __pa(ghcb);
738+
enum es_result res;
734739
phys_addr_t paddr;
735740
void __user *ref;
736741

@@ -740,11 +745,12 @@ static enum es_result vc_do_mmio(struct ghcb *ghcb, struct es_em_ctxt *ctxt,
740745

741746
exit_code = read ? SVM_VMGEXIT_MMIO_READ : SVM_VMGEXIT_MMIO_WRITE;
742747

743-
if (!vc_slow_virt_to_phys(ghcb, ctxt, (unsigned long)ref, &paddr)) {
744-
if (!read)
748+
res = vc_slow_virt_to_phys(ghcb, ctxt, (unsigned long)ref, &paddr);
749+
if (res != ES_OK) {
750+
if (res == ES_EXCEPTION && !read)
745751
ctxt->fi.error_code |= X86_PF_WRITE;
746752

747-
return ES_EXCEPTION;
753+
return res;
748754
}
749755

750756
exit_info_1 = paddr;

0 commit comments

Comments
 (0)