diff options
author | Kun Qin <kun.q@outlook.com> | 2021-03-04 20:14:13 -0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2021-03-05 15:25:07 +0000 |
commit | 3c2dc30d1bc45eeef68d7d0e056a4b3928015ec0 (patch) | |
tree | 722124b196af109bd7e1fc6a0c309eb1ca2370a1 /SecurityPkg/Tcg/Tcg2Smm | |
parent | e2d6833c114766c8e69647f753d8eb73212cb434 (diff) | |
download | edk2-3c2dc30d1bc45eeef68d7d0e056a4b3928015ec0.tar.gz edk2-3c2dc30d1bc45eeef68d7d0e056a4b3928015ec0.tar.bz2 edk2-3c2dc30d1bc45eeef68d7d0e056a4b3928015ec0.zip |
SecurityPkg: Tcg2Smm: Separate Tcg2Smm into 2 modules
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3169
This change separated the original Tcg2Smm module into 2 drivers: the
SMM driver that registers callback for physical presence and memory
clear; the Tcg2Acpi driver that patches and publishes ACPI table for
runtime use.
Tcg2Smm introduced an SMI root handler to allow Tcg2Acpi to communicate
the NVS region used by Tpm.asl and exchange the registered SwSmiValue.
Lastly, Tcg2Smm driver will publish gTcg2MmSwSmiRegisteredGuid at the end
of entrypoint to ensure Tcg2Acpi to load after Tcg2Smm is ready to
communicate.
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Qi Zhang <qi1.zhang@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
Message-Id: <MWHPR06MB310295CC623EF7C062844DFFF3969@MWHPR06MB3102.namprd06.prod.outlook.com>
Diffstat (limited to 'SecurityPkg/Tcg/Tcg2Smm')
-rw-r--r-- | SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c | 853 | ||||
-rw-r--r-- | SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h | 113 | ||||
-rw-r--r-- | SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf | 25 | ||||
-rw-r--r-- | SecurityPkg/Tcg/Tcg2Smm/Tcg2TraditionalMm.c | 82 | ||||
-rw-r--r-- | SecurityPkg/Tcg/Tcg2Smm/Tpm.asl | 517 |
5 files changed, 286 insertions, 1304 deletions
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c index 08105c3692..589c08794b 100644 --- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c +++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c @@ -10,47 +10,95 @@ PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check.
Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Tcg2Smm.h"
-#pragma pack(1)
-
-typedef struct {
- EFI_ACPI_DESCRIPTION_HEADER Header;
- // Flags field is replaced in version 4 and above
- // BIT0~15: PlatformClass This field is only valid for version 4 and above
- // BIT16~31: Reserved
- UINT32 Flags;
- UINT64 AddressOfControlArea;
- UINT32 StartMethod;
- UINT8 PlatformSpecificParameters[12]; // size up to 12
- UINT32 Laml; // Optional
- UINT64 Lasa; // Optional
-} EFI_TPM2_ACPI_TABLE_V4;
-
-#pragma pack()
-
-EFI_TPM2_ACPI_TABLE_V4 mTpm2AcpiTemplate = {
- {
- EFI_ACPI_5_0_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE,
- sizeof (mTpm2AcpiTemplate),
- EFI_TPM2_ACPI_TABLE_REVISION,
- //
- // Compiler initializes the remaining bytes to 0
- // These fields should be filled in in production
- //
- },
- 0, // BIT0~15: PlatformClass
- // BIT16~31: Reserved
- 0, // Control Area
- EFI_TPM2_ACPI_TABLE_START_METHOD_TIS, // StartMethod
-};
-
-EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable;
-TCG_NVS *mTcgNvs;
+EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable = NULL;
+TCG_NVS *mTcgNvs = NULL;
+UINTN mPpSoftwareSmi;
+UINTN mMcSoftwareSmi;
+EFI_HANDLE mReadyToLockHandle;
+
+/**
+ Communication service SMI Handler entry.
+
+ This handler takes requests to exchange Mmi channel and Nvs address between MM and DXE.
+
+ Caution: This function may receive untrusted input.
+ Communicate buffer and buffer size are external input, so this function will do basic validation.
+
+ @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
+ @param[in] RegisterContext Points to an optional handler context which was specified when the
+ handler was registered.
+ @param[in, out] CommBuffer A pointer to a collection of data in memory that will
+ be conveyed from a non-SMM environment into an SMM environment.
+ @param[in, out] CommBufferSize The size of the CommBuffer.
+
+ @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers
+ 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.
+
+**/
+EFI_STATUS
+EFIAPI
+TpmNvsCommunciate (
+ IN EFI_HANDLE DispatchHandle,
+ IN CONST VOID *RegisterContext,
+ IN OUT VOID *CommBuffer,
+ IN OUT UINTN *CommBufferSize
+ )
+{
+ EFI_STATUS Status;
+ UINTN TempCommBufferSize;
+ TPM_NVS_MM_COMM_BUFFER *CommParams;
+
+ DEBUG ((DEBUG_VERBOSE, "%a()\n", __FUNCTION__));
+
+ //
+ // If input is invalid, stop processing this SMI
+ //
+ if (CommBuffer == NULL || CommBufferSize == NULL) {
+ return EFI_SUCCESS;
+ }
+
+ TempCommBufferSize = *CommBufferSize;
+
+ if(TempCommBufferSize != sizeof (TPM_NVS_MM_COMM_BUFFER)) {
+ DEBUG ((DEBUG_ERROR, "[%a] MM Communication buffer size is invalid for this handler!\n", __FUNCTION__));
+ return EFI_ACCESS_DENIED;
+ }
+ if (!IsBufferOutsideMmValid ((UINTN) CommBuffer, TempCommBufferSize)) {
+ DEBUG ((DEBUG_ERROR, "[%a] - MM Communication buffer in invalid location!\n", __FUNCTION__));
+ return EFI_ACCESS_DENIED;
+ }
+
+ //
+ // Farm out the job to individual functions based on what was requested.
+ //
+ CommParams = (TPM_NVS_MM_COMM_BUFFER*) CommBuffer;
+ Status = EFI_SUCCESS;
+ switch (CommParams->Function) {
+ case TpmNvsMmExchangeInfo:
+ DEBUG ((DEBUG_VERBOSE, "[%a] - Function requested: MM_EXCHANGE_NVS_INFO\n", __FUNCTION__));
+ CommParams->RegisteredPpSwiValue = mPpSoftwareSmi;
+ CommParams->RegisteredMcSwiValue = mMcSoftwareSmi;
+ mTcgNvs = (TCG_NVS*) (UINTN) CommParams->TargetAddress;
+ break;
+
+ default:
+ DEBUG ((DEBUG_INFO, "[%a] - Unknown function %d!\n", __FUNCTION__, CommParams->Function));
+ Status = EFI_UNSUPPORTED;
+ break;
+ }
+
+ CommParams->ReturnStatus = (UINT64) Status;
+ return EFI_SUCCESS;
+}
/**
Software SMI callback for TPM physical presence which is called from ACPI method.
@@ -186,721 +234,140 @@ MemoryClearCallback ( }
/**
- Find the operation region in TCG ACPI table by given Name and Size,
- and initialize it if the region is found.
-
- @param[in, out] Table The TPM item in ACPI table.
- @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.
-
-**/
-VOID *
-AssignOpRegion (
- EFI_ACPI_DESCRIPTION_HEADER *Table,
- UINT32 Name,
- UINT16 Size
- )
-{
- EFI_STATUS Status;
- AML_OP_REGION_32_8 *OpRegion;
- EFI_PHYSICAL_ADDRESS MemoryAddress;
-
- MemoryAddress = SIZE_4GB - 1;
-
- //
- // Patch some pointers for the ASL code before loading the SSDT.
- //
- for (OpRegion = (AML_OP_REGION_32_8 *) (Table + 1);
- OpRegion <= (AML_OP_REGION_32_8 *) ((UINT8 *) Table + Table->Length);
- OpRegion = (AML_OP_REGION_32_8 *) ((UINT8 *) OpRegion + 1)) {
- if ((OpRegion->OpRegionOp == AML_EXT_REGION_OP) &&
- (OpRegion->NameString == Name) &&
- (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);
- ZeroMem ((VOID *)(UINTN)MemoryAddress, Size);
- OpRegion->RegionOffset = (UINT32) (UINTN) MemoryAddress;
- OpRegion->RegionLen = (UINT8) Size;
- break;
- }
- }
-
- return (VOID *) (UINTN) MemoryAddress;
-}
-
-/**
- Patch version string of Physical Presence interface supported by platform. The initial string tag in TPM
-ACPI table is "$PV".
-
- @param[in, out] Table The TPM item in ACPI table.
- @param[in] PPVer Version string of Physical Presence interface supported by platform.
-
- @return The allocated address for the found region.
-
-**/
-EFI_STATUS
-UpdatePPVersion (
- EFI_ACPI_DESCRIPTION_HEADER *Table,
- CHAR8 *PPVer
- )
-{
- EFI_STATUS Status;
- UINT8 *DataPtr;
-
- //
- // Patch some pointers for the ASL code before loading the SSDT.
- //
- for (DataPtr = (UINT8 *)(Table + 1);
- DataPtr <= (UINT8 *) ((UINT8 *) Table + Table->Length - PHYSICAL_PRESENCE_VERSION_SIZE);
- DataPtr += 1) {
- if (AsciiStrCmp((CHAR8 *)DataPtr, PHYSICAL_PRESENCE_VERSION_TAG) == 0) {
- Status = AsciiStrCpyS((CHAR8 *)DataPtr, PHYSICAL_PRESENCE_VERSION_SIZE, PPVer);
- DEBUG((EFI_D_INFO, "TPM2 Physical Presence Interface Version update status 0x%x\n", Status));
- return Status;
- }
- }
-
- return EFI_NOT_FOUND;
-}
-
-/**
- Patch interrupt resources returned by TPM _PRS. ResourceTemplate to patch is determined by input
- interrupt buffer size. BufferSize, PkgLength and interrupt descriptor in ByteList need to be patched
+ Notification for SMM ReadyToLock protocol.
- @param[in, out] Table The TPM item in ACPI table.
- @param[in] IrqBuffer Input new IRQ buffer.
- @param[in] IrqBuffserSize Input new IRQ buffer size.
- @param[out] IsShortFormPkgLength If _PRS returns Short length Package(ACPI spec 20.2.4).
+ @param[in] Protocol Points to the protocol's unique identifier.
+ @param[in] Interface Points to the interface instance.
+ @param[in] Handle The handle on which the interface was installed.
- @return patch status.
+ @retval EFI_SUCCESS Notification runs successfully.
**/
EFI_STATUS
-UpdatePossibleResource (
- IN OUT EFI_ACPI_DESCRIPTION_HEADER *Table,
- IN UINT32 *IrqBuffer,
- IN UINT32 IrqBuffserSize,
- OUT BOOLEAN *IsShortFormPkgLength
- )
-{
- UINT8 *DataPtr;
- UINT8 *DataEndPtr;
- UINT32 NewPkgLength;
- UINT32 OrignalPkgLength;
-
- NewPkgLength = 0;
- OrignalPkgLength = 0;
- DataEndPtr = NULL;
-
- //
- // Follow ACPI spec
- // 6.4.3 Extend Interrupt Descriptor.
- // 19.3.3 ASL Resource Template
- // 20 AML specification
- // to patch TPM ACPI object _PRS returned ResourceTemplate() containing 2 resource descriptors and an auto appended End Tag
- //
- // AML data is organized by following rule.
- // Code need to patch BufferSize and PkgLength and interrupt descriptor in ByteList
- //
- // ============= Buffer ====================
- // DefBuffer := BufferOp PkgLength BufferSize ByteList
- // BufferOp := 0x11
- //
- // ==============PkgLength==================
- // PkgLength := PkgLeadByte |
- // <PkgLeadByte ByteData> |
- // <PkgLeadByte ByteData ByteData> |
- // <PkgLeadByte ByteData ByteData ByteData>
- //
- // PkgLeadByte := <bit 7-6: ByteData count that follows (0-3)>
- // <bit 5-4: Only used if PkgLength <= 63 >
- // <bit 3-0: Least significant package length nybble>
- //
- //==============BufferSize==================
- // BufferSize := Integer
- // Integer := ByteConst|WordConst|DwordConst....
- //
- // ByteConst := BytePrefix ByteData
- //
- //==============ByteList===================
- // ByteList := ByteData ByteList
- //
- //=========================================
-
- //
- // 1. Check TPM_PRS_RESS with PkgLength <=63 can hold the input interrupt number buffer for patching
- //
- for (DataPtr = (UINT8 *)(Table + 1);
- DataPtr < (UINT8 *) ((UINT8 *) Table + Table->Length - (TPM_PRS_RES_NAME_SIZE + TPM_POS_RES_TEMPLATE_MIN_SIZE));
- DataPtr += 1) {
- if (CompareMem(DataPtr, TPM_PRS_RESS, TPM_PRS_RES_NAME_SIZE) == 0) {
- //
- // Jump over object name & BufferOp
- //
- DataPtr += TPM_PRS_RES_NAME_SIZE + 1;
-
- if ((*DataPtr & (BIT7|BIT6)) == 0) {
- OrignalPkgLength = (UINT32)*DataPtr;
- DataEndPtr = DataPtr + OrignalPkgLength;
-
- //
- // Jump over PkgLength = PkgLeadByte only
- //
- NewPkgLength++;
-
- //
- // Jump over BufferSize
- //
- if (*(DataPtr + 1) == AML_BYTE_PREFIX) {
- NewPkgLength += 2;
- } else if (*(DataPtr + 1) == AML_WORD_PREFIX) {
- NewPkgLength += 3;
- } else if (*(DataPtr + 1) == AML_DWORD_PREFIX) {
- NewPkgLength += 5;
- } else {
- ASSERT(FALSE);
- return EFI_UNSUPPORTED;
- }
- } else {
- ASSERT(FALSE);
- return EFI_UNSUPPORTED;
- }
-
- //
- // Include Memory32Fixed Descriptor (12 Bytes) + Interrupt Descriptor header(5 Bytes) + End Tag(2 Bytes)
- //
- NewPkgLength += 19 + IrqBuffserSize;
- if (NewPkgLength > 63) {
- break;
- }
-
- if (NewPkgLength > OrignalPkgLength) {
- ASSERT(FALSE);
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // 1.1 Patch PkgLength
- //
- *DataPtr = (UINT8)NewPkgLength;
-
- //
- // 1.2 Patch BufferSize = sizeof(Memory32Fixed Descriptor + Interrupt Descriptor + End Tag).
- // It is Little endian. So only patch lowest byte of BufferSize due to current interrupt number limit.
- //
- *(DataPtr + 2) = (UINT8)(IrqBuffserSize + 19);
-
- //
- // Notify _PRS to report short formed ResourceTemplate
- //
- *IsShortFormPkgLength = TRUE;
-
- break;
- }
- }
-
- //
- // 2. Use TPM_PRS_RESL with PkgLength > 63 to hold longer input interrupt number buffer for patching
- //
- if (NewPkgLength > 63) {
- NewPkgLength = 0;
- OrignalPkgLength = 0;
- for (DataPtr = (UINT8 *)(Table + 1);
- DataPtr < (UINT8 *) ((UINT8 *) Table + Table->Length - (TPM_PRS_RES_NAME_SIZE + TPM_POS_RES_TEMPLATE_MIN_SIZE));
- DataPtr += 1) {
- if (CompareMem(DataPtr, TPM_PRS_RESL, TPM_PRS_RES_NAME_SIZE) == 0) {
- //
- // Jump over object name & BufferOp
- //
- DataPtr += TPM_PRS_RES_NAME_SIZE + 1;
-
- if ((*DataPtr & (BIT7|BIT6)) != 0) {
- OrignalPkgLength = (UINT32)(*(DataPtr + 1) << 4) + (*DataPtr & 0x0F);
- DataEndPtr = DataPtr + OrignalPkgLength;
- //
- // Jump over PkgLength = PkgLeadByte + ByteData length
- //
- NewPkgLength += 1 + ((*DataPtr & (BIT7|BIT6)) >> 6);
-
- //
- // Jump over BufferSize
- //
- if (*(DataPtr + NewPkgLength) == AML_BYTE_PREFIX) {
- NewPkgLength += 2;
- } else if (*(DataPtr + NewPkgLength) == AML_WORD_PREFIX) {
- NewPkgLength += 3;
- } else if (*(DataPtr + NewPkgLength) == AML_DWORD_PREFIX) {
- NewPkgLength += 5;
- } else {
- ASSERT(FALSE);
- return EFI_UNSUPPORTED;
- }
- } else {
- ASSERT(FALSE);
- return EFI_UNSUPPORTED;
- }
-
- //
- // Include Memory32Fixed Descriptor (12 Bytes) + Interrupt Descriptor header(5 Bytes) + End Tag(2 Bytes)
- //
- NewPkgLength += 19 + IrqBuffserSize;
-
- if (NewPkgLength > OrignalPkgLength) {
- ASSERT(FALSE);
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // 2.1 Patch PkgLength. Only patch PkgLeadByte and first ByteData
- //
- *DataPtr = (UINT8)((*DataPtr) & 0xF0) | (NewPkgLength & 0x0F);
- *(DataPtr + 1) = (UINT8)((NewPkgLength & 0xFF0) >> 4);
-
- //
- // 2.2 Patch BufferSize = sizeof(Memory32Fixed Descriptor + Interrupt Descriptor + End Tag).
- // It is Little endian. Only patch lowest byte of BufferSize due to current interrupt number limit.
- //
- *(DataPtr + 2 + ((*DataPtr & (BIT7|BIT6)) >> 6)) = (UINT8)(IrqBuffserSize + 19);
-
- //
- // Notify _PRS to report long formed ResourceTemplate
- //
- *IsShortFormPkgLength = FALSE;
- break;
- }
- }
- }
-
- if (DataPtr >= (UINT8 *) ((UINT8 *) Table + Table->Length - (TPM_PRS_RES_NAME_SIZE + TPM_POS_RES_TEMPLATE_MIN_SIZE))) {
- return EFI_NOT_FOUND;
- }
-
- //
- // 3. Move DataPtr to Interrupt descriptor header and patch interrupt descriptor.
- // 5 bytes for interrupt descriptor header, 2 bytes for End Tag
- //
- DataPtr += NewPkgLength - (5 + IrqBuffserSize + 2);
- //
- // 3.1 Patch Length bit[7:0] of Interrupt descriptor patch interrupt descriptor
- //
- *(DataPtr + 1) = (UINT8)(2 + IrqBuffserSize);
- //
- // 3.2 Patch Interrupt Table Length
- //
- *(DataPtr + 4) = (UINT8)(IrqBuffserSize / sizeof(UINT32));
- //
- // 3.3 Copy patched InterruptNumBuffer
- //
- CopyMem(DataPtr + 5, IrqBuffer, IrqBuffserSize);
-
- //
- // 4. Jump over Interrupt descriptor and Patch END Tag, set Checksum field to 0
- //
- DataPtr += 5 + IrqBuffserSize;
- *DataPtr = ACPI_END_TAG_DESCRIPTOR;
- *(DataPtr + 1) = 0;
-
- //
- // 5. Jump over new ResourceTemplate. Stuff rest bytes to NOOP
- //
- DataPtr += 2;
- if (DataPtr < DataEndPtr) {
- SetMem(DataPtr, (UINTN)DataEndPtr - (UINTN)DataPtr, AML_NOOP_OP);
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Patch TPM2 device HID string. The initial string tag in TPM2 ACPI table is "NNN0000".
-
- @param[in, out] Table The TPM2 SSDT ACPI table.
-
- @return HID Update status.
-
-**/
-EFI_STATUS
-UpdateHID (
- EFI_ACPI_DESCRIPTION_HEADER *Table
- )
-{
- EFI_STATUS Status;
- UINT8 *DataPtr;
- CHAR8 Hid[TPM_HID_ACPI_SIZE];
- UINT32 ManufacturerID;
- UINT32 FirmwareVersion1;
- UINT32 FirmwareVersion2;
- BOOLEAN PnpHID;
-
- PnpHID = TRUE;
-
- //
- // Initialize HID with Default PNP string
- //
- ZeroMem(Hid, TPM_HID_ACPI_SIZE);
-
- //
- // Get Manufacturer ID
- //
- Status = Tpm2GetCapabilityManufactureID(&ManufacturerID);
- if (!EFI_ERROR(Status)) {
- DEBUG((EFI_D_INFO, "TPM_PT_MANUFACTURER 0x%08x\n", ManufacturerID));
- //
- // ManufacturerID defined in TCG Vendor ID Registry
- // may tailed with 0x00 or 0x20
- //
- if ((ManufacturerID >> 24) == 0x00 || ((ManufacturerID >> 24) == 0x20)) {
- //
- // HID containing PNP ID "NNN####"
- // NNN is uppercase letter for Vendor ID specified by manufacturer
- //
- CopyMem(Hid, &ManufacturerID, 3);
- } else {
- //
- // HID containing ACP ID "NNNN####"
- // NNNN is uppercase letter for Vendor ID specified by manufacturer
- //
- CopyMem(Hid, &ManufacturerID, 4);
- PnpHID = FALSE;
- }
- } else {
- DEBUG ((EFI_D_ERROR, "Get TPM_PT_MANUFACTURER failed %x!\n", Status));
- ASSERT(FALSE);
- return Status;
- }
-
- Status = Tpm2GetCapabilityFirmwareVersion(&FirmwareVersion1, &FirmwareVersion2);
- if (!EFI_ERROR(Status)) {
- DEBUG((EFI_D_INFO, "TPM_PT_FIRMWARE_VERSION_1 0x%x\n", FirmwareVersion1));
- DEBUG((EFI_D_INFO, "TPM_PT_FIRMWARE_VERSION_2 0x%x\n", FirmwareVersion2));
- //
- // #### is Firmware Version 1
- //
- if (PnpHID) {
- AsciiSPrint(Hid + 3, TPM_HID_PNP_SIZE - 3, "%02d%02d", ((FirmwareVersion1 & 0xFFFF0000) >> 16), (FirmwareVersion1 & 0x0000FFFF));
- } else {
- AsciiSPrint(Hid + 4, TPM_HID_ACPI_SIZE - 4, "%02d%02d", ((FirmwareVersion1 & 0xFFFF0000) >> 16), (FirmwareVersion1 & 0x0000FFFF));
- }
-
- } else {
- DEBUG ((EFI_D_ERROR, "Get TPM_PT_FIRMWARE_VERSION_X failed %x!\n", Status));
- ASSERT(FALSE);
- return Status;
- }
-
- //
- // Patch HID in ASL code before loading the SSDT.
- //
- for (DataPtr = (UINT8 *)(Table + 1);
- DataPtr <= (UINT8 *) ((UINT8 *) Table + Table->Length - TPM_HID_PNP_SIZE);
- DataPtr += 1) {
- if (AsciiStrCmp((CHAR8 *)DataPtr, TPM_HID_TAG) == 0) {
- if (PnpHID) {
- CopyMem(DataPtr, Hid, TPM_HID_PNP_SIZE);
- //
- // if HID is PNP ID, patch the last byte in HID TAG to Noop
- //
- *(DataPtr + TPM_HID_PNP_SIZE) = AML_NOOP_OP;
- } else {
-
- CopyMem(DataPtr, Hid, TPM_HID_ACPI_SIZE);
- }
- DEBUG((DEBUG_INFO, "TPM2 ACPI _HID is patched to %a\n", DataPtr));
-
- return Status;
- }
- }
-
- DEBUG((EFI_D_ERROR, "TPM2 ACPI HID TAG for patch not found!\n"));
- return EFI_NOT_FOUND;
-}
-
-/**
- Initialize and publish TPM items in ACPI table.
-
- @retval EFI_SUCCESS The TCG ACPI table is published successfully.
- @retval Others The TCG ACPI table is not published.
-
-**/
-EFI_STATUS
-PublishAcpiTable (
- VOID
- )
-{
- EFI_STATUS Status;
- EFI_ACPI_TABLE_PROTOCOL *AcpiTable;
- UINTN TableKey;
- EFI_ACPI_DESCRIPTION_HEADER *Table;
- UINTN TableSize;
- UINT32 *PossibleIrqNumBuf;
- UINT32 PossibleIrqNumBufSize;
- BOOLEAN IsShortFormPkgLength;
-
- IsShortFormPkgLength = FALSE;
-
- Status = GetSectionFromFv (
- &gEfiCallerIdGuid,
- EFI_SECTION_RAW,
- 0,
- (VOID **) &Table,
- &TableSize
- );
- ASSERT_EFI_ERROR (Status);
-
- //
- // Measure to PCR[0] with event EV_POST_CODE ACPI DATA.
- // The measurement has to be done before any update.
- // Otherwise, the PCR record would be different after TPM FW update
- // or the PCD configuration change.
- //
- TpmMeasureAndLogData(
- 0,
- EV_POST_CODE,
- EV_POSTCODE_INFO_ACPI_DATA,
- ACPI_DATA_LEN,
- Table,
- TableSize
- );
-
- //
- // Update Table version before measuring it to PCR
- //
- Status = UpdatePPVersion(Table, (CHAR8 *)PcdGetPtr(PcdTcgPhysicalPresenceInterfaceVer));
- ASSERT_EFI_ERROR (Status);
-
- DEBUG ((
- DEBUG_INFO,
- "Current physical presence interface version - %a\n",
- (CHAR8 *) PcdGetPtr(PcdTcgPhysicalPresenceInterfaceVer)
- ));
-
- //
- // Update TPM2 HID after measuring it to PCR
- //
- Status = UpdateHID(Table);
- if (EFI_ERROR(Status)) {
- return Status;
- }
-
- if (PcdGet32(PcdTpm2CurrentIrqNum) != 0) {
- //
- // Patch _PRS interrupt resource only when TPM interrupt is supported
- //
- PossibleIrqNumBuf = (UINT32 *)PcdGetPtr(PcdTpm2PossibleIrqNumBuf);
- PossibleIrqNumBufSize = (UINT32)PcdGetSize(PcdTpm2PossibleIrqNumBuf);
-
- if (PossibleIrqNumBufSize <= MAX_PRS_INT_BUF_SIZE && (PossibleIrqNumBufSize % sizeof(UINT32)) == 0) {
- Status = UpdatePossibleResource(Table, PossibleIrqNumBuf, PossibleIrqNumBufSize, &IsShortFormPkgLength);
- DEBUG ((
- DEBUG_INFO,
- "UpdatePossibleResource status - %x. TPM2 service may not ready in OS.\n",
- Status
- ));
- } else {
- DEBUG ((
- DEBUG_INFO,
- "PcdTpm2PossibleIrqNumBuf size %x is not correct. TPM2 service may not ready in OS.\n",
- PossibleIrqNumBufSize
- ));
- }
- }
-
- ASSERT (Table->OemTableId == SIGNATURE_64 ('T', 'p', 'm', '2', 'T', 'a', 'b', 'l'));
- CopyMem (Table->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (Table->OemId) );
- mTcgNvs = AssignOpRegion (Table, SIGNATURE_32 ('T', 'N', 'V', 'S'), (UINT16) sizeof (TCG_NVS));
- ASSERT (mTcgNvs != NULL);
- mTcgNvs->TpmIrqNum = PcdGet32(PcdTpm2CurrentIrqNum);
- mTcgNvs->IsShortFormPkgLength = IsShortFormPkgLength;
-
- //
- // Publish the TPM ACPI table. Table is re-checksummed.
- //
- Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **) &AcpiTable);
- ASSERT_EFI_ERROR (Status);
-
- TableKey = 0;
- Status = AcpiTable->InstallAcpiTable (
- AcpiTable,
- Table,
- TableSize,
- &TableKey
- );
- ASSERT_EFI_ERROR (Status);
-
- return Status;
-}
-
-/**
- Publish TPM2 ACPI table
-
- @retval EFI_SUCCESS The TPM2 ACPI table is published successfully.
- @retval Others The TPM2 ACPI table is not published.
-
-**/
-EFI_STATUS
-PublishTpm2 (
- VOID
- )
+EFIAPI
+TcgMmReadyToLock (
+ IN CONST EFI_GUID *Protocol,
+ IN VOID *Interface,
+ IN EFI_HANDLE Handle
+)
{
- EFI_STATUS Status;
- EFI_ACPI_TABLE_PROTOCOL *AcpiTable;
- UINTN TableKey;
- UINT64 OemTableId;
- EFI_TPM2_ACPI_CONTROL_AREA *ControlArea;
- TPM2_PTP_INTERFACE_TYPE InterfaceType;
-
- //
- // Measure to PCR[0] with event EV_POST_CODE ACPI DATA.
- // The measurement has to be done before any update.
- // Otherwise, the PCR record would be different after event log update
- // or the PCD configuration change.
- //
- TpmMeasureAndLogData(
- 0,
- EV_POST_CODE,
- EV_POSTCODE_INFO_ACPI_DATA,
- ACPI_DATA_LEN,
- &mTpm2AcpiTemplate,
- mTpm2AcpiTemplate.Header.Length
- );
-
- mTpm2AcpiTemplate.Header.Revision = PcdGet8(PcdTpm2AcpiTableRev);
- DEBUG((DEBUG_INFO, "Tpm2 ACPI table revision is %d\n", mTpm2AcpiTemplate.Header.Revision));
-
- //
- // PlatformClass is only valid for version 4 and above
- // BIT0~15: PlatformClass
- // BIT16~31: Reserved
- //
- if (mTpm2AcpiTemplate.Header.Revision >= EFI_TPM2_ACPI_TABLE_REVISION_4) {
- mTpm2AcpiTemplate.Flags = (mTpm2AcpiTemplate.Flags & 0xFFFF0000) | PcdGet8(PcdTpmPlatformClass);
- DEBUG((DEBUG_INFO, "Tpm2 ACPI table PlatformClass is %d\n", (mTpm2AcpiTemplate.Flags & 0x0000FFFF)));
- }
-
- mTpm2AcpiTemplate.Laml = PcdGet32(PcdTpm2AcpiTableLaml);
- mTpm2AcpiTemplate.Lasa = PcdGet64(PcdTpm2AcpiTableLasa);
- if ((mTpm2AcpiTemplate.Header.Revision < EFI_TPM2_ACPI_TABLE_REVISION_4) ||
- (mTpm2AcpiTemplate.Laml == 0) || (mTpm2AcpiTemplate.Lasa == 0)) {
- //
- // If version is smaller than 4 or Laml/Lasa is not valid, rollback to original Length.
- //
- mTpm2AcpiTemplate.Header.Length = sizeof(EFI_TPM2_ACPI_TABLE);
- }
+ EFI_STATUS Status;
- InterfaceType = PcdGet8(PcdActiveTpmInterfaceType);
- switch (InterfaceType) {
- case Tpm2PtpInterfaceCrb:
- mTpm2AcpiTemplate.StartMethod = EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE;
- mTpm2AcpiTemplate.AddressOfControlArea = PcdGet64 (PcdTpmBaseAddress) + 0x40;
- ControlArea = (EFI_TPM2_ACPI_CONTROL_AREA *)(UINTN)mTpm2AcpiTemplate.AddressOfControlArea;
- ControlArea->CommandSize = 0xF80;
- ControlArea->ResponseSize = 0xF80;
- ControlArea->Command = PcdGet64 (PcdTpmBaseAddress) + 0x80;
- ControlArea->Response = PcdGet64 (PcdTpmBaseAddress) + 0x80;
- break;
- case Tpm2PtpInterfaceFifo:
- case Tpm2PtpInterfaceTis:
- break;
- default:
- DEBUG((EFI_D_ERROR, "TPM2 InterfaceType get error! %d\n", InterfaceType));
- break;
+ if (mReadyToLockHandle != NULL) {
+ Status = gMmst->MmiHandlerUnRegister (mReadyToLockHandle);
+ mReadyToLockHandle = NULL;
}
-
- CopyMem (mTpm2AcpiTemplate.Header.OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (mTpm2AcpiTemplate.Header.OemId));
- OemTableId = PcdGet64 (PcdAcpiDefaultOemTableId);
- CopyMem (&mTpm2AcpiTemplate.Header.OemTableId, &OemTableId, sizeof (UINT64));
- mTpm2AcpiTemplate.Header.OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
- mTpm2AcpiTemplate.Header.CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
- mTpm2AcpiTemplate.Header.CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
-
- //
- // Construct ACPI table
- //
- Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **) &AcpiTable);
- ASSERT_EFI_ERROR (Status);
-
- Status = AcpiTable->InstallAcpiTable (
- AcpiTable,
- &mTpm2AcpiTemplate,
- mTpm2AcpiTemplate.Header.Length,
- &TableKey
- );
- ASSERT_EFI_ERROR (Status);
-
return Status;
}
/**
- The driver's entry point.
+ The driver's common initialization routine.
It install callbacks for TPM physical presence and MemoryClear, and locate
SMM variable to be used in the callback function.
- @param[in] ImageHandle The firmware allocated handle for the EFI image.
- @param[in] SystemTable A pointer to the EFI System Table.
-
@retval EFI_SUCCESS The entry point is executed successfully.
@retval Others Some error occurs when executing this entry point.
**/
EFI_STATUS
-EFIAPI
-InitializeTcgSmm (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+InitializeTcgCommon (
+ VOID
)
{
EFI_STATUS Status;
EFI_SMM_SW_DISPATCH2_PROTOCOL *SwDispatch;
EFI_SMM_SW_REGISTER_CONTEXT SwContext;
- EFI_HANDLE SwHandle;
+ EFI_HANDLE PpSwHandle;
+ EFI_HANDLE McSwHandle;
+ EFI_HANDLE NotifyHandle;
if (!CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm20DtpmGuid)){
DEBUG ((EFI_D_ERROR, "No TPM2 DTPM instance required!\n"));
return EFI_UNSUPPORTED;
}
- Status = PublishAcpiTable ();
+ // Initialize variables first
+ mReadyToLockHandle = NULL;
+ SwDispatch = NULL;
+ PpSwHandle = NULL;
+ McSwHandle = NULL;
+ NotifyHandle = NULL;
+
+ // Register a root handler to communicate the NVS region and SMI channel between MM and DXE
+ Status = gMmst->MmiHandlerRegister (TpmNvsCommunciate, &gTpmNvsMmGuid, &mReadyToLockHandle);
ASSERT_EFI_ERROR (Status);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "[%a] Failed to register NVS communicate as root MM handler - %r!\n", __FUNCTION__, Status));
+ goto Cleanup;
+ }
//
// Get the Sw dispatch protocol and register SMI callback functions.
//
Status = gMmst->MmLocateProtocol (&gEfiSmmSwDispatch2ProtocolGuid, NULL, (VOID**)&SwDispatch);
ASSERT_EFI_ERROR (Status);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "[%a] Failed to locate Sw dispatch protocol - %r!\n", __FUNCTION__, Status));
+ goto Cleanup;
+ }
+
SwContext.SwSmiInputValue = (UINTN) -1;
- Status = SwDispatch->Register (SwDispatch, PhysicalPresenceCallback, &SwContext, &SwHandle);
+ Status = SwDispatch->Register (SwDispatch, PhysicalPresenceCallback, &SwContext, &PpSwHandle);
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR (Status)) {
- return Status;
+ DEBUG ((DEBUG_ERROR, "[%a] Failed to register PP callback as SW MM handler - %r!\n", __FUNCTION__, Status));
+ goto Cleanup;
}
- mTcgNvs->PhysicalPresence.SoftwareSmi = (UINT8) SwContext.SwSmiInputValue;
+ mPpSoftwareSmi = SwContext.SwSmiInputValue;
SwContext.SwSmiInputValue = (UINTN) -1;
- Status = SwDispatch->Register (SwDispatch, MemoryClearCallback, &SwContext, &SwHandle);
+ Status = SwDispatch->Register (SwDispatch, MemoryClearCallback, &SwContext, &McSwHandle);
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR (Status)) {
- return Status;
+ DEBUG ((DEBUG_ERROR, "[%a] Failed to register MC callback as SW MM handler - %r!\n", __FUNCTION__, Status));
+ goto Cleanup;
}
- mTcgNvs->MemoryClear.SoftwareSmi = (UINT8) SwContext.SwSmiInputValue;
+ mMcSoftwareSmi = SwContext.SwSmiInputValue;
//
// Locate SmmVariableProtocol.
//
Status = gMmst->MmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID**)&mSmmVariable);
ASSERT_EFI_ERROR (Status);
+ if (EFI_ERROR (Status)) {
+ // Should not happen
+ DEBUG ((DEBUG_ERROR, "[%a] Failed to locate SMM variable protocol - %r!\n", __FUNCTION__, Status));
+ goto Cleanup;
+ }
- //
- // Set TPM2 ACPI table
- //
- Status = PublishTpm2 ();
+ // Turn off the light before leaving the room... at least, take a remote...
+ Status = gMmst->MmRegisterProtocolNotify (&gEfiMmReadyToLockProtocolGuid, TcgMmReadyToLock, &NotifyHandle);
ASSERT_EFI_ERROR (Status);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "[%a] Failed to register ready to lock notification - %r!\n", __FUNCTION__, Status));
+ goto Cleanup;
+ }
+ Tcg2NotifyMmReady ();
- return EFI_SUCCESS;
+Cleanup:
+ if (EFI_ERROR (Status)) {
+ // Something is whacked, clean up the mess...
+ if (NotifyHandle != NULL) {
+ gMmst->MmRegisterProtocolNotify (&gEfiMmReadyToLockProtocolGuid, NULL, &NotifyHandle);
+ }
+ if (McSwHandle != NULL && SwDispatch != NULL) {
+ SwDispatch->UnRegister (SwDispatch, McSwHandle);
+ }
+ if (PpSwHandle != NULL && SwDispatch != NULL) {
+ SwDispatch->UnRegister (SwDispatch, PpSwHandle);
+ }
+ if (mReadyToLockHandle != NULL) {
+ gMmst->MmiHandlerUnRegister (mReadyToLockHandle);
+ }
+ }
+
+ return Status;
}
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h index d7328c8f2a..d7f78aa432 100644 --- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h +++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h @@ -2,6 +2,7 @@ The header file for Tcg2 SMM driver.
Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -9,13 +10,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #ifndef __TCG2_SMM_H__
#define __TCG2_SMM_H__
-#include <PiDxe.h>
-#include <IndustryStandard/Acpi.h>
-#include <IndustryStandard/Tpm2Acpi.h>
+#include <PiMm.h>
#include <Guid/MemoryOverwriteControl.h>
#include <Guid/TpmInstance.h>
+#include <Guid/TpmNvsMm.h>
+#include <Protocol/MmReadyToLock.h>
#include <Protocol/SmmSwDispatch2.h>
#include <Protocol/AcpiTable.h>
#include <Protocol/SmmVariable.h>
@@ -25,56 +26,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MmServicesTableLib.h>
-#include <Library/UefiDriverEntryPoint.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/DxeServicesLib.h>
-#include <Library/TpmMeasurementLib.h>
#include <Library/Tpm2CommandLib.h>
#include <Library/Tcg2PhysicalPresenceLib.h>
#include <Library/IoLib.h>
-#include <Library/PrintLib.h>
#include <Library/PcdLib.h>
#include <Library/Tpm2DeviceLib.h>
#include <IndustryStandard/TpmPtp.h>
-#pragma pack(1)
-typedef struct {
- UINT8 SoftwareSmi;
- UINT32 Parameter;
- UINT32 Response;
- UINT32 Request;
- UINT32 RequestParameter;
- UINT32 LastRequest;
- UINT32 ReturnCode;
-} PHYSICAL_PRESENCE_NVS;
-
-typedef struct {
- UINT8 SoftwareSmi;
- UINT32 Parameter;
- UINT32 Request;
- UINT32 ReturnCode;
-} MEMORY_CLEAR_NVS;
-
-typedef struct {
- PHYSICAL_PRESENCE_NVS PhysicalPresence;
- MEMORY_CLEAR_NVS MemoryClear;
- UINT32 PPRequestUserConfirm;
- UINT32 TpmIrqNum;
- BOOLEAN IsShortFormPkgLength;
-} TCG_NVS;
-
-typedef struct {
- UINT8 OpRegionOp;
- UINT32 NameString;
- UINT8 RegionSpace;
- UINT8 DWordPrefix;
- UINT32 RegionOffset;
- UINT8 BytePrefix;
- UINT8 RegionLen;
-} AML_OP_REGION_32_8;
-#pragma pack()
-
//
// The definition for TCG MOR
//
@@ -87,36 +46,42 @@ typedef struct { #define MOR_REQUEST_SUCCESS 0
#define MOR_REQUEST_GENERAL_FAILURE 1
-//
-// Physical Presence Interface Version supported by Platform
-//
-#define PHYSICAL_PRESENCE_VERSION_TAG "$PV"
-#define PHYSICAL_PRESENCE_VERSION_SIZE 4
+/**
+ Notify the system that the SMM variable driver is ready.
+**/
+VOID
+Tcg2NotifyMmReady (
+ VOID
+ );
-//
-// PNP _HID for TPM2 device
-//
-#define TPM_HID_TAG "NNNN0000"
-#define TPM_HID_PNP_SIZE 8
-#define TPM_HID_ACPI_SIZE 9
+/**
+ This function is an abstraction layer for implementation specific Mm buffer validation routine.
-#define TPM_PRS_RESL "RESL"
-#define TPM_PRS_RESS "RESS"
-#define TPM_PRS_RES_NAME_SIZE 4
-//
-// Minimum PRS resource template size
-// 1 byte for BufferOp
-// 1 byte for PkgLength
-// 2 bytes for BufferSize
-// 12 bytes for Memory32Fixed descriptor
-// 5 bytes for Interrupt descriptor
-// 2 bytes for END Tag
-//
-#define TPM_POS_RES_TEMPLATE_MIN_SIZE (1 + 1 + 2 + 12 + 5 + 2)
+ @param Buffer The buffer start address to be checked.
+ @param Length The buffer length to be checked.
+
+ @retval TRUE This buffer is valid per processor architecture and not overlap with SMRAM.
+ @retval FALSE This buffer is not valid per processor architecture or overlap with SMRAM.
+**/
+BOOLEAN
+IsBufferOutsideMmValid (
+ IN EFI_PHYSICAL_ADDRESS Buffer,
+ IN UINT64 Length
+ );
+
+/**
+ The driver's common initialization routine.
+
+ It install callbacks for TPM physical presence and MemoryClear, and locate
+ SMM variable to be used in the callback function.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval Others Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+InitializeTcgCommon (
+ VOID
+ );
-//
-// Max Interrupt buffer size for PRS interrupt resource
-// Now support 15 interrupts in maxmum
-//
-#define MAX_PRS_INT_BUF_SIZE (15*4)
#endif // __TCG_SMM_H__
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf index 872ed27cbe..096338d0ef 100644 --- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf +++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf @@ -39,7 +39,7 @@ [Sources]
Tcg2Smm.h
Tcg2Smm.c
- Tpm.asl
+ Tcg2TraditionalMm.c
[Packages]
MdePkg/MdePkg.dec
@@ -58,6 +58,7 @@ Tpm2CommandLib
Tcg2PhysicalPresenceLib
PcdLib
+ SmmMemLib
[Guids]
## SOMETIMES_PRODUCES ## Variable:L"MemoryOverwriteRequestControl"
@@ -65,34 +66,18 @@ gEfiMemoryOverwriteControlDataGuid
gEfiTpmDeviceInstanceTpm20DtpmGuid ## PRODUCES ## GUID # TPM device identifier
+ gTcg2MmSwSmiRegisteredGuid ## PRODUCES
+ gTpmNvsMmGuid ## CONSUMES
[Protocols]
gEfiSmmSwDispatch2ProtocolGuid ## CONSUMES
gEfiSmmVariableProtocolGuid ## CONSUMES
- gEfiAcpiTableProtocolGuid ## CONSUMES
-
-[FixedPcd]
- gEfiSecurityPkgTokenSpaceGuid.PcdSmiCommandIoPort ## CONSUMES
+ gEfiMmReadyToLockProtocolGuid ## CONSUMES
[Pcd]
gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemId ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemTableId ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemRevision ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision ## SOMETIMES_CONSUMES
- gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## CONSUMES
- gEfiSecurityPkgTokenSpaceGuid.PcdTcgPhysicalPresenceInterfaceVer ## CONSUMES
- gEfiSecurityPkgTokenSpaceGuid.PcdTpm2AcpiTableRev ## CONSUMES
- gEfiSecurityPkgTokenSpaceGuid.PcdTpmPlatformClass ## SOMETIMES_CONSUMES
- gEfiSecurityPkgTokenSpaceGuid.PcdTpm2CurrentIrqNum ## CONSUMES
- gEfiSecurityPkgTokenSpaceGuid.PcdTpm2PossibleIrqNumBuf ## CONSUMES
- gEfiSecurityPkgTokenSpaceGuid.PcdActiveTpmInterfaceType ## CONSUMES
- gEfiSecurityPkgTokenSpaceGuid.PcdTpm2AcpiTableLaml ## CONSUMES
- gEfiSecurityPkgTokenSpaceGuid.PcdTpm2AcpiTableLasa ## CONSUMES
[Depex]
- gEfiAcpiTableProtocolGuid AND
gEfiSmmSwDispatch2ProtocolGuid AND
gEfiSmmVariableProtocolGuid AND
gEfiTcg2ProtocolGuid
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2TraditionalMm.c b/SecurityPkg/Tcg/Tcg2Smm/Tcg2TraditionalMm.c new file mode 100644 index 0000000000..5930090b4e --- /dev/null +++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2TraditionalMm.c @@ -0,0 +1,82 @@ +/** @file
+ TCG2 SMM driver that updates TPM2 items in ACPI table and registers
+ SMI2 callback functions for Tcg2 physical presence, ClearMemory, and
+ sample for dTPM StartMethod.
+
+ Caution: This module requires additional review when modified.
+ This driver will have external input - variable and ACPINvs data in SMM mode.
+ This external input must be validated carefully to avoid security issue.
+
+ PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check.
+
+Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "Tcg2Smm.h"
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/SmmMemLib.h>
+
+/**
+ Notify the system that the SMM variable driver is ready.
+**/
+VOID
+Tcg2NotifyMmReady (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ EFI_HANDLE Handle;
+
+ Handle = NULL;
+ Status = gBS->InstallProtocolInterface (
+ &Handle,
+ &gTcg2MmSwSmiRegisteredGuid,
+ EFI_NATIVE_INTERFACE,
+ NULL
+ );
+ ASSERT_EFI_ERROR (Status);
+}
+
+/**
+ This function is an abstraction layer for implementation specific Mm buffer validation routine.
+
+ @param Buffer The buffer start address to be checked.
+ @param Length The buffer length to be checked.
+
+ @retval TRUE This buffer is valid per processor architecture and not overlap with SMRAM.
+ @retval FALSE This buffer is not valid per processor architecture or overlap with SMRAM.
+**/
+BOOLEAN
+IsBufferOutsideMmValid (
+ IN EFI_PHYSICAL_ADDRESS Buffer,
+ IN UINT64 Length
+ )
+{
+ return SmmIsBufferOutsideSmmValid (Buffer, Length);
+}
+
+/**
+ The driver's entry point.
+
+ It install callbacks for TPM physical presence and MemoryClear, and locate
+ SMM variable to be used in the callback function.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval Others Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeTcgSmm (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ return InitializeTcgCommon ();
+}
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tpm.asl b/SecurityPkg/Tcg/Tcg2Smm/Tpm.asl deleted file mode 100644 index 95f9d7eae8..0000000000 --- a/SecurityPkg/Tcg/Tcg2Smm/Tpm.asl +++ /dev/null @@ -1,517 +0,0 @@ -/** @file
- The TPM2 definition block in ACPI table for TCG2 physical presence
- and MemoryClear.
-
-Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
-(c)Copyright 2016 HP Development Company, L.P.<BR>
-Copyright (c) Microsoft Corporation.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-DefinitionBlock (
- "Tpm.aml",
- "SSDT",
- 2,
- "INTEL ",
- "Tpm2Tabl",
- 0x1000
- )
-{
- Scope (\_SB)
- {
- Device (TPM)
- {
- //
- // TCG2
- //
-
- //
- // TAG for patching TPM2.0 _HID
- //
- Name (_HID, "NNNN0000")
-
- Name (_CID, "MSFT0101")
-
- //
- // Readable name of this device, don't know if this way is correct yet
- //
- Name (_STR, Unicode ("TPM 2.0 Device"))
-
- //
- // Operational region for Smi port access
- //
- OperationRegion (SMIP, SystemIO, FixedPcdGet16 (PcdSmiCommandIoPort), 1)
- Field (SMIP, ByteAcc, NoLock, Preserve)
- {
- IOPN, 8
- }
-
- //
- // Operational region for TPM access
- //
- OperationRegion (TPMR, SystemMemory, 0xfed40000, 0x5000)
- Field (TPMR, AnyAcc, NoLock, Preserve)
- {
- ACC0, 8, // TPM_ACCESS_0
- Offset(0x8),
- INTE, 32, // TPM_INT_ENABLE_0
- INTV, 8, // TPM_INT_VECTOR_0
- Offset(0x10),
- INTS, 32, // TPM_INT_STATUS_0
- INTF, 32, // TPM_INTF_CAPABILITY_0
- STS0, 32, // TPM_STS_0
- Offset(0x24),
- FIFO, 32, // TPM_DATA_FIFO_0
- Offset(0x30),
- TID0, 32, // TPM_INTERFACE_ID_0
- // ignore the rest
- }
-
- //
- // Operational region for TPM support, TPM Physical Presence and TPM Memory Clear
- // Region Offset 0xFFFF0000 and Length 0xF0 will be fixed in C code.
- //
- OperationRegion (TNVS, SystemMemory, 0xFFFF0000, 0xF0)
- Field (TNVS, AnyAcc, NoLock, Preserve)
- {
- PPIN, 8, // Software SMI for Physical Presence Interface
- PPIP, 32, // Used for save physical presence parameter
- PPRP, 32, // Physical Presence request operation response
- PPRQ, 32, // Physical Presence request operation
- PPRM, 32, // Physical Presence request operation parameter
- LPPR, 32, // Last Physical Presence request operation
- FRET, 32, // Physical Presence function return code
- MCIN, 8, // Software SMI for Memory Clear Interface
- MCIP, 32, // Used for save the Mor parameter
- MORD, 32, // Memory Overwrite Request Data
- MRET, 32, // Memory Overwrite function return code
- UCRQ, 32, // Physical Presence request operation to Get User Confirmation Status
- IRQN, 32, // IRQ Number for _CRS
- SFRB, 8 // Is shortformed Pkglength for resource buffer
- }
-
- //
- // Possible resource settings returned by _PRS method
- // RESS : ResourceTemplate with PkgLength <=63
- // RESL : ResourceTemplate with PkgLength > 63
- //
- // The format of the data has to follow the same format as
- // _CRS (according to ACPI spec).
- //
- Name (RESS, ResourceTemplate() {
- Memory32Fixed (ReadWrite, 0xfed40000, 0x5000)
- Interrupt(ResourceConsumer, Level, ActiveLow, Shared, , , ) {1,2,3,4,5,6,7,8,9,10}
- })
-
- Name (RESL, ResourceTemplate() {
- Memory32Fixed (ReadWrite, 0xfed40000, 0x5000)
- Interrupt(ResourceConsumer, Level, ActiveLow, Shared, , , ) {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
- })
-
- //
- // Current resource settings for _CRS method
- //
- Name(RES0, ResourceTemplate () {
- Memory32Fixed (ReadWrite, 0xfed40000, 0x5000, REG0)
- Interrupt(ResourceConsumer, Level, ActiveLow, Shared, , , INTR) {12}
- })
-
- Name(RES1, ResourceTemplate () {
- Memory32Fixed (ReadWrite, 0xfed40000, 0x5000, REG1)
- })
-
-
- //
- // Return the resource consumed by TPM device.
- //
- Method(_CRS,0,Serialized)
- {
- //
- // IRQNum = 0 means disable IRQ support
- //
- If (LEqual(IRQN, 0)) {
- Return (RES1)
- }
- Else
- {
- CreateDWordField(RES0, ^INTR._INT, LIRQ)
- Store(IRQN, LIRQ)
- Return (RES0)
- }
- }
-
- //
- // Set resources consumed by the TPM device. This is used to
- // assign an interrupt number to the device. The input byte stream
- // has to be the same as returned by _CRS (according to ACPI spec).
- //
- // Platform may choose to override this function with specific interrupt
- // programing logic to replace FIFO/TIS SIRQ registers programing
- //
- Method(_SRS,1,Serialized)
- {
- //
- // Do not configure Interrupt if IRQ Num is configured 0 by default
- //
- If (LNotEqual(IRQN, 0)) {
- //
- // Update resource descriptor
- // Use the field name to identify the offsets in the argument
- // buffer and RES0 buffer.
- //
- CreateDWordField(Arg0, ^INTR._INT, IRQ0)
- CreateDWordField(RES0, ^INTR._INT, LIRQ)
- Store(IRQ0, LIRQ)
- Store(IRQ0, IRQN)
-
- CreateBitField(Arg0, ^INTR._HE, ITRG)
- CreateBitField(RES0, ^INTR._HE, LTRG)
- Store(ITRG, LTRG)
-
- CreateBitField(Arg0, ^INTR._LL, ILVL)
- CreateBitField(RES0, ^INTR._LL, LLVL)
- Store(ILVL, LLVL)
-
- //
- // Update TPM FIFO PTP/TIS interface only, identified by TPM_INTERFACE_ID_x lowest
- // nibble.
- // 0000 - FIFO interface as defined in PTP for TPM 2.0 is active
- // 1111 - FIFO interface as defined in TIS1.3 is active
- //
- If (LOr(LEqual (And (TID0, 0x0F), 0x00), LEqual (And (TID0, 0x0F), 0x0F))) {
- //
- // If FIFO interface, interrupt vector register is
- // available. TCG PTP specification allows only
- // values 1..15 in this field. For other interrupts
- // the field should stay 0.
- //
- If (LLess (IRQ0, 16)) {
- Store (And(IRQ0, 0xF), INTV)
- }
- //
- // Interrupt enable register (TPM_INT_ENABLE_x) bits 3:4
- // contains settings for interrupt polarity.
- // The other bits of the byte enable individual interrupts.
- // They should be all be zero, but to avoid changing the
- // configuration, the other bits are be preserved.
- // 00 - high level
- // 01 - low level
- // 10 - rising edge
- // 11 - falling edge
- //
- // ACPI spec definitions:
- // _HE: '1' is Edge, '0' is Level
- // _LL: '1' is ActiveHigh, '0' is ActiveLow (inverted from TCG spec)
- //
- If (LEqual (ITRG, 1)) {
- Or(INTE, 0x00000010, INTE)
- } Else {
- And(INTE, 0xFFFFFFEF, INTE)
- }
- if (LEqual (ILVL, 0)) {
- Or(INTE, 0x00000008, INTE)
- } Else {
- And(INTE, 0xFFFFFFF7, INTE)
- }
- }
- }
- }
-
- Method(_PRS,0,Serialized)
- {
- //
- // IRQNum = 0 means disable IRQ support
- //
- If (LEqual(IRQN, 0)) {
- Return (RES1)
- } ElseIf(LEqual(SFRB, 0)) {
- //
- // Long format. Possible resources PkgLength > 63
- //
- Return (RESL)
- } Else {
- //
- // Short format. Possible resources PkgLength <=63
- //
- Return (RESS)
- }
- }
-
- Method (PTS, 1, Serialized)
- {
- //
- // Detect Sx state for MOR, only S4, S5 need to handle
- //
- If (LAnd (LLess (Arg0, 6), LGreater (Arg0, 3)))
- {
- //
- // Bit4 -- DisableAutoDetect. 0 -- Firmware MAY autodetect.
- //
- If (LNot (And (MORD, 0x10)))
- {
- //
- // Trigger the SMI through ACPI _PTS method.
- //
- Store (0x02, MCIP)
-
- //
- // Trigger the SMI interrupt
- //
- Store (MCIN, IOPN)
- }
- }
- Return (0)
- }
-
- Method (_STA, 0)
- {
- if (LEqual (ACC0, 0xff))
- {
- Return (0)
- }
- Return (0x0f)
- }
-
- //
- // TCG Hardware Information
- //
- Method (HINF, 1, Serialized, 0, {BuffObj, PkgObj}, {UnknownObj}) // IntObj
- {
- //
- // Switch by function index
- //
- Switch (ToInteger(Arg0))
- {
- Case (0)
- {
- //
- // Standard query
- //
- Return (Buffer () {0x03})
- }
- Case (1)
- {
- //
- // Return failure if no TPM present
- //
- Name(TPMV, Package () {0x01, Package () {0x2, 0x0}})
- if (LEqual (_STA (), 0x00))
- {
- Return (Package () {0x00})
- }
-
- //
- // Return TPM version
- //
- Return (TPMV)
- }
- Default {BreakPoint}
- }
- Return (Buffer () {0})
- }
-
- Name(TPM2, Package (0x02){
- Zero,
- Zero
- })
-
- Name(TPM3, Package (0x03){
- Zero,
- Zero,
- Zero
- })
-
- //
- // TCG Physical Presence Interface
- //
- Method (TPPI, 2, Serialized, 0, {BuffObj, PkgObj, IntObj, StrObj}, {UnknownObj, UnknownObj}) // IntObj, PkgObj
- {
- //
- // Switch by function index
- //
- Switch (ToInteger(Arg0))
- {
- Case (0)
- {
- //
- // Standard query, supports function 1-8
- //
- Return (Buffer () {0xFF, 0x01})
- }
- Case (1)
- {
- //
- // a) Get Physical Presence Interface Version
- //
- Return ("$PV")
- }
- Case (2)
- {
- //
- // b) Submit TPM Operation Request to Pre-OS Environment
- //
-
- Store (DerefOf (Index (Arg1, 0x00)), PPRQ)
- Store (0, PPRM)
- Store (0x02, PPIP)
-
- //
- // Trigger the SMI interrupt
- //
- Store (PPIN, IOPN)
- Return (FRET)
-
-
- }
- Case (3)
- {
- //
- // c) Get Pending TPM Operation Requested By the OS
- //
-
- Store (PPRQ, Index (TPM2, 0x01))
- Return (TPM2)
- }
- Case (4)
- {
- //
- // d) Get Platform-Specific Action to Transition to Pre-OS Environment
- //
- Return (2)
- }
- Case (5)
- {
- //
- // e) Return TPM Operation Response to OS Environment
- //
- Store (0x05, PPIP)
-
- //
- // Trigger the SMI interrupt
- //
- Store (PPIN, IOPN)
-
- Store (LPPR, Index (TPM3, 0x01))
- Store (PPRP, Index (TPM3, 0x02))
-
- Return (TPM3)
- }
- Case (6)
- {
-
- //
- // f) Submit preferred user language (Not implemented)
- //
-
- Return (3)
-
- }
- Case (7)
- {
- //
- // g) Submit TPM Operation Request to Pre-OS Environment 2
- //
- Store (7, PPIP)
- Store (DerefOf (Index (Arg1, 0x00)), PPRQ)
- Store (0, PPRM)
- If (LEqual (PPRQ, 23)) {
- Store (DerefOf (Index (Arg1, 0x01)), PPRM)
- }
-
- //
- // Trigger the SMI interrupt
- //
- Store (PPIN, IOPN)
- Return (FRET)
- }
- Case (8)
- {
- //
- // e) Get User Confirmation Status for Operation
- //
- Store (8, PPIP)
- Store (DerefOf (Index (Arg1, 0x00)), UCRQ)
-
- //
- // Trigger the SMI interrupt
- //
- Store (PPIN, IOPN)
-
- Return (FRET)
- }
-
- Default {BreakPoint}
- }
- Return (1)
- }
-
- Method (TMCI, 2, Serialized, 0, IntObj, {UnknownObj, UnknownObj}) // IntObj, PkgObj
- {
- //
- // Switch by function index
- //
- Switch (ToInteger (Arg0))
- {
- Case (0)
- {
- //
- // Standard query, supports function 1-1
- //
- Return (Buffer () {0x03})
- }
- Case (1)
- {
- //
- // Save the Operation Value of the Request to MORD (reserved memory)
- //
- Store (DerefOf (Index (Arg1, 0x00)), MORD)
-
- //
- // Trigger the SMI through ACPI _DSM method.
- //
- Store (0x01, MCIP)
-
- //
- // Trigger the SMI interrupt
- //
- Store (MCIN, IOPN)
- Return (MRET)
- }
- Default {BreakPoint}
- }
- Return (1)
- }
-
- Method (_DSM, 4, Serialized, 0, UnknownObj, {BuffObj, IntObj, IntObj, PkgObj})
- {
-
- //
- // TCG Hardware Information
- //
- If(LEqual(Arg0, ToUUID ("cf8e16a5-c1e8-4e25-b712-4f54a96702c8")))
- {
- Return (HINF (Arg2))
- }
-
- //
- // TCG Physical Presence Interface
- //
- If(LEqual(Arg0, ToUUID ("3dddfaa6-361b-4eb4-a424-8d10089d1653")))
- {
- Return (TPPI (Arg2, Arg3))
- }
-
- //
- // TCG Memory Clear Interface
- //
- If(LEqual(Arg0, ToUUID ("376054ed-cc13-4675-901c-4756d7f2d45d")))
- {
- Return (TMCI (Arg2, Arg3))
- }
-
- Return (Buffer () {0})
- }
- }
- }
-}
|