From 0bb4cf0228fce0b6aaedc0bfc1d79147aebf16f3 Mon Sep 17 00:00:00 2001 From: Dionna Glaze Date: Mon, 12 May 2025 14:39:03 +0000 Subject: [PATCH] SecurityPkg: Clarify Is800155Event The Event3 memory comparison is technically correct since the definitions of the struct types are the same. The extended bodies of the events are different. The Event2 size guard for the Event3 comparison should be split to use the Event3 in its sizeof for better clarity. The large single condition makes the function difficult to understand, so the combined logic is split into different conditional statements. Signed-off-by: Dionna Glaze [ardb: whitespace fixes] Signed-off-by: Ard Biesheuvel --- SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c | 33 ++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c index 24a27cd6f3..85a852842d 100644 --- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c +++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c @@ -798,6 +798,7 @@ Tcg2GetEventLog ( @retval FALSE This is NOT a Tcg800155PlatformIdEvent. **/ +STATIC BOOLEAN Is800155Event ( IN VOID *NewEventHdr, @@ -806,18 +807,26 @@ Is800155Event ( IN UINT32 NewEventSize ) { - if ((((TCG_PCR_EVENT2_HDR *)NewEventHdr)->EventType == EV_NO_ACTION) && - (NewEventSize >= sizeof (TCG_Sp800_155_PlatformId_Event2)) && - ((CompareMem ( - NewEventData, - TCG_Sp800_155_PlatformId_Event2_SIGNATURE, - sizeof (TCG_Sp800_155_PlatformId_Event2_SIGNATURE) - 1 - ) == 0) || - (CompareMem ( - NewEventData, - TCG_Sp800_155_PlatformId_Event3_SIGNATURE, - sizeof (TCG_Sp800_155_PlatformId_Event3_SIGNATURE) - 1 - ) == 0))) + if (((TCG_PCR_EVENT2_HDR *)NewEventHdr)->EventType != EV_NO_ACTION) { + return FALSE; + } + + if ((NewEventSize >= sizeof (TCG_Sp800_155_PlatformId_Event2)) && + (CompareMem ( + NewEventData, + TCG_Sp800_155_PlatformId_Event2_SIGNATURE, + sizeof (TCG_Sp800_155_PlatformId_Event2_SIGNATURE) - 1 + ) == 0)) + { + return TRUE; + } + + if ((NewEventSize >= sizeof (TCG_Sp800_155_PlatformId_Event3)) && + (CompareMem ( + NewEventData, + TCG_Sp800_155_PlatformId_Event3_SIGNATURE, + sizeof (TCG_Sp800_155_PlatformId_Event3_SIGNATURE) - 1 + ) == 0)) { return TRUE; }