]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: PlatformBdsLib: lock down SMM in PlatformBdsInit()
authorLaszlo Ersek <lersek@redhat.com>
Wed, 27 Apr 2016 15:37:42 +0000 (17:37 +0200)
committerLaszlo Ersek <lersek@redhat.com>
Thu, 28 Apr 2016 17:35:26 +0000 (19:35 +0200)
OVMF's PlatformBdsLib currently makes SMM vulnerable to the following
attack:

(1) a malicious guest OS copies a UEFI driver module to the EFI system
    partition,

(2) the OS adds the driver as a Driver#### option, and references it from
    DriverOrder,

(3) at next boot, the BdsEntry() function in
    "IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c" processes
    Driver#### and DriverOrder between the calls to PlatformBdsInit() and
    PlatformBdsPolicyBehavior(),

(4) OVMF locks down SMM only in PlatformBdsPolicyBehavior(), hence the
    driver runs with SMM unlocked.

The BdsEntry() function of the MdeModulePkg BDS driver (in file
"MdeModulePkg/Universal/BdsDxe/BdsEntry.c") recommends to "Signal
ReadyToLock event" in PlatformBootManagerBeforeConsole() -- which
corresponds to PlatformBdsInit() --, not in
PlatformBootManagerAfterConsole() -- which corresponds to
PlatformBdsPolicyBehavior().

Albeit an independent question, but it's worth mentioning: this patch also
brings OvmfPkg's PlatformBdsInit() closer to ArmVirtPkg's. Namely, the
latter signals End-of-Dxe in PlatformBdsInit() already.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
OvmfPkg/Library/PlatformBdsLib/BdsPlatform.c

index 0bc02baf0371818528c656645fc03b71173768af..b22f2a74a9d8a3ff9c6a0a2da266cf748e7d8f3b 100644 (file)
@@ -88,6 +88,20 @@ InstallDevicePathCallback (
   VOID\r
   );\r
 \r
+EFI_STATUS\r
+EFIAPI\r
+ConnectRootBridge (\r
+  IN EFI_HANDLE  RootBridgeHandle,\r
+  IN VOID        *Instance,\r
+  IN VOID        *Context\r
+  );\r
+\r
+STATIC\r
+VOID\r
+SaveS3BootScript (\r
+  VOID\r
+  );\r
+\r
 //\r
 // BDS Platform Functions\r
 //\r
@@ -113,6 +127,31 @@ Returns:
 {\r
   DEBUG ((EFI_D_INFO, "PlatformBdsInit\n"));\r
   InstallDevicePathCallback ();\r
+\r
+  VisitAllInstancesOfProtocol (&gEfiPciRootBridgeIoProtocolGuid,\r
+    ConnectRootBridge, NULL);\r
+\r
+  //\r
+  // Signal the ACPI platform driver that it can download QEMU ACPI tables.\r
+  //\r
+  EfiEventGroupSignal (&gRootBridgesConnectedEventGroupGuid);\r
+\r
+  //\r
+  // We can't signal End-of-Dxe earlier than this. Namely, End-of-Dxe triggers\r
+  // the preparation of S3 system information. That logic has a hard dependency\r
+  // on the presence of the FACS ACPI table. Since our ACPI tables are only\r
+  // installed after PCI enumeration completes, we must not trigger the S3 save\r
+  // earlier, hence we can't signal End-of-Dxe earlier.\r
+  //\r
+  EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);\r
+\r
+  if (QemuFwCfgS3Enabled ()) {\r
+    //\r
+    // Save the boot script too. Note that this requires/includes emitting the\r
+    // DxeSmmReadyToLock event, which in turn locks down SMM.\r
+    //\r
+    SaveS3BootScript ();\r
+  }\r
 }\r
 \r
 \r
@@ -1242,31 +1281,6 @@ Returns:
 \r
   DEBUG ((EFI_D_INFO, "PlatformBdsPolicyBehavior\n"));\r
 \r
-  VisitAllInstancesOfProtocol (&gEfiPciRootBridgeIoProtocolGuid,\r
-    ConnectRootBridge, NULL);\r
-\r
-  //\r
-  // Signal the ACPI platform driver that it can download QEMU ACPI tables.\r
-  //\r
-  EfiEventGroupSignal (&gRootBridgesConnectedEventGroupGuid);\r
-\r
-  //\r
-  // We can't signal End-of-Dxe earlier than this. Namely, End-of-Dxe triggers\r
-  // the preparation of S3 system information. That logic has a hard dependency\r
-  // on the presence of the FACS ACPI table. Since our ACPI tables are only\r
-  // installed after PCI enumeration completes, we must not trigger the S3 save\r
-  // earlier, hence we can't signal End-of-Dxe earlier.\r
-  //\r
-  EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);\r
-\r
-  if (QemuFwCfgS3Enabled ()) {\r
-    //\r
-    // Save the boot script too. Note that this requires/includes emitting the\r
-    // DxeSmmReadyToLock event, which in turn locks down SMM.\r
-    //\r
-    SaveS3BootScript ();\r
-  }\r
-\r
   if (PcdGetBool (PcdOvmfFlashVariablesEnable)) {\r
     DEBUG ((EFI_D_INFO, "PlatformBdsPolicyBehavior: not restoring NvVars "\r
       "from disk since flash variables appear to be supported.\n"));\r