]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Variable/RuntimeDxe: delay MorLock creation until EndOfDxe
authorLaszlo Ersek <lersek@redhat.com>
Sat, 30 Sep 2017 15:37:57 +0000 (17:37 +0200)
committerLaszlo Ersek <lersek@redhat.com>
Tue, 10 Oct 2017 09:25:26 +0000 (11:25 +0200)
The "MemoryOverwriteRequestControl" (a.k.a. MOR) variable comes from the
"TCG Platform Reset Attack Mitigation Specification":

https://www.trustedcomputinggroup.org/wp-content/uploads/Platform-Reset-Attack-Mitigation-Specification.pdf

The "MemoryOverwriteRequestControlLock" variable (a.k.a. MORL) is a
Microsoft extension, called "Secure MOR implementation":

https://docs.microsoft.com/en-us/windows-hardware/drivers/bringup/device-guard-requirements

Currently the VariableSmm driver creates MORL without regard to MOR. This
can lead to a situation where a platform does not support MOR from the
prerequisite spec (because it does not include the
"SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.inf" driver), but appears
to support MORL from the dependent Microsoft spec.

"winload.efi" notices this inconsistency, and disables the Device Guard
Virtualization Based Security in Windows Server 2016 and Windows 10 64-bit
Enterprise.

If the platform includes
"SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.inf", then MOR will exist
by the time EndOfDxe is reached, and VariableSmm can safely create MORL.
Otherwise, do not create MORL (delete it if it exists), and also prevent
other modules from creating it.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Ladi Prosek <lprosek@redhat.com>
Cc: Star Zeng <star.zeng@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=727
Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1496170
Reported-by: Ladi Prosek <lprosek@redhat.com>
Suggested-by: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Tested-by: Ladi Prosek <lprosek@redhat.com>
MdeModulePkg/Universal/Variable/RuntimeDxe/TcgMorLockSmm.c

index 3b2d555d2e45a200fd9faccaa99e943c50b4a212..faeaabb224afc6fa9214fdc34191e94fce2ee864 100644 (file)
@@ -45,6 +45,7 @@ typedef enum {
   MorLockStateLocked = 1,\r
 } MOR_LOCK_STATE;\r
 \r
+BOOLEAN         mMorLockInitializationRequired = FALSE;\r
 UINT8           mMorLockKey[MOR_LOCK_V2_KEY_SIZE];\r
 BOOLEAN         mMorLockKeyEmpty = TRUE;\r
 BOOLEAN         mMorLockPassThru = FALSE;\r
@@ -392,10 +393,8 @@ MorLockInit (
   VOID\r
   )\r
 {\r
-  //\r
-  // Set variable to report capability to OS\r
-  //\r
-  return SetMorLockVariable (0);\r
+  mMorLockInitializationRequired = TRUE;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -408,7 +407,61 @@ MorLockInitAtEndOfDxe (
   VOID\r
   )\r
 {\r
+  UINTN      MorSize;\r
+  EFI_STATUS MorStatus;\r
+\r
+  if (!mMorLockInitializationRequired) {\r
+    //\r
+    // The EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL has never been installed, thus\r
+    // the variable write service is unavailable. This should never happen.\r
+    //\r
+    ASSERT (FALSE);\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Check if the MOR variable exists.\r
+  //\r
+  MorSize = 0;\r
+  MorStatus = VariableServiceGetVariable (\r
+                MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,\r
+                &gEfiMemoryOverwriteControlDataGuid,\r
+                NULL,                                   // Attributes\r
+                &MorSize,\r
+                NULL                                    // Data\r
+                );\r
   //\r
-  // Do nothing.\r
+  // We provided a zero-sized buffer, so the above call can never succeed.\r
   //\r
+  ASSERT (EFI_ERROR (MorStatus));\r
+\r
+  if (MorStatus == EFI_BUFFER_TOO_SMALL) {\r
+    //\r
+    // The MOR variable exists; set the MOR Control Lock variable to report the\r
+    // capability to the OS.\r
+    //\r
+    SetMorLockVariable (0);\r
+    return;\r
+  }\r
+\r
+  //\r
+  // The platform does not support the MOR variable. Delete the MOR Control\r
+  // Lock variable (should it exists for some reason) and prevent other modules\r
+  // from creating it.\r
+  //\r
+  mMorLockPassThru = TRUE;\r
+  VariableServiceSetVariable (\r
+    MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,\r
+    &gEfiMemoryOverwriteRequestControlLockGuid,\r
+    0,                                          // Attributes\r
+    0,                                          // DataSize\r
+    NULL                                        // Data\r
+    );\r
+  mMorLockPassThru = FALSE;\r
+\r
+  VariableLockRequestToLock (\r
+    NULL,                                       // This\r
+    MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,\r
+    &gEfiMemoryOverwriteRequestControlLockGuid\r
+    );\r
 }\r