Blame SOURCES/0037-tpm-Fix-off-by-one-error-when-calculating-event-size.patch

d1e1c8
From 6fd8db6bb3b23b9e41f109135253f77263071f46 Mon Sep 17 00:00:00 2001
d1e1c8
From: Chris Coulson <chris.coulson@canonical.com>
d1e1c8
Date: Sat, 22 Jun 2019 15:33:03 +0100
d1e1c8
Subject: [PATCH 37/62] tpm: Fix off-by-one error when calculating event size
d1e1c8
d1e1c8
tpm_log_event_raw() allocates a buffer for the EFI_TCG2_EVENT structure
d1e1c8
that is one byte larger than necessary, and sets event->Size accordingly.
d1e1c8
The result of this is that the event data recorded in the log differs
d1e1c8
from the data that is measured to the TPM (it has an extra zero byte
d1e1c8
at the end).
d1e1c8
d1e1c8
Upstream-commit-id: 8a27a4809a6
d1e1c8
---
d1e1c8
 tpm.c | 6 ++++--
d1e1c8
 1 file changed, 4 insertions(+), 2 deletions(-)
d1e1c8
d1e1c8
diff --git a/tpm.c b/tpm.c
d1e1c8
index f07362c70bb..516fb876caa 100644
d1e1c8
--- a/tpm.c
d1e1c8
+++ b/tpm.c
d1e1c8
@@ -131,8 +131,10 @@ static EFI_STATUS tpm_log_event_raw(EFI_PHYSICAL_ADDRESS buf, UINTN size,
d1e1c8
 #endif
d1e1c8
 	} else if (tpm2) {
d1e1c8
 		EFI_TCG2_EVENT *event;
d1e1c8
+		UINTN event_size = sizeof(*event) - sizeof(event->Event) +
d1e1c8
+			logsize;
d1e1c8
 
d1e1c8
-		event = AllocatePool(sizeof(*event) + logsize);
d1e1c8
+		event = AllocatePool(event_size);
d1e1c8
 		if (!event) {
d1e1c8
 			perror(L"Unable to allocate event structure\n");
d1e1c8
 			return EFI_OUT_OF_RESOURCES;
d1e1c8
@@ -142,7 +144,7 @@ static EFI_STATUS tpm_log_event_raw(EFI_PHYSICAL_ADDRESS buf, UINTN size,
d1e1c8
 		event->Header.HeaderVersion = 1;
d1e1c8
 		event->Header.PCRIndex = pcr;
d1e1c8
 		event->Header.EventType = type;
d1e1c8
-		event->Size = sizeof(*event) - sizeof(event->Event) + logsize + 1;
d1e1c8
+		event->Size = event_size;
d1e1c8
 		CopyMem(event->Event, (VOID *)log, logsize);
d1e1c8
 		if (hash) {
d1e1c8
 			/* TPM 2 systems will generate the appropriate hash
d1e1c8
-- 
d1e1c8
2.26.2
d1e1c8