Skip to content

Commit b4f1874

Browse files
hwtiardbiesheuvel
authored andcommitted
tpm: check event log version before reading final events
This fixes the boot issues since 5.3 on several Dell models when the TPM is enabled. Depending on the exact grub binary, booting the kernel would freeze early, or just report an error parsing the final events log. We get an event log in the SHA-1 format, which doesn't have a tcg_efi_specid_event_head in the first event, and there is a final events table which doesn't match the crypto agile format. __calc_tpm2_event_size reads bad "count" and "efispecid->num_algs", and either fails, or loops long enough for the machine to be appear frozen. So we now only parse the final events table, which is per the spec always supposed to be in the crypto agile format, when we got a event log in this format. Fixes: c46f340 ("tpm: Reserve the TPM final events table") Fixes: 166a280 ("tpm: Don't duplicate events from the final event log in the TCG2 log") Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1779611 Signed-off-by: Loïc Yhuel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Javier Martinez Canillas <[email protected]> Reviewed-by: Jerry Snitselaar <[email protected]> Reviewed-by: Matthew Garrett <[email protected]> [ardb: warn when final events table is missing or in the wrong format] Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent e8da08a commit b4f1874

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

drivers/firmware/efi/libstub/tpm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void efi_retrieve_tpm2_eventlog(void)
5454
efi_status_t status;
5555
efi_physical_addr_t log_location = 0, log_last_entry = 0;
5656
struct linux_efi_tpm_eventlog *log_tbl = NULL;
57-
struct efi_tcg2_final_events_table *final_events_table;
57+
struct efi_tcg2_final_events_table *final_events_table = NULL;
5858
unsigned long first_entry_addr, last_entry_addr;
5959
size_t log_size, last_entry_size;
6060
efi_bool_t truncated;
@@ -127,7 +127,8 @@ void efi_retrieve_tpm2_eventlog(void)
127127
* Figure out whether any events have already been logged to the
128128
* final events structure, and if so how much space they take up
129129
*/
130-
final_events_table = get_efi_config_table(LINUX_EFI_TPM_FINAL_LOG_GUID);
130+
if (version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
131+
final_events_table = get_efi_config_table(LINUX_EFI_TPM_FINAL_LOG_GUID);
131132
if (final_events_table && final_events_table->nr_events) {
132133
struct tcg_pcr_event2_head *header;
133134
int offset;

drivers/firmware/efi/tpm.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ int __init efi_tpm_eventlog_init(void)
6262
tbl_size = sizeof(*log_tbl) + log_tbl->size;
6363
memblock_reserve(efi.tpm_log, tbl_size);
6464

65-
if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR)
65+
if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR ||
66+
log_tbl->version != EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) {
67+
pr_warn(FW_BUG "TPM Final Events table missing or invalid\n");
6668
goto out;
69+
}
6770

6871
final_tbl = early_memremap(efi.tpm_final_log, sizeof(*final_tbl));
6972

0 commit comments

Comments
 (0)