From: Zhihao Li <zhihao...@intel.com> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3855
In UefiCpuPkg, there are a new Protocol with the new service SmmWaitForAllProcessor(), which can be used by SMI handler to optionally wait for other APs to complete SMM rendezvous in relaxed AP mode. This patch use the new service to let TcgSmm and Tcg2Smm driver work normally in relaxed AP mode. Cc: Jiewen Yao <jiewen....@intel.com> Cc: Jian J Wang <jian.j.w...@intel.com> Cc: Rahul Kumar <rahul1.ku...@intel.com> Cc: Qi Zhang <qi1.zh...@intel.com> Signed-off-by: Zhihao Li <zhihao...@intel.com> --- SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c | 21 ++++++++++++++++++-- SecurityPkg/Tcg/TcgSmm/TcgSmm.c | 15 ++++++++++++-- SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h | 3 ++- SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf | 3 ++- SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf | 1 + SecurityPkg/Tcg/TcgSmm/TcgSmm.h | 3 ++- SecurityPkg/Tcg/TcgSmm/TcgSmm.inf | 3 ++- 7 files changed, 41 insertions(+), 8 deletions(-) diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c index 498fb626bd9c..4367102fbd49 100644 --- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c +++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c @@ -9,7 +9,7 @@ PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check. -Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR> Copyright (c) Microsoft Corporation. SPDX-License-Identifier: BSD-2-Clause-Patent @@ -42,6 +42,7 @@ EFI_HANDLE mReadyToLockHandle; should still be called. @retval EFI_UNSUPPORTED An unknown test function was requested. @retval EFI_ACCESS_DENIED Part of the communication buffer lies in an invalid region. + @retval EFI_ABORTED Fail to wait for all AP check in SMM. **/ EFI_STATUS @@ -78,6 +79,11 @@ TpmNvsCommunciate ( return EFI_ACCESS_DENIED; } + if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) { + DEBUG ((DEBUG_ERROR, "TpmNvsCommunciate: fail to wait for all AP check in SMM!\n")); + return EFI_ABORTED; + } + // // Farm out the job to individual functions based on what was requested. // @@ -116,7 +122,7 @@ TpmNvsCommunciate ( @param[in, out] CommBufferSize The size of the CommBuffer. @retval EFI_SUCCESS The interrupt was handled successfully. - + @retval EFI_ABORTED Fail to wait for all AP check in SMM. **/ EFI_STATUS EFIAPI @@ -132,6 +138,11 @@ PhysicalPresenceCallback ( UINT32 OperationRequest; UINT32 RequestParameter; + if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) { + DEBUG ((DEBUG_ERROR, "TpmPhysicalPresent: fail to wait for all AP check in SMM!\n")); + return EFI_ABORTED; + } + if (mTcgNvs->PhysicalPresence.Parameter == TCG_ACPI_FUNCTION_RETURN_REQUEST_RESPONSE_TO_OS) { mTcgNvs->PhysicalPresence.ReturnCode = Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction ( &MostRecentRequest, @@ -173,6 +184,7 @@ PhysicalPresenceCallback ( @param[in, out] CommBufferSize The size of the CommBuffer. @retval EFI_SUCCESS The interrupt was handled successfully. + @retval EFI_ABORTED Fail to wait for all AP check in SMM. **/ EFI_STATUS @@ -217,6 +229,11 @@ MemoryClearCallback ( return EFI_SUCCESS; } + if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) { + DEBUG ((DEBUG_ERROR, "TpmMemoryClear: fail to wait for all AP check in SMM!\n")); + return EFI_ABORTED; + } + DataSize = sizeof (UINT8); Status = mSmmVariable->SmmSetVariable ( MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, diff --git a/SecurityPkg/Tcg/TcgSmm/TcgSmm.c b/SecurityPkg/Tcg/TcgSmm/TcgSmm.c index 96327a483ba9..e91567ca3169 100644 --- a/SecurityPkg/Tcg/TcgSmm/TcgSmm.c +++ b/SecurityPkg/Tcg/TcgSmm/TcgSmm.c @@ -8,7 +8,7 @@ PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check. -Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -33,7 +33,7 @@ TCG_NVS *mTcgNvs; @param[in, out] CommBufferSize The size of the CommBuffer. @retval EFI_SUCCESS The interrupt was handled successfully. - + @retval EFI_ABORTED Fail to wait for all AP check in SMM. **/ EFI_STATUS EFIAPI @@ -92,6 +92,11 @@ PhysicalPresenceCallback ( return EFI_SUCCESS; } + if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) { + DEBUG ((DEBUG_ERROR, "TPMPhysicalPresent: fail to wait for all AP check in SMM!\n")); + return EFI_ABORTED; + } + if (PpData.PPRequest != mTcgNvs->PhysicalPresence.Request) { PpData.PPRequest = (UINT8)mTcgNvs->PhysicalPresence.Request; DataSize = sizeof (EFI_PHYSICAL_PRESENCE); @@ -238,6 +243,7 @@ PhysicalPresenceCallback ( @param[in, out] CommBufferSize The size of the CommBuffer. @retval EFI_SUCCESS The interrupt was handled successfully. + @retval EFI_ABORTED Fail to wait for all AP check in SMM. **/ EFI_STATUS @@ -282,6 +288,11 @@ MemoryClearCallback ( return EFI_SUCCESS; } + if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) { + DEBUG ((DEBUG_ERROR, " TpmMemoryClear: fail to wait for all AP check in SMM!\n")); + return EFI_ABORTED; + } + DataSize = sizeof (UINT8); Status = mSmmVariable->SmmSetVariable ( MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h index 84b65eb0897c..c0c0e9d91aeb 100644 --- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h +++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h @@ -1,7 +1,7 @@ /** @file The header file for Tcg2 SMM driver. -Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR> Copyright (c) Microsoft Corporation. SPDX-License-Identifier: BSD-2-Clause-Patent @@ -31,6 +31,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/IoLib.h> #include <Library/PcdLib.h> #include <Library/Tpm2DeviceLib.h> +#include <Library/SmmCpuRendezvousLib.h> #include <IndustryStandard/TpmPtp.h> diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf index 096338d0ef47..10b0629d506b 100644 --- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf +++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf @@ -20,7 +20,7 @@ # This driver will have external input - variable and ACPINvs data in SMM mode. # This external input must be validated carefully to avoid security issue. # -# Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR> # Copyright (c) Microsoft Corporation.<BR> # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -59,6 +59,7 @@ [LibraryClasses] Tcg2PhysicalPresenceLib PcdLib SmmMemLib + SmmCpuRendezvousLib [Guids] ## SOMETIMES_PRODUCES ## Variable:L"MemoryOverwriteRequestControl" diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf b/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf index 746eda3e9fed..6cf74803a12d 100644 --- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf +++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf @@ -55,6 +55,7 @@ [LibraryClasses] Tcg2PhysicalPresenceLib PcdLib MemLib + SmmCpuRendezvousLib [Guids] ## SOMETIMES_PRODUCES ## Variable:L"MemoryOverwriteRequestControl" diff --git a/SecurityPkg/Tcg/TcgSmm/TcgSmm.h b/SecurityPkg/Tcg/TcgSmm/TcgSmm.h index e348ad105499..dcc85ee3efbc 100644 --- a/SecurityPkg/Tcg/TcgSmm/TcgSmm.h +++ b/SecurityPkg/Tcg/TcgSmm/TcgSmm.h @@ -1,7 +1,7 @@ /** @file The header file for TCG SMM driver. -Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -31,6 +31,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/TpmMeasurementLib.h> #include <Library/PcdLib.h> #include <Library/TcgPpVendorLib.h> +#include <Library/SmmCpuRendezvousLib.h> #pragma pack(1) typedef struct { diff --git a/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf b/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf index 9fac896dde8b..1d0f1c9170d4 100644 --- a/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf +++ b/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf @@ -9,7 +9,7 @@ # This driver will have external input - variable and ACPINvs data in SMM mode. # This external input must be validated carefully to avoid security issue. # -# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.<BR> # Copyright (c) Microsoft Corporation.<BR> # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -46,6 +46,7 @@ [LibraryClasses] TpmMeasurementLib PcdLib TcgPpVendorLib + SmmCpuRendezvousLib [Guids] ## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresence" -- 2.26.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#90614): https://edk2.groups.io/g/devel/message/90614 Mute This Topic: https://groups.io/mt/91873299/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-