libstub,tpm: do not ignore failure case when reading final event log
authorGregory Price <gourry@gourry.net>
Fri, 13 Sep 2024 23:19:54 +0000 (19:19 -0400)
committerArd Biesheuvel <ardb@kernel.org>
Tue, 15 Oct 2024 18:27:30 +0000 (20:27 +0200)
Current code fails to check for an error case when reading events
from final event log to calculate offsets.  Check the error case,
and break early because all subsequent calls will also fail.

Signed-off-by: Gregory Price <gourry@gourry.net>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/libstub/tpm.c

index d31ea3f..a5c6c4f 100644 (file)
@@ -124,6 +124,9 @@ static void efi_retrieve_tcg2_eventlog(int version, efi_physical_addr_t log_loca
                        event_size = __calc_tpm2_event_size(header,
                                                   (void *)(long)log_location,
                                                   false);
+                       /* If calc fails this is a malformed log */
+                       if (!event_size)
+                               break;
                        final_events_size += event_size;
                        i--;
                }