Skip to content

Commit

Permalink
tpm: Fix off-by-one error when calculating event size
Browse files Browse the repository at this point in the history
tpm_log_event_raw() allocates a buffer for the EFI_TCG2_EVENT structure
that is one byte larger than necessary, and sets event->Size accordingly.
The result of this is that the event data recorded in the log differs
from the data that is measured to the TPM (it has an extra zero byte
at the end).
  • Loading branch information
chrisccoulson authored and vathpela committed Nov 22, 2019
1 parent 6a73ca8 commit 8a27a48
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/tpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ static EFI_STATUS tpm_log_event_raw(EFI_PHYSICAL_ADDRESS buf, UINTN size,
#endif
} else if (tpm2) {
EFI_TCG2_EVENT *event;
UINTN event_size = sizeof(*event) - sizeof(event->Event) +
logsize;

event = AllocatePool(sizeof(*event) + logsize);
event = AllocatePool(event_size);
if (!event) {
perror(L"Unable to allocate event structure\n");
return EFI_OUT_OF_RESOURCES;
Expand All @@ -142,7 +144,7 @@ static EFI_STATUS tpm_log_event_raw(EFI_PHYSICAL_ADDRESS buf, UINTN size,
event->Header.HeaderVersion = 1;
event->Header.PCRIndex = pcr;
event->Header.EventType = type;
event->Size = sizeof(*event) - sizeof(event->Event) + logsize + 1;
event->Size = event_size;
CopyMem(event->Event, (VOID *)log, logsize);
if (hash) {
/* TPM 2 systems will generate the appropriate hash
Expand Down

0 comments on commit 8a27a48

Please sign in to comment.