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

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