Skip to content

Commit 05c8c1f

Browse files
vathpelaIngo Molnar
authored andcommitted
efi/tpm: Don't traverse an event log with no events
When there are no entries to put into the final event log, some machines will return the template they would have populated anyway. In this case the nr_events field is 0, but the rest of the log is just garbage. This patch stops us from trying to iterate the table with __calc_tpm2_event_size() when the number of events in the table is 0. Tested-by: Lyude Paul <[email protected]> Signed-off-by: Peter Jones <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Acked-by: Matthew Garrett <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Cc: Ben Dooks <[email protected]> Cc: Dave Young <[email protected]> Cc: Jerry Snitselaar <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Lukas Wunner <[email protected]> Cc: Octavian Purdila <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Scott Talbert <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Fixes: c46f340 ("tpm: Reserve the TPM final events table") Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 047d50a commit 05c8c1f

File tree

1 file changed

+10
-5
lines changed
  • drivers/firmware/efi

1 file changed

+10
-5
lines changed

drivers/firmware/efi/tpm.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,16 @@ int __init efi_tpm_eventlog_init(void)
7575
goto out;
7676
}
7777

78-
tbl_size = tpm2_calc_event_log_size((void *)efi.tpm_final_log
79-
+ sizeof(final_tbl->version)
80-
+ sizeof(final_tbl->nr_events),
81-
final_tbl->nr_events,
82-
log_tbl->log);
78+
tbl_size = 0;
79+
if (final_tbl->nr_events != 0) {
80+
void *events = (void *)efi.tpm_final_log
81+
+ sizeof(final_tbl->version)
82+
+ sizeof(final_tbl->nr_events);
83+
84+
tbl_size = tpm2_calc_event_log_size(events,
85+
final_tbl->nr_events,
86+
log_tbl->log);
87+
}
8388
memblock_reserve((unsigned long)final_tbl,
8489
tbl_size + sizeof(*final_tbl));
8590
early_memunmap(final_tbl, sizeof(*final_tbl));

0 commit comments

Comments
 (0)