]> Git Repo - linux.git/commitdiff
x86/sev-es: Handle string port IO to kernel memory properly
authorHyunwook (Wooky) Baek <[email protected]>
Sun, 10 Jan 2021 07:11:02 +0000 (23:11 -0800)
committerBorislav Petkov <[email protected]>
Mon, 11 Jan 2021 19:01:52 +0000 (20:01 +0100)
Don't assume dest/source buffers are userspace addresses when manually
copying data for string I/O or MOVS MMIO, as {get,put}_user() will fail
if handed a kernel address and ultimately lead to a kernel panic.

When invoking INSB/OUTSB instructions in kernel space in a
SEV-ES-enabled VM, the kernel crashes with the following message:

  "SEV-ES: Unsupported exception in #VC instruction emulation - can't continue"

Handle that case properly.

 [ bp: Massage commit message. ]

Fixes: f980f9c31a92 ("x86/sev-es: Compile early handler code into kernel image")
Signed-off-by: Hyunwook (Wooky) Baek <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Acked-by: David Rientjes <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
arch/x86/kernel/sev-es.c

index 0bd1a0fc587e0f830e25e5b4199972ad1471ff96..ab31c34ba508c9186b8acbcd1521c9f7133e8006 100644 (file)
@@ -286,6 +286,12 @@ static enum es_result vc_write_mem(struct es_em_ctxt *ctxt,
        u16 d2;
        u8  d1;
 
+       /* If instruction ran in kernel mode and the I/O buffer is in kernel space */
+       if (!user_mode(ctxt->regs) && !access_ok(target, size)) {
+               memcpy(dst, buf, size);
+               return ES_OK;
+       }
+
        switch (size) {
        case 1:
                memcpy(&d1, buf, 1);
@@ -335,6 +341,12 @@ static enum es_result vc_read_mem(struct es_em_ctxt *ctxt,
        u16 d2;
        u8  d1;
 
+       /* If instruction ran in kernel mode and the I/O buffer is in kernel space */
+       if (!user_mode(ctxt->regs) && !access_ok(s, size)) {
+               memcpy(buf, src, size);
+               return ES_OK;
+       }
+
        switch (size) {
        case 1:
                if (get_user(d1, s))
This page took 0.049109 seconds and 4 git commands to generate.