summaryrefslogtreecommitdiff
path: root/tpm.c
diff options
context:
space:
mode:
authorSteve McIntyre <steve@einval.com>2022-04-27 22:41:59 +0100
committerSteve McIntyre <steve@einval.com>2022-04-27 22:41:59 +0100
commitacb8d1ffbca46190a934a5b27185a95ba4451fda (patch)
treedc4a7291fa6dff3855f012b74ee779fa49ce8e94 /tpm.c
parent39c311d6773b915df277a62425a6715b2d977ab6 (diff)
parent8529e0f7f70f427a7202815061362eceba6bfc50 (diff)
downloadefi-boot-shim-acb8d1ffbca46190a934a5b27185a95ba4451fda.tar.gz
efi-boot-shim-acb8d1ffbca46190a934a5b27185a95ba4451fda.zip
Update upstream source from tag 'upstream/15.5'
Update to upstream version '15.5' with Debian dir 3ac353daa3d32301e3b225b2b6f446200a2c682f
Diffstat (limited to 'tpm.c')
-rw-r--r--tpm.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/tpm.c b/tpm.c
index 808e0444..41f36651 100644
--- a/tpm.c
+++ b/tpm.c
@@ -10,6 +10,7 @@ typedef struct {
UINTN measuredcount = 0;
VARIABLE_RECORD *measureddata = NULL;
+static BOOLEAN tpm_defective = FALSE;
static BOOLEAN tpm_present(efi_tpm_protocol_t *tpm)
{
@@ -18,6 +19,9 @@ static BOOLEAN tpm_present(efi_tpm_protocol_t *tpm)
UINT32 flags;
EFI_PHYSICAL_ADDRESS eventlog, lastevent;
+ if (tpm_defective)
+ return FALSE;
+
caps.Size = (UINT8)sizeof(caps);
efi_status = tpm->status_check(tpm, &caps, &flags,
&eventlog, &lastevent);
@@ -192,6 +196,12 @@ static EFI_STATUS tpm_log_event_raw(EFI_PHYSICAL_ADDRESS buf, UINTN size,
(UINT64)size, TPM_ALG_SHA, event, &eventnum,
&lastevent);
}
+ if (efi_status == EFI_UNSUPPORTED) {
+ perror(L"Could not write TPM event: %r. Considering "
+ "the TPM as defective.\n", efi_status);
+ tpm_defective = TRUE;
+ efi_status = EFI_SUCCESS;
+ }
FreePool(event);
return efi_status;
}
@@ -353,3 +363,25 @@ fallback_should_prefer_reset(void)
return EFI_NOT_FOUND;
return EFI_SUCCESS;
}
+
+#ifdef SHIM_UNIT_TEST
+static void DESTRUCTOR
+tpm_clean_up_measurements(void)
+{
+ for (UINTN i = 0; i < measuredcount; i++) {
+ VARIABLE_RECORD *vr = &measureddata[i];
+
+ if (vr->VariableName)
+ FreePool(vr->VariableName);
+ if (vr->VendorGuid)
+ FreePool(vr->VendorGuid);
+ if (vr->Data)
+ FreePool(vr->Data);
+ }
+ if (measureddata)
+ FreePool(measureddata);
+
+ measuredcount = 0;
+ measureddata = NULL;
+}
+#endif