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

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