Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cherry-Pick] Tcg2Smm: Added support for Standalone Mm [RB&FF] #351

Merged
33 changes: 33 additions & 0 deletions SecurityPkg/Include/Guid/Tcg2AcpiCommunicateBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/** @file
This Tcg2 Acpi Communicate Buffer HOB is used to store the address
of a buffer reserved for Tcg2Acpi driver. The buffer will be used to
retrive information from standalone mm environment.

Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#ifndef TCG2_ACPI_COMMUNICATE_BUFFER_H_
#define TCG2_ACPI_COMMUNICATE_BUFFER_H_

#define TCG2_ACPI_COMMUNICATE_BUFFER_HOB_REVISION 1

#define TCG2_ACPI_COMMUNICATE_BUFFER_GUID \
{ \
0xcefea14f, 0x9f1a, 0x4774, {0x8d, 0x18, 0x79, 0x93, 0x8d, 0x48, 0xfe, 0x7d} \
}

typedef struct {
///
/// Base address of the buffer reserved for Tcg2Acpi driver.
/// Tcg2Acpi will use it to exchange information with Tcg2StandaloneMm.
///
EFI_PHYSICAL_ADDRESS Tcg2AcpiCommunicateBuffer;
UINT64 Pages;
} TCG2_ACPI_COMMUNICATE_BUFFER;

extern EFI_GUID gEdkiiTcg2AcpiCommunicateBufferHobGuid;

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,12 @@
Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction() and Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction()
will receive untrusted input and do validation.

Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2015 - 2024, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include <PiMm.h>

#include <Guid/Tcg2PhysicalPresenceData.h>

#include <Protocol/SmmVariable.h>

#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/Tcg2PpVendorLib.h>
#include <Library/MmServicesTableLib.h>

#define PP_INF_VERSION_1_2 "1.2"
#include "MmTcg2PhysicalPresenceLibCommon.h"

EFI_SMM_VARIABLE_PROTOCOL *mTcg2PpSmmVariable;
BOOLEAN mIsTcg2PPVerLowerThan_1_3 = FALSE;
Expand Down Expand Up @@ -407,9 +395,7 @@ Tcg2PhysicalPresenceLibCommonConstructor (
{
EFI_STATUS Status;

if (AsciiStrnCmp (PP_INF_VERSION_1_2, (CHAR8 *)PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer), sizeof (PP_INF_VERSION_1_2) - 1) >= 0) {
mIsTcg2PPVerLowerThan_1_3 = TRUE;
}
mIsTcg2PPVerLowerThan_1_3 = IsTcg2PPVerLowerThan_1_3 ();

//
// Locate SmmVariableProtocol.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,26 @@
Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction() and Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction()
will receive untrusted input and do validation.

Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2015 - 2024, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#ifndef _MM_TCG2_PHYSICAL_PRESENCE_LIB_COMMON_H_
#define _MM_TCG2_PHYSICAL_PRESENCE_LIB_COMMON_H_

#include <Guid/Tcg2PhysicalPresenceData.h>

#include <Protocol/SmmVariable.h>

#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/Tcg2PpVendorLib.h>
#include <Library/MmServicesTableLib.h>

#define PP_INF_VERSION_1_2 "1.2"

/**
The constructor function locates MmVariable protocol.

Expand All @@ -31,4 +43,15 @@ Tcg2PhysicalPresenceLibCommonConstructor (
VOID
);

/**
Check if Tcg2 PP version is lower than PP_INF_VERSION_1_3.

@retval TRUE Tcg2 PP version is lower than PP_INF_VERSION_1_3.
@retval Other Tcg2 PP version is not lower than PP_INF_VERSION_1_3.
**/
BOOLEAN
IsTcg2PPVerLowerThan_1_3 (
VOID
);

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction() and Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction()
will receive untrusted input and do validation.

Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2015 - 2024, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/
Expand Down Expand Up @@ -39,3 +39,17 @@ Tcg2PhysicalPresenceLibTraditionalConstructor (
{
return Tcg2PhysicalPresenceLibCommonConstructor ();
}

/**
Check if Tcg2 PP version is lower than PP_INF_VERSION_1_3.

@retval TRUE Tcg2 PP version is lower than PP_INF_VERSION_1_3.
@retval Other Tcg2 PP version is not lower than PP_INF_VERSION_1_3.
**/
BOOLEAN
IsTcg2PPVerLowerThan_1_3 (
VOID
)
{
return (BOOLEAN)(AsciiStrnCmp (PP_INF_VERSION_1_2, (CHAR8 *)PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer), sizeof (PP_INF_VERSION_1_2) - 1) >= 0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction() and Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction()
will receive untrusted input and do validation.

Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2015 - 2024, Intel Corporation. All rights reserved.<BR>
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include <PiMm.h>

#include <Library/HobLib.h>

#include "MmTcg2PhysicalPresenceLibCommon.h"

/**
Expand All @@ -40,3 +42,26 @@ Tcg2PhysicalPresenceLibStandaloneMmConstructor (
{
return Tcg2PhysicalPresenceLibCommonConstructor ();
}

/**
Check if Tcg2 PP version is lower than PP_INF_VERSION_1_3.

@retval TRUE Tcg2 PP version is lower than PP_INF_VERSION_1_3.
@retval Other Tcg2 PP version is not lower than PP_INF_VERSION_1_3.
**/
BOOLEAN
IsTcg2PPVerLowerThan_1_3 (
VOID
)
{
VOID *GuidHob;

GuidHob = GetFirstGuidHob (&gEdkiiTcgPhysicalPresenceInterfaceVerHobGuid);
ASSERT (GuidHob != NULL);

if (AsciiStrnCmp (PP_INF_VERSION_1_2, (CHAR8 *)GET_GUID_HOB_DATA (GuidHob), sizeof (PP_INF_VERSION_1_2) - 1) >= 0) {
return TRUE;
}

return FALSE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# This driver will have external input - variable.
# This external input must be validated carefully to avoid security issue.
#
# Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2015 - 2024, Intel Corporation. All rights reserved.<BR>
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
Expand Down Expand Up @@ -44,18 +44,19 @@
Tcg2PpVendorLib
MmServicesTableLib
BaseMemoryLib
HobLib

[Guids]
## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresence"
## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresence"
## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresenceFlags"
gEfiTcg2PhysicalPresenceGuid
gEdkiiTcgPhysicalPresenceInterfaceVerHobGuid

[Protocols]
gEfiSmmVariableProtocolGuid ## CONSUMES

[Pcd]
gEfiSecurityPkgTokenSpaceGuid.PcdTcgPhysicalPresenceInterfaceVer ## CONSUMES
gEfiSecurityPkgTokenSpaceGuid.PcdTcg2PhysicalPresenceFlags ## SOMETIMES_CONSUMES
gEfiSecurityPkgTokenSpaceGuid.PcdDisallowPPIPersistentClearPermissions ## CONSUMES # MU_CHANGE 108842

Expand Down
11 changes: 11 additions & 0 deletions SecurityPkg/SecurityPkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,17 @@
## GUID used to generate Spdm Uid
gEfiDeviceSecuritySpdmUidGuid = {0xe37b5665, 0x5ef9, 0x4e7e, {0xb4, 0x91, 0xd6, 0x78, 0xab, 0xff, 0xfb, 0xcb }}

## GUID used to tag the HOB indicating the TPM instance.
## The GUIDed HOB contains the same value as PcdGetPtr (PcdTpmInstanceGuid).
gEdkiiTpmInstanceHobGuid = { 0x4551b023, 0xba46, 0x4584, { 0x81, 0xcd, 0x4d, 0xe8, 0x61, 0xa7, 0x28, 0xbe } }

## GUID used to tag the HOB indicating the Version of Physical Presence interface.
## The GUIDed HOB contains the same value as PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer).
gEdkiiTcgPhysicalPresenceInterfaceVerHobGuid = { 0x3979411a, 0x4e6d, 0x47e4, { 0x94, 0x4b, 0x0e, 0xcc, 0x6c, 0xf6, 0xc0, 0xcd } }

## Include/Guid/Tcg2AcpiCommunicateBuffer.h
gEdkiiTcg2AcpiCommunicateBufferHobGuid = { 0xcefea14f, 0x9f1a, 0x4774, { 0x8d, 0x18, 0x79, 0x93, 0x8d, 0x48, 0xfe, 0x7d } }

[Protocols]
## MU_CHANGE - START - Add a new protocol to support Log-only events.
# Include/Protocol/MuTcg2Protocol.h
Expand Down
28 changes: 15 additions & 13 deletions SecurityPkg/Tcg/Tcg2Acpi/Tcg2Acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2015 - 2024, Intel Corporation. All rights reserved.<BR>
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent

Expand All @@ -22,6 +22,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Guid/TpmInstance.h>
#include <Guid/TpmNvsMm.h>
#include <Guid/PiSmmCommunicationRegionTable.h>
#include <Guid/Tcg2AcpiCommunicateBuffer.h>

#include <Protocol/AcpiTable.h>
#include <Protocol/Tcg2Protocol.h>
Expand All @@ -38,7 +39,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/Tpm2DeviceLib.h>
#include <Library/Tpm2CommandLib.h>
#include <Library/UefiLib.h>
#include <Library/MmUnblockMemoryLib.h>
#include <Library/HobLib.h>

//
// Physical Presence Interface Version supported by Platform
Expand Down Expand Up @@ -116,7 +117,7 @@ TCG_NVS *mTcgNvs;
@param[in] Name The name string to find in TPM table.
@param[in] Size The size of the region to find.

@return The allocated address for the found region.
@return The Acpi Communicate Buffer for the found region.

**/
VOID *
Expand All @@ -126,9 +127,10 @@ AssignOpRegion (
UINT16 Size
)
{
EFI_STATUS Status;
AML_OP_REGION_32_8 *OpRegion;
EFI_PHYSICAL_ADDRESS MemoryAddress;
AML_OP_REGION_32_8 *OpRegion;
EFI_PHYSICAL_ADDRESS MemoryAddress;
EFI_HOB_GUID_TYPE *GuidHob;
TCG2_ACPI_COMMUNICATE_BUFFER *Tcg2AcpiCommunicateBufferHob;

MemoryAddress = SIZE_4GB - 1;

Expand All @@ -144,16 +146,16 @@ AssignOpRegion (
(OpRegion->DWordPrefix == AML_DWORD_PREFIX) &&
(OpRegion->BytePrefix == AML_BYTE_PREFIX))
{
Status = gBS->AllocatePages (AllocateMaxAddress, EfiACPIMemoryNVS, EFI_SIZE_TO_PAGES (Size), &MemoryAddress);
ASSERT_EFI_ERROR (Status);
GuidHob = GetFirstGuidHob (&gEdkiiTcg2AcpiCommunicateBufferHobGuid);
ASSERT (GuidHob != NULL);
Tcg2AcpiCommunicateBufferHob = GET_GUID_HOB_DATA (GuidHob);
MemoryAddress = Tcg2AcpiCommunicateBufferHob->Tcg2AcpiCommunicateBuffer;
ASSERT (MemoryAddress != 0);
ASSERT (EFI_PAGES_TO_SIZE (Tcg2AcpiCommunicateBufferHob->Pages) >= Size);

ZeroMem ((VOID *)(UINTN)MemoryAddress, Size);
OpRegion->RegionOffset = (UINT32)(UINTN)MemoryAddress;
OpRegion->RegionLen = (UINT8)Size;
// Request to unblock this region from MM core
Status = MmUnblockMemoryRequest (MemoryAddress, EFI_SIZE_TO_PAGES (Size));
if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
ASSERT_EFI_ERROR (Status);
}

break;
}
Expand Down
5 changes: 3 additions & 2 deletions SecurityPkg/Tcg/Tcg2Acpi/Tcg2Acpi.inf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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 - 2024, Intel Corporation. All rights reserved.<BR>
# Copyright (c) Microsoft Corporation.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
Expand Down Expand Up @@ -57,12 +57,13 @@
Tpm2CommandLib
Tcg2PhysicalPresenceLib
PcdLib
MmUnblockMemoryLib
HobLib

[Guids]
gEfiTpmDeviceInstanceTpm20DtpmGuid ## PRODUCES ## GUID # TPM device identifier
gTpmNvsMmGuid ## CONSUMES
gEdkiiPiSmmCommunicationRegionTableGuid ## CONSUMES
gEdkiiTcg2AcpiCommunicateBufferHobGuid

[Protocols]
gEfiAcpiTableProtocolGuid ## CONSUMES
Expand Down
9 changes: 8 additions & 1 deletion SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This module initializes TPM device type based on variable and detection.
# NOTE: This module is only for reference only, each platform should have its own setup page.
#
# Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2015 - 2024, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
Expand Down Expand Up @@ -46,22 +46,29 @@
TimerLib
Tpm12CommandLib
Tpm12DeviceLib
HobLib
MmUnblockMemoryLib

[Guids]
## SOMETIMES_CONSUMES ## Variable:L"TCG2_CONFIGURATION"
## SOMETIMES_CONSUMES ## Variable:L"TCG2_DEVICE_DETECTION"
gTcg2ConfigFormSetGuid
gEfiTpmDeviceSelectedGuid ## PRODUCES ## GUID # Used as a PPI GUID
gEfiTpmDeviceInstanceNoneGuid ## SOMETIMES_CONSUMES ## GUID # TPM device identifier
gEdkiiTpmInstanceHobGuid
gEdkiiTcgPhysicalPresenceInterfaceVerHobGuid
gEdkiiTcg2AcpiCommunicateBufferHobGuid

[Ppis]
gEfiPeiReadOnlyVariable2PpiGuid ## CONSUMES
gPeiTpmInitializationDonePpiGuid ## SOMETIMES_PRODUCES
gEfiPeiMemoryDiscoveredPpiGuid

[Pcd]
gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid ## PRODUCES
gEfiSecurityPkgTokenSpaceGuid.PcdTpmInitializationPolicy ## PRODUCES
gEfiSecurityPkgTokenSpaceGuid.PcdTpmAutoDetection ## CONSUMES
gEfiSecurityPkgTokenSpaceGuid.PcdTcgPhysicalPresenceInterfaceVer

[Depex]
gEfiPeiMasterBootModePpiGuid AND
Expand Down
Loading
Loading