From 0baa915056b6dc3dbea51c045e1e3ef8a0d86a08 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Thu, 15 Jun 2017 15:16:05 +0200 Subject: [PATCH] shim/tpm: Take out GetCapability() call from tpm2_present() logic The EFI_TCG2_PROTOCOL.GetCapability() function is used to learn if a TPM2 chip is present. But the protocol capability information is also needed for other reasons, for example to determine what event log formats are supported by the firmware. Take out the GetCapability() call from the tpm2_present() logic and reduce that function to just checking if a TPM2 chip is available or not, so the capabilities can later be used to determine the supported TPM log formats. Signed-off-by: Javier Martinez Canillas --- tpm.c | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/tpm.c b/tpm.c index 99486b1..2ca5845 100644 --- a/tpm.c +++ b/tpm.c @@ -35,29 +35,41 @@ static BOOLEAN tpm_present(efi_tpm_protocol_t *tpm) return TRUE; } -static BOOLEAN tpm2_present(efi_tpm2_protocol_t *tpm) +static EFI_STATUS tpm2_get_caps(efi_tpm2_protocol_t *tpm, + EFI_TCG2_BOOT_SERVICE_CAPABILITY *caps, + BOOLEAN *old_caps) { EFI_STATUS status; - EFI_TCG2_BOOT_SERVICE_CAPABILITY caps; - TREE_BOOT_SERVICE_CAPABILITY *caps_1_0; - caps.Size = (UINT8)sizeof(caps); + caps->Size = (UINT8)sizeof(*caps); - status = uefi_call_wrapper(tpm->get_capability, 2, tpm, &caps); + status = uefi_call_wrapper(tpm->get_capability, 2, tpm, caps); if (status != EFI_SUCCESS) - return FALSE; + return status; - if (caps.StructureVersion.Major == 1 && - caps.StructureVersion.Minor == 0) { - caps_1_0 = (TREE_BOOT_SERVICE_CAPABILITY *)∩︀ + if (caps->StructureVersion.Major == 1 && + caps->StructureVersion.Minor == 0) + *old_caps = TRUE; + + return EFI_SUCCESS; +} + +static BOOLEAN tpm2_present(efi_tpm2_protocol_t *tpm, + EFI_TCG2_BOOT_SERVICE_CAPABILITY *caps, + BOOLEAN old_caps) +{ + TREE_BOOT_SERVICE_CAPABILITY *caps_1_0; + + if (old_caps) { + caps_1_0 = (TREE_BOOT_SERVICE_CAPABILITY *)caps; if (caps_1_0->TrEEPresentFlag) return TRUE; - } else { - if (caps.TPMPresentFlag) - return TRUE; } + if (caps->TPMPresentFlag) + return TRUE; + return FALSE; } @@ -90,9 +102,15 @@ EFI_STATUS tpm_log_event(EFI_PHYSICAL_ADDRESS buf, UINTN size, UINT8 pcr, status = LibLocateProtocol(&tpm2_guid, (VOID **)&tpm2); /* TPM 2.0 */ if (status == EFI_SUCCESS) { + BOOLEAN old_caps; EFI_TCG2_EVENT *event; + EFI_TCG2_BOOT_SERVICE_CAPABILITY caps; - if (!tpm2_present(tpm2)) + status = tpm2_get_caps(tpm2, &caps, &old_caps); + if (status != EFI_SUCCESS) + return EFI_SUCCESS; + + if (!tpm2_present(tpm2, &caps, old_caps)) return EFI_SUCCESS; status = trigger_tcg2_final_events_table(tpm2);