Skip to content

Commit 72de94d

Browse files
committed
x86/sev: Check for user-space IOIO pointing to kernel space
jira VULN-6719 cve CVE-2023-46813 commit-author Joerg Roedel <[email protected]> commit 63e44bc Check the memory operand of INS/OUTS before emulating the instruction. The #VC exception can get raised from user-space, but the memory operand can be manipulated to access kernel memory before the emulation actually begins and after the exception handler has run. [ bp: Massage commit message. ] Fixes: 597cfe4 ("x86/boot/compressed/64: Setup a GHCB-based VC Exception handler") Reported-by: Tom Dohrmann <[email protected]> Signed-off-by: Joerg Roedel <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Cc: <[email protected]> (cherry picked from commit 63e44bc) Signed-off-by: Marcin Wcisło <[email protected]>
1 parent c90c4a4 commit 72de94d

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

arch/x86/boot/compressed/sev.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ static enum es_result vc_ioio_check(struct es_em_ctxt *ctxt, u16 port, size_t si
108108
return ES_OK;
109109
}
110110

111+
static bool fault_in_kernel_space(unsigned long address)
112+
{
113+
return false;
114+
}
115+
111116
#undef __init
112117
#undef __pa
113118
#define __init

arch/x86/kernel/sev-shared.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,36 @@ void __init do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code)
589589
sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ);
590590
}
591591

592+
static enum es_result vc_insn_string_check(struct es_em_ctxt *ctxt,
593+
unsigned long address,
594+
bool write)
595+
{
596+
if (user_mode(ctxt->regs) && fault_in_kernel_space(address)) {
597+
ctxt->fi.vector = X86_TRAP_PF;
598+
ctxt->fi.error_code = X86_PF_USER;
599+
ctxt->fi.cr2 = address;
600+
if (write)
601+
ctxt->fi.error_code |= X86_PF_WRITE;
602+
603+
return ES_EXCEPTION;
604+
}
605+
606+
return ES_OK;
607+
}
608+
592609
static enum es_result vc_insn_string_read(struct es_em_ctxt *ctxt,
593610
void *src, char *buf,
594611
unsigned int data_size,
595612
unsigned int count,
596613
bool backwards)
597614
{
598615
int i, b = backwards ? -1 : 1;
599-
enum es_result ret = ES_OK;
616+
unsigned long address = (unsigned long)src;
617+
enum es_result ret;
618+
619+
ret = vc_insn_string_check(ctxt, address, false);
620+
if (ret != ES_OK)
621+
return ret;
600622

601623
for (i = 0; i < count; i++) {
602624
void *s = src + (i * data_size * b);
@@ -617,7 +639,12 @@ static enum es_result vc_insn_string_write(struct es_em_ctxt *ctxt,
617639
bool backwards)
618640
{
619641
int i, s = backwards ? -1 : 1;
620-
enum es_result ret = ES_OK;
642+
unsigned long address = (unsigned long)dst;
643+
enum es_result ret;
644+
645+
ret = vc_insn_string_check(ctxt, address, true);
646+
if (ret != ES_OK)
647+
return ret;
621648

622649
for (i = 0; i < count; i++) {
623650
void *d = dst + (i * data_size * s);

0 commit comments

Comments
 (0)