x86/sev: Disable MMIO emulation from user mode
authorBorislav Petkov (AMD) <bp@alien8.de>
Thu, 5 Oct 2023 09:06:36 +0000 (11:06 +0200)
committerBorislav Petkov (AMD) <bp@alien8.de>
Mon, 9 Oct 2023 13:45:34 +0000 (15:45 +0200)
A virt scenario can be constructed where MMIO memory can be user memory.
When that happens, a race condition opens between when the hardware
raises the #VC and when the #VC handler gets to emulate the instruction.

If the MOVS is replaced with a MOVS accessing kernel memory in that
small race window, then write to kernel memory happens as the access
checks are not done at emulation time.

Disable MMIO emulation in user mode temporarily until a sensible use
case appears and justifies properly handling the race window.

Fixes: 0118b604c2c9 ("x86/sev-es: Handle MMIO String Instructions")
Reported-by: Tom Dohrmann <erbse.13@gmx.de>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Tested-by: Tom Dohrmann <erbse.13@gmx.de>
Cc: <stable@kernel.org>
arch/x86/kernel/sev.c

index 2787826d9f607798da1d2b2fca4d8550a601eb0c..4ee14e647ae62b0efc8c15196e57dbcd466c3532 100644 (file)
@@ -1509,6 +1509,9 @@ static enum es_result vc_handle_mmio(struct ghcb *ghcb, struct es_em_ctxt *ctxt)
                        return ES_DECODE_FAILED;
        }
 
+       if (user_mode(ctxt->regs))
+               return ES_UNSUPPORTED;
+
        switch (mmio) {
        case INSN_MMIO_WRITE:
                memcpy(ghcb->shared_buffer, reg_data, bytes);