- Rebase to edk2-stable202508 [RHEL-111718] - Resolves: RHEL-111718 ([edk2,rhel-10] rebase to edk2-stable202508)
151 lines
5.5 KiB
Diff
151 lines
5.5 KiB
Diff
From f959d0c58a7f9c8e8b2155a145328fec5cab1edf Mon Sep 17 00:00:00 2001
|
|
From: Phil Noh <Phil.Noh@amd.com>
|
|
Date: Fri, 5 Sep 2025 15:11:15 -0500
|
|
Subject: [PATCH] SecurityPkg/Tpm2DeviceLibDTpm: Remove global variable for
|
|
command code
|
|
|
|
As a BASE type library, currently the TCG PEI driver, Tcg2Pei.inf links
|
|
the library. On edk2-stable202508 version, it is found that the driver
|
|
includes and updates the global variable of mLastCommandSent in debug
|
|
build. Also found that the previous commit (460f270) for the library adds
|
|
and uses the global variable. Updating the global variable in PEI drivers
|
|
could affect the following issues. To address these issues, remove the
|
|
global variable usage.
|
|
|
|
PEI ROM Boot : Global variable is not updated
|
|
PEI RAM Boot : PEI FV integration/security check is failed
|
|
|
|
Signed-off-by: Phil Noh <Phil.Noh@amd.com>
|
|
---
|
|
.../Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmDump.c | 13 +++++--------
|
|
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c | 9 ++++++++-
|
|
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.h | 4 +++-
|
|
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Tis.c | 9 ++++++++-
|
|
4 files changed, 24 insertions(+), 11 deletions(-)
|
|
|
|
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmDump.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmDump.c
|
|
index 7b2e449130..56a9684299 100644
|
|
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmDump.c
|
|
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmDump.c
|
|
@@ -218,8 +218,6 @@ TPM2_CODE_STRING ResponseCodeStrings[] = {
|
|
};
|
|
UINTN ResponseCodeStringsCount = sizeof (ResponseCodeStrings) / sizeof (ResponseCodeStrings[0]);
|
|
|
|
-UINT32 mLastCommandSent = 0;
|
|
-
|
|
/**
|
|
This simple function will dump up to MAX_TPM_BUFFER_DUMP bytes
|
|
of a TPM data buffer and apppend '...' if buffer is larger.
|
|
@@ -678,9 +676,6 @@ DumpTpmInputBlock (
|
|
// If verbose, dump all of the buffer contents for deeper analysis.
|
|
DumpTpmBuffer ("DATA: ", MIN (InputBlockSize, NativeSize), InputBlock);
|
|
|
|
- // Update the last command sent so that response parsing can have some context.
|
|
- mLastCommandSent = NativeCode;
|
|
-
|
|
return;
|
|
}
|
|
|
|
@@ -690,13 +685,15 @@ DumpTpmInputBlock (
|
|
|
|
@param[in] OutputBlockSize Size of the output buffer.
|
|
@param[in] OutputBlock Pointer to the output buffer itself.
|
|
+ @param[in] CommandCode Command code for the input block.
|
|
|
|
**/
|
|
VOID
|
|
EFIAPI
|
|
DumpTpmOutputBlock (
|
|
IN UINT32 OutputBlockSize,
|
|
- IN CONST UINT8 *OutputBlock
|
|
+ IN CONST UINT8 *OutputBlock,
|
|
+ IN UINT32 CommandCode
|
|
)
|
|
{
|
|
CONST TPM2_RESPONSE_HEADER *RespHeader;
|
|
@@ -716,8 +713,8 @@ DumpTpmOutputBlock (
|
|
DEBUG ((DEBUG_SECURITY, "Size: %d (0x%X)\n", NativeSize, NativeSize));
|
|
|
|
// Debug anything else based on the Command context.
|
|
- if (mLastCommandSent != 0x00) {
|
|
- switch (mLastCommandSent) {
|
|
+ if (CommandCode != 0x00) {
|
|
+ switch (CommandCode) {
|
|
case TPM_CC_StartAuthSession:
|
|
DumpTpmStartAuthSessionResponse (OutputBlockSize, OutputBlock);
|
|
break;
|
|
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
|
|
index d3054690e2..dc67786736 100644
|
|
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
|
|
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
|
|
@@ -162,6 +162,7 @@ PtpCrbTpmCommand (
|
|
UINT16 Data16;
|
|
UINT32 Data32;
|
|
UINT8 RetryCnt;
|
|
+ UINT32 CommandCode;
|
|
|
|
DEBUG_CODE_BEGIN ();
|
|
DumpTpmInputBlock (SizeIn, BufferIn);
|
|
@@ -336,7 +337,13 @@ PtpCrbTpmCommand (
|
|
}
|
|
|
|
DEBUG_CODE_BEGIN ();
|
|
- DumpTpmOutputBlock (TpmOutSize, BufferOut);
|
|
+ if (SizeIn >= sizeof (TPM2_COMMAND_HEADER)) {
|
|
+ CommandCode = SwapBytes32 (((TPM2_COMMAND_HEADER *)BufferIn)->commandCode);
|
|
+ } else {
|
|
+ CommandCode = 0;
|
|
+ }
|
|
+
|
|
+ DumpTpmOutputBlock (TpmOutSize, BufferOut, CommandCode);
|
|
DEBUG_CODE_END ();
|
|
|
|
//
|
|
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.h b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.h
|
|
index 8b7c37bb9b..7061414040 100644
|
|
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.h
|
|
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.h
|
|
@@ -73,12 +73,14 @@ DumpTpmInputBlock (
|
|
a response from the TPM for maximum user-readability.
|
|
@param[in] OutputBlockSize Size of the output buffer.
|
|
@param[in] OutputBlock Pointer to the output buffer itself.
|
|
+ @param[in] CommandCode Command code for the input block.
|
|
**/
|
|
VOID
|
|
EFIAPI
|
|
DumpTpmOutputBlock (
|
|
IN UINT32 OutputBlockSize,
|
|
- IN CONST UINT8 *OutputBlock
|
|
+ IN CONST UINT8 *OutputBlock,
|
|
+ IN UINT32 CommandCode
|
|
);
|
|
|
|
#endif // TPM2_PTP_H_
|
|
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Tis.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Tis.c
|
|
index d2f0abd160..1e141c9272 100644
|
|
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Tis.c
|
|
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Tis.c
|
|
@@ -223,6 +223,7 @@ Tpm2TisTpmCommand (
|
|
UINT32 TpmOutSize;
|
|
UINT16 Data16;
|
|
UINT32 Data32;
|
|
+ UINT32 CommandCode;
|
|
|
|
DEBUG_CODE_BEGIN ();
|
|
DumpTpmInputBlock (SizeIn, BufferIn);
|
|
@@ -370,7 +371,13 @@ Tpm2TisTpmCommand (
|
|
|
|
Exit:
|
|
DEBUG_CODE_BEGIN ();
|
|
- DumpTpmOutputBlock (TpmOutSize, BufferOut);
|
|
+ if (SizeIn >= sizeof (TPM2_COMMAND_HEADER)) {
|
|
+ CommandCode = SwapBytes32 (((TPM2_COMMAND_HEADER *)BufferIn)->commandCode);
|
|
+ } else {
|
|
+ CommandCode = 0;
|
|
+ }
|
|
+
|
|
+ DumpTpmOutputBlock (TpmOutSize, BufferOut, CommandCode);
|
|
DEBUG_CODE_END ();
|
|
MmioWrite8 ((UINTN)&TisReg->Status, TIS_PC_STS_READY);
|
|
return Status;
|