[edk2-devel] [PATCH v7 0/9] Ovmf: Disable the TPM2 platform hierarchy

Stefan Berger stefanb at linux.ibm.com
Fri Sep 10 20:47:46 UTC 2021


On 9/10/21 12:15 PM, Stefan Berger wrote:

>
> On 9/10/21 11:32 AM, Yao, Jiewen wrote:
>> According to the security policy, PP request must be processed before 
>> EndOfDxe.
>>
>> May I know when you trigger PP request?
>
> OVMF has 3 implementations invoking it in 
> PlatformBootManagerAfterConsole():
>
> https://github.com/tianocore/edk2/blob/master/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c#L1517 
>
>
> https://github.com/tianocore/edk2/blob/master/OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c#L1451 
>
>
> https://github.com/tianocore/edk2/blob/master/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c#L1316 
>

Before I post yet another series...:

The problem is that PPI may require interaction with the console, so it 
seems we have to handle it in PlatformBootManagerAfterConsole(). The 
disablement of the TPM 2 platform hierarchy may only occur after that, 
so we have to move this part here after TPM-PPI-Handling from 
BeforeConsole() into AfterConsole() because this is what triggers that 
new code from edk2-platforms to disable that TPM 2 platform hierarchy:

   Status = gBS->InstallProtocolInterface (&Handle,
                   &gEfiDxeSmmReadyToLockProtocolGuid, EFI_NATIVE_INTERFACE,
                   NULL);

And then we have this part here also in BeforeConsole() that has to be 
moved as well into AfterConsole().

   //
   // Dispatch deferred images after EndOfDxe event and ReadyToLock
   // installation.
   //
   EfiBootManagerDispatchDeferredImages ();


This then leads to something like this with the sequence 
(TPM-PPI-handling, gEfiDxeSmmReadyToLockProtocol, 
EfiBootManagerDispatchDeferredImages) needing to stay in that order. 
However, I am not sure know whether one can just move these parts around 
like this.


diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c 
b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
index 71f63b2448..266d58dfbe 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
@@ -354,7 +354,6 @@ PlatformBootManagerBeforeConsole (
    VOID
    )
  {
-  EFI_HANDLE    Handle;
    EFI_STATUS    Status;
    UINT16        FrontPageTimeout;
    RETURN_STATUS PcdStatus;
@@ -387,8 +386,10 @@ PlatformBootManagerBeforeConsole (
      SaveS3BootScript ();
    }

+#if 0
    //
    // Prevent further changes to LockBoxes or SMRAM.
+  // Any TPM 2 Physical Presence Interface opcode must be handled BEFORE
    //
    Handle = NULL;
    Status = gBS->InstallProtocolInterface (&Handle,
@@ -401,6 +402,7 @@ PlatformBootManagerBeforeConsole (
    // installation.
    //
    EfiBootManagerDispatchDeferredImages ();
+#endif

    PlatformInitializeConsole (
      XenDetected() ? gXenPlatformConsole : gPlatformConsole);
@@ -437,6 +439,7 @@ PlatformBootManagerBeforeConsole (
    //
    VisitAllInstancesOfProtocol (&gEfiPciIoProtocolGuid, 
ConnectVirtioPciRng,
      NULL);
+
  }


@@ -1474,6 +1477,8 @@ PlatformBootManagerAfterConsole (
    VOID
    )
  {
+  EFI_STATUS                         Status;
+  EFI_HANDLE                         Handle;
    EFI_BOOT_MODE                      BootMode;

    DEBUG ((DEBUG_INFO, "PlatformBootManagerAfterConsole\n"));
@@ -1511,11 +1516,29 @@ PlatformBootManagerAfterConsole (
    //
    PciAcpiInitialization ();

+#if 1
    //
-  // Process TPM PPI request
+  // Process TPM PPI request; this may require interaction via console
    //
    Tcg2PhysicalPresenceLibProcessRequest (NULL);

+  //
+  // Prevent further changes to LockBoxes or SMRAM.
+  // Any TPM 2 Physical Presence Interface opcode must be handled BEFORE
+  //
+  Handle = NULL;
+  Status = gBS->InstallProtocolInterface (&Handle,
+                  &gEfiDxeSmmReadyToLockProtocolGuid, EFI_NATIVE_INTERFACE,
+                  NULL);
+  ASSERT_EFI_ERROR (Status);
+
+  //
+  // Dispatch deferred images after EndOfDxe event and ReadyToLock
+  // installation.
+  //
+  EfiBootManagerDispatchDeferredImages ();
+#endif
+
    //
    // Process QEMU's -kernel command line option
    //


    Stefan



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#80507): https://edk2.groups.io/g/devel/message/80507
Mute This Topic: https://groups.io/mt/85498425/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-






More information about the edk2-devel-archive mailing list