Skip to content

Commit

Permalink
OvmfPkg: Handle TPM 2 physical presence opcodes much earlier
Browse files Browse the repository at this point in the history
Handle the TPM 2 physical presence interface (PPI) opcodes in
PlatformBootManagerBeforeConsole() before the TPM 2 platform hierarchy
is disabled. Since the handling of the PPI opcodes may require inter-
action with the user, initialize the keyboard before handling PPI codes.

Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Peter Grehan <grehan@freebsd.org>
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>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
  • Loading branch information
stefanberger authored and mergify[bot] committed Sep 30, 2021
1 parent 499c460 commit b8675de
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
19 changes: 11 additions & 8 deletions OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
Expand Up @@ -387,8 +387,19 @@ PlatformBootManagerBeforeConsole (
SaveS3BootScript ();
}

// We need to connect all trusted consoles for TCG PP. Here we treat all
// consoles in OVMF to be trusted consoles.
PlatformInitializeConsole (
XenDetected() ? gXenPlatformConsole : gPlatformConsole);

//
// Process TPM PPI request; this may require keyboard input
//
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,
Expand All @@ -402,9 +413,6 @@ PlatformBootManagerBeforeConsole (
//
EfiBootManagerDispatchDeferredImages ();

PlatformInitializeConsole (
XenDetected() ? gXenPlatformConsole : gPlatformConsole);

FrontPageTimeout = GetFrontPageTimeoutFromQemu ();
PcdStatus = PcdSet16S (PcdPlatformBootTimeOut, FrontPageTimeout);
ASSERT_RETURN_ERROR (PcdStatus);
Expand Down Expand Up @@ -1511,11 +1519,6 @@ PlatformBootManagerAfterConsole (
//
PciAcpiInitialization ();

//
// Process TPM PPI request
//
Tcg2PhysicalPresenceLibProcessRequest (NULL);

//
// Process QEMU's -kernel command line option
//
Expand Down
17 changes: 10 additions & 7 deletions OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c
Expand Up @@ -375,8 +375,18 @@ PlatformBootManagerBeforeConsole (
//
EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);

// We need to connect all trusted consoles for TCG PP. Here we treat all
// consoles in OVMF to be trusted consoles.
PlatformInitializeConsole (gPlatformConsole);

//
// Process TPM PPI request
//
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,
Expand All @@ -390,8 +400,6 @@ PlatformBootManagerBeforeConsole (
//
EfiBootManagerDispatchDeferredImages ();

PlatformInitializeConsole (gPlatformConsole);

PlatformRegisterOptionsAndKeys ();

//
Expand Down Expand Up @@ -1445,11 +1453,6 @@ PlatformBootManagerAfterConsole (
//
PciAcpiInitialization ();

//
// Process TPM PPI request
//
Tcg2PhysicalPresenceLibProcessRequest (NULL);

//
// Perform some platform specific connect sequence
//
Expand Down
17 changes: 10 additions & 7 deletions OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c
Expand Up @@ -338,8 +338,18 @@ PlatformBootManagerBeforeConsole (
//
EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);

// We need to connect all trusted consoles for TCG PP. Here we treat all
// consoles in OVMF to be trusted consoles.
PlatformInitializeConsole (gPlatformConsole);

//
// Process TPM PPI request
//
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,
Expand All @@ -353,8 +363,6 @@ PlatformBootManagerBeforeConsole (
//
EfiBootManagerDispatchDeferredImages ();

PlatformInitializeConsole (gPlatformConsole);

Status = gRT->SetVariable (
EFI_TIME_OUT_VARIABLE_NAME,
&gEfiGlobalVariableGuid,
Expand Down Expand Up @@ -1310,11 +1318,6 @@ PlatformBootManagerAfterConsole (
//
PciAcpiInitialization ();

//
// Process TPM PPI request
//
Tcg2PhysicalPresenceLibProcessRequest (NULL);

//
// Process QEMU's -kernel command line option
//
Expand Down

0 comments on commit b8675de

Please sign in to comment.