Skip to content

Commit c972c82

Browse files
committed
tpm: fix signed/unsigned bug when checking event logs
JIRA: https://issues.redhat.com/browse/RHEL-72764 Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git commit e6d654e Author: Gregory Price <gourry@gourry.net> Date: Fri Sep 13 19:19:51 2024 -0400 tpm: fix signed/unsigned bug when checking event logs A prior bugfix that fixes a signed/unsigned error causes another signed unsigned error. A situation where log_tbl->size is invalid can cause the size passed to memblock_reserve to become negative. log_size from the main event log is an unsigned int, and the code reduces to the following u64 value = (int)unsigned_value; This results in sign extension, and the value sent to memblock_reserve becomes effectively negative. Fixes: be59d57 ("efi/tpm: Fix sanity check of unsigned tbl_size being less than zero") Signed-off-by: Gregory Price <gourry@gourry.net> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Štěpán Horáček <shoracek@redhat.com>
1 parent c6605c7 commit c972c82

File tree

1 file changed

+9
-8
lines changed
  • drivers/firmware/efi

1 file changed

+9
-8
lines changed

drivers/firmware/efi/tpm.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ int __init efi_tpm_eventlog_init(void)
4040
{
4141
struct linux_efi_tpm_eventlog *log_tbl;
4242
struct efi_tcg2_final_events_table *final_tbl;
43-
int tbl_size;
43+
unsigned int tbl_size;
44+
int final_tbl_size;
4445
int ret = 0;
4546

4647
if (efi.tpm_log == EFI_INVALID_TABLE_ADDR) {
@@ -80,26 +81,26 @@ int __init efi_tpm_eventlog_init(void)
8081
goto out;
8182
}
8283

83-
tbl_size = 0;
84+
final_tbl_size = 0;
8485
if (final_tbl->nr_events != 0) {
8586
void *events = (void *)efi.tpm_final_log
8687
+ sizeof(final_tbl->version)
8788
+ sizeof(final_tbl->nr_events);
8889

89-
tbl_size = tpm2_calc_event_log_size(events,
90-
final_tbl->nr_events,
91-
log_tbl->log);
90+
final_tbl_size = tpm2_calc_event_log_size(events,
91+
final_tbl->nr_events,
92+
log_tbl->log);
9293
}
9394

94-
if (tbl_size < 0) {
95+
if (final_tbl_size < 0) {
9596
pr_err(FW_BUG "Failed to parse event in TPM Final Events Log\n");
9697
ret = -EINVAL;
9798
goto out_calc;
9899
}
99100

100101
memblock_reserve(efi.tpm_final_log,
101-
tbl_size + sizeof(*final_tbl));
102-
efi_tpm_final_log_size = tbl_size;
102+
final_tbl_size + sizeof(*final_tbl));
103+
efi_tpm_final_log_size = final_tbl_size;
103104

104105
out_calc:
105106
early_memunmap(final_tbl, sizeof(*final_tbl));

0 commit comments

Comments
 (0)