]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvfmPkg/VmgExitLib: Properly decode MMIO MOVZX and MOVSX opcodes
authorLendacky, Thomas <thomas.lendacky@amd.com>
Thu, 29 Apr 2021 17:12:10 +0000 (12:12 -0500)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 30 Apr 2021 18:35:50 +0000 (18:35 +0000)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3345

The MOVZX and MOVSX instructions use the ModRM byte in the instruction,
but the instruction decoding support was not decoding it. This resulted
in invalid decoding and failing of the MMIO operation. Also, when
performing the zero-extend or sign-extend operation, the memory operation
should be using the size, and not the size enumeration value.

Add the ModRM byte decoding for the MOVZX and MOVSX opcodes and use the
true data size to perform the extend operations. Additionally, add a
DEBUG statement identifying the MMIO address being flagged as encrypted
during the MMIO address validation.

Fixes: c45f678a1ea2080344e125dc55b14e4b9f98483d
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Message-Id: <5949d54cb2c9ab69256f67ed5654b32654c0501c.1619716333.git.thomas.lendacky@amd.com>

OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c

index 24259060fd652460103698fbbe92205f03420a49..b716541ad170380c2d0869f23a1b990d471196fa 100644 (file)
@@ -643,6 +643,9 @@ ValidateMmioMemory (
   //\r
   // Any state other than unencrypted is an error, issue a #GP.\r
   //\r
+  DEBUG ((DEBUG_ERROR,\r
+    "MMIO using encrypted memory: %lx\n",\r
+    (UINT64) MemoryAddress));\r
   GpEvent.Uint64 = 0;\r
   GpEvent.Elements.Vector = GP_EXCEPTION;\r
   GpEvent.Elements.Type   = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;\r
@@ -817,6 +820,7 @@ MmioExit (
     // fall through\r
     //\r
   case 0xB7:\r
+    DecodeModRm (Regs, InstructionData);\r
     Bytes = (Bytes != 0) ? Bytes : 2;\r
 \r
     Status = ValidateMmioMemory (Ghcb, InstructionData->Ext.RmData, Bytes);\r
@@ -835,7 +839,7 @@ MmioExit (
     }\r
 \r
     Register = GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg);\r
-    SetMem (Register, InstructionData->DataSize, 0);\r
+    SetMem (Register, (UINTN) (1 << InstructionData->DataSize), 0);\r
     CopyMem (Register, Ghcb->SharedBuffer, Bytes);\r
     break;\r
 \r
@@ -848,6 +852,7 @@ MmioExit (
     // fall through\r
     //\r
   case 0xBF:\r
+    DecodeModRm (Regs, InstructionData);\r
     Bytes = (Bytes != 0) ? Bytes : 2;\r
 \r
     Status = ValidateMmioMemory (Ghcb, InstructionData->Ext.RmData, Bytes);\r
@@ -878,7 +883,7 @@ MmioExit (
     }\r
 \r
     Register = GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg);\r
-    SetMem (Register, InstructionData->DataSize, SignByte);\r
+    SetMem (Register, (UINTN) (1 << InstructionData->DataSize), SignByte);\r
     CopyMem (Register, Ghcb->SharedBuffer, Bytes);\r
     break;\r
 \r