]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/AcpiPlatformDxe: Measure ACPI table from QEMU in TDVF
authorMin M Xu <min.m.xu@intel.com>
Thu, 2 Feb 2023 09:03:14 +0000 (17:03 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sat, 4 Feb 2023 02:45:08 +0000 (02:45 +0000)
https://bugzilla.tianocore.org/show_bug.cgi?id=4245

QEMU provides the following three files for guest to install the ACPI
tables:
 - etc/acpi/rsdp
 - etc/acpi/tables
 - etc/table-loader

"etc/acpi/rsdp" and "etc/acpi/tables" are similar, they are only kept
separate because they have different allocation requirements in SeaBIOS.

Both of these fw_cfg files contain preformatted ACPI payload.
"etc/acpi/rsdp" contains only the RSDP table, while "etc/acpi/tables"
contains all other tables, concatenated. To be noted, the tables in these
two files have been filled in by qemu, but two kinds of fields are
incomplete: pointers to other tables and checksums (which depend on the
pointers).

"/etc/table-loader" is a linker/loader which provides the commands to
"patch" the tables in "etc/acpi/tables" and then install them. "Patch"
means to fill the pointers and compute the checksum.

From the security perspective these 3 files are the raw data downloaded
from qemu. They should be measured and extended before they're consumed.

Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Michael Roth <michael.roth@amd.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c

index 8939dde425497ff239022af25b7b641a7cd24d92..3fd0483b50eb78f10c2d26331a88391806fdefe6 100644 (file)
@@ -46,6 +46,7 @@
   UefiBootServicesTableLib\r
   UefiDriverEntryPoint\r
   HobLib\r
+  TpmMeasurementLib\r
 \r
 [Protocols]\r
   gEfiAcpiTableProtocolGuid                     # PROTOCOL ALWAYS_CONSUMED\r
index f0d81d6fd73da8b27576433909c57a0616698d34..68abc34f2280ca5aaebc23dfa6f4223a45651c4c 100644 (file)
@@ -10,6 +10,7 @@
 \r
 #include <IndustryStandard/Acpi.h>            // EFI_ACPI_DESCRIPTION_HEADER\r
 #include <IndustryStandard/QemuLoader.h>      // QEMU_LOADER_FNAME_SIZE\r
+#include <IndustryStandard/UefiTcgPlatform.h>\r
 #include <Library/BaseLib.h>                  // AsciiStrCmp()\r
 #include <Library/BaseMemoryLib.h>            // CopyMem()\r
 #include <Library/DebugLib.h>                 // DEBUG()\r
@@ -18,6 +19,7 @@
 #include <Library/QemuFwCfgLib.h>             // QemuFwCfgFindFile()\r
 #include <Library/QemuFwCfgS3Lib.h>           // QemuFwCfgS3Enabled()\r
 #include <Library/UefiBootServicesTableLib.h> // gBS\r
+#include <Library/TpmMeasurementLib.h>\r
 \r
 #include "AcpiPlatform.h"\r
 \r
@@ -415,6 +417,21 @@ ProcessCmdAllocate (
     (UINT64)Blob->Size,\r
     (UINT64)(UINTN)Blob->Base\r
     ));\r
+\r
+  //\r
+  // Measure the data which is downloaded from QEMU.\r
+  // It has to be done before it is consumed. Because the data will\r
+  // be updated in the following operations.\r
+  //\r
+  TpmMeasureAndLogData (\r
+    1,\r
+    EV_PLATFORM_CONFIG_FLAGS,\r
+    EV_POSTCODE_INFO_ACPI_DATA,\r
+    ACPI_DATA_LEN,\r
+    (VOID *)(UINTN)Blob->Base,\r
+    Blob->Size\r
+    );\r
+\r
   return EFI_SUCCESS;\r
 \r
 FreeBlob:\r
@@ -1126,6 +1143,21 @@ InstallQemuFwCfgTables (
   QemuFwCfgSelectItem (FwCfgItem);\r
   QemuFwCfgReadBytes (FwCfgSize, LoaderStart);\r
   RestorePciDecoding (OriginalPciAttributes, OriginalPciAttributesCount);\r
+\r
+  //\r
+  // Measure the "etc/table-loader" which is downloaded from QEMU.\r
+  // It has to be done before it is consumed. Because it would be\r
+  // updated in the following operations.\r
+  //\r
+  TpmMeasureAndLogData (\r
+    1,\r
+    EV_PLATFORM_CONFIG_FLAGS,\r
+    EV_POSTCODE_INFO_ACPI_DATA,\r
+    ACPI_DATA_LEN,\r
+    (VOID *)(UINTN)LoaderStart,\r
+    FwCfgSize\r
+    );\r
+\r
   LoaderEnd = LoaderStart + FwCfgSize / sizeof *LoaderEntry;\r
 \r
   AllocationsRestrictedTo32Bit = NULL;\r