PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check.\r
\r
Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials \r
-are licensed and made available under the terms and conditions of the BSD License \r
-which accompanies this distribution. The full text of the license may be found at \r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
http://opensource.org/licenses/bsd-license.php\r
\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
\r
**/\r
\r
#include "Tcg2Smm.h"\r
\r
-typedef enum {\r
- PtpInterfaceTis,\r
- PtpInterfaceFifo,\r
- PtpInterfaceCrb,\r
- PtpInterfaceMax,\r
-} PTP_INTERFACE_TYPE;\r
-\r
-/**\r
- Return PTP interface type.\r
-\r
- @param[in] Register Pointer to PTP register.\r
-\r
- @return PTP interface type.\r
-**/\r
-PTP_INTERFACE_TYPE\r
-GetPtpInterface (\r
- IN VOID *Register\r
- )\r
-{\r
- PTP_CRB_INTERFACE_IDENTIFIER InterfaceId;\r
- PTP_FIFO_INTERFACE_CAPABILITY InterfaceCapability;\r
-\r
- //\r
- // Check interface id\r
- //\r
- InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);\r
- InterfaceCapability.Uint32 = MmioRead32 ((UINTN)&((PTP_FIFO_REGISTERS *)Register)->InterfaceCapability);\r
-\r
- if (InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_TIS) {\r
- return PtpInterfaceTis;\r
- }\r
-\r
- if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB) &&\r
- (InterfaceId.Bits.InterfaceVersion == PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_CRB) &&\r
- (InterfaceId.Bits.CapCRB != 0)) {\r
- return PtpInterfaceCrb;\r
- }\r
-\r
- if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO) &&\r
- (InterfaceId.Bits.InterfaceVersion == PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_FIFO) &&\r
- (InterfaceId.Bits.CapFIFO != 0) &&\r
- (InterfaceCapability.Bits.InterfaceVersion == INTERFACE_CAPABILITY_INTERFACE_VERSION_PTP)) {\r
- return PtpInterfaceFifo;\r
- }\r
-\r
- //\r
- // No Ptp interface available\r
- //\r
- return PtpInterfaceMax;\r
-}\r
\r
EFI_TPM2_ACPI_TABLE mTpm2AcpiTemplate = {\r
{\r
mTcgNvs->PhysicalPresence.LastRequest = MostRecentRequest;\r
mTcgNvs->PhysicalPresence.Response = Response;\r
return EFI_SUCCESS;\r
- } else if ((mTcgNvs->PhysicalPresence.Parameter == TCG_ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS) \r
+ } else if ((mTcgNvs->PhysicalPresence.Parameter == TCG_ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS)\r
|| (mTcgNvs->PhysicalPresence.Parameter == TCG_ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS_2)) {\r
\r
OperationRequest = mTcgNvs->PhysicalPresence.Request;\r
return EFI_SUCCESS;\r
}\r
MorControl &= ~MOR_CLEAR_MEMORY_BIT_MASK;\r
+ } else {\r
+ mTcgNvs->MemoryClear.ReturnCode = MOR_REQUEST_GENERAL_FAILURE;\r
+ DEBUG ((EFI_D_ERROR, "[TPM] MOR Parameter error! Parameter = %x\n", mTcgNvs->MemoryClear.Parameter));\r
+ return EFI_SUCCESS;\r
}\r
\r
DataSize = sizeof (UINT8);\r
DataSize,\r
&MorControl\r
);\r
- if (EFI_ERROR (Status)) { \r
+ if (EFI_ERROR (Status)) {\r
mTcgNvs->MemoryClear.ReturnCode = MOR_REQUEST_GENERAL_FAILURE;\r
DEBUG ((EFI_D_ERROR, "[TPM] Set MOR variable failure! Status = %r\n", Status));\r
}\r
for (OpRegion = (AML_OP_REGION_32_8 *) (Table + 1);\r
OpRegion <= (AML_OP_REGION_32_8 *) ((UINT8 *) Table + Table->Length);\r
OpRegion = (AML_OP_REGION_32_8 *) ((UINT8 *) OpRegion + 1)) {\r
- if ((OpRegion->OpRegionOp == AML_EXT_REGION_OP) && \r
+ if ((OpRegion->OpRegionOp == AML_EXT_REGION_OP) &&\r
(OpRegion->NameString == Name) &&\r
(OpRegion->DWordPrefix == AML_DWORD_PREFIX) &&\r
(OpRegion->BytePrefix == AML_BYTE_PREFIX)) {\r
}\r
\r
/**\r
- Patch version string of Physical Presence interface supported by platform. The initial string tag in TPM \r
+ Patch version string of Physical Presence interface supported by platform. The initial string tag in TPM\r
ACPI table is "$PV".\r
\r
@param[in, out] Table The TPM item in ACPI table.\r
@param[in, out] Table The TPM item in ACPI table.\r
@param[in] IrqBuffer Input new IRQ buffer.\r
@param[in] IrqBuffserSize Input new IRQ buffer size.\r
+ @param[out] IsShortFormPkgLength If _PRS returns Short length Package(ACPI spec 20.2.4).\r
\r
@return patch status.\r
\r
**/\r
EFI_STATUS\r
UpdatePossibleResource (\r
- EFI_ACPI_DESCRIPTION_HEADER *Table,\r
- UINT32 *IrqBuffer,\r
- UINT32 IrqBuffserSize\r
+ IN OUT EFI_ACPI_DESCRIPTION_HEADER *Table,\r
+ IN UINT32 *IrqBuffer,\r
+ IN UINT32 IrqBuffserSize,\r
+ OUT BOOLEAN *IsShortFormPkgLength\r
)\r
{\r
UINT8 *DataPtr;\r
//\r
// Notify _PRS to report short formed ResourceTemplate\r
//\r
- mTcgNvs->IsShortFormPkgLength = TRUE;\r
+ *IsShortFormPkgLength = TRUE;\r
\r
break;\r
}\r
//\r
// Notify _PRS to report long formed ResourceTemplate\r
//\r
- mTcgNvs->IsShortFormPkgLength = FALSE;\r
+ *IsShortFormPkgLength = FALSE;\r
break;\r
}\r
}\r
*(DataPtr + 1) = 0;\r
\r
//\r
- // 5. Jump over whole ResourceTemplate. Stuff rest bytes to NOOP\r
+ // 5. Jump over new ResourceTemplate. Stuff rest bytes to NOOP\r
//\r
- for (DataPtr += 2; DataPtr < DataEndPtr; DataPtr++) {\r
- *DataPtr = AML_NOOP_OP;\r
+ DataPtr += 2;\r
+ if (DataPtr < DataEndPtr) {\r
+ SetMem(DataPtr, (UINTN)DataEndPtr - (UINTN)DataPtr, AML_NOOP_OP);\r
}\r
\r
return EFI_SUCCESS;\r
if (!EFI_ERROR(Status)) {\r
DEBUG((EFI_D_INFO, "TPM_PT_MANUFACTURER 0x%08x\n", ManufacturerID));\r
//\r
- // ManufacturerID defined in TCG Vendor ID Registry \r
+ // ManufacturerID defined in TCG Vendor ID Registry\r
// may tailed with 0x00 or 0x20\r
//\r
if ((ManufacturerID >> 24) == 0x00 || ((ManufacturerID >> 24) == 0x20)) {\r
} else {\r
AsciiSPrint(Hid + 4, TPM_HID_ACPI_SIZE - 4, "%02d%02d", ((FirmwareVersion1 & 0xFFFF0000) >> 16), (FirmwareVersion1 & 0x0000FFFF));\r
}\r
- \r
+\r
} else {\r
DEBUG ((EFI_D_ERROR, "Get TPM_PT_FIRMWARE_VERSION_X failed %x!\n", Status));\r
ASSERT(FALSE);\r
UINTN TableSize;\r
UINT32 *PossibleIrqNumBuf;\r
UINT32 PossibleIrqNumBufSize;\r
+ BOOLEAN IsShortFormPkgLength;\r
+\r
+ IsShortFormPkgLength = FALSE;\r
\r
Status = GetSectionFromFv (\r
&gEfiCallerIdGuid,\r
PossibleIrqNumBufSize = (UINT32)PcdGetSize(PcdTpm2PossibleIrqNumBuf);\r
\r
if (PossibleIrqNumBufSize <= MAX_PRS_INT_BUF_SIZE && (PossibleIrqNumBufSize % sizeof(UINT32)) == 0) {\r
- Status = UpdatePossibleResource(Table, PossibleIrqNumBuf, PossibleIrqNumBufSize);\r
+ Status = UpdatePossibleResource(Table, PossibleIrqNumBuf, PossibleIrqNumBufSize, &IsShortFormPkgLength);\r
DEBUG ((\r
DEBUG_INFO,\r
"UpdatePossibleResource status - %x. TPM2 service may not ready in OS.\n",\r
mTcgNvs = AssignOpRegion (Table, SIGNATURE_32 ('T', 'N', 'V', 'S'), (UINT16) sizeof (TCG_NVS));\r
ASSERT (mTcgNvs != NULL);\r
mTcgNvs->TpmIrqNum = PcdGet32(PcdTpm2CurrentIrqNum);\r
- mTcgNvs->IsShortFormPkgLength = FALSE;\r
+ mTcgNvs->IsShortFormPkgLength = IsShortFormPkgLength;\r
\r
//\r
// Publish the TPM ACPI table. Table is re-checksumed.\r
UINTN TableKey;\r
UINT64 OemTableId;\r
EFI_TPM2_ACPI_CONTROL_AREA *ControlArea;\r
- PTP_INTERFACE_TYPE InterfaceType;\r
+ TPM2_PTP_INTERFACE_TYPE InterfaceType;\r
\r
mTpm2AcpiTemplate.Header.Revision = PcdGet8(PcdTpm2AcpiTableRev);\r
DEBUG((DEBUG_INFO, "Tpm2 ACPI table revision is %d\n", mTpm2AcpiTemplate.Header.Revision));\r
\r
//\r
// PlatformClass is only valid for version 4 and above\r
- // BIT0~15: PlatformClass \r
+ // BIT0~15: PlatformClass\r
// BIT16~31: Reserved\r
//\r
if (mTpm2AcpiTemplate.Header.Revision >= EFI_TPM2_ACPI_TABLE_REVISION_4) {\r
sizeof(mTpm2AcpiTemplate)\r
);\r
\r
- InterfaceType = GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
+ InterfaceType = PcdGet8(PcdActiveTpmInterfaceType);\r
switch (InterfaceType) {\r
- case PtpInterfaceCrb:\r
+ case Tpm2PtpInterfaceCrb:\r
mTpm2AcpiTemplate.StartMethod = EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE;\r
mTpm2AcpiTemplate.AddressOfControlArea = PcdGet64 (PcdTpmBaseAddress) + 0x40;\r
ControlArea = (EFI_TPM2_ACPI_CONTROL_AREA *)(UINTN)mTpm2AcpiTemplate.AddressOfControlArea;\r
ControlArea->Command = PcdGet64 (PcdTpmBaseAddress) + 0x80;\r
ControlArea->Response = PcdGet64 (PcdTpmBaseAddress) + 0x80;\r
break;\r
- case PtpInterfaceFifo:\r
- case PtpInterfaceTis:\r
+ case Tpm2PtpInterfaceFifo:\r
+ case Tpm2PtpInterfaceTis:\r
break;\r
default:\r
DEBUG((EFI_D_ERROR, "TPM2 InterfaceType get error! %d\n", InterfaceType));\r
/**\r
The driver's entry point.\r
\r
- It install callbacks for TPM physical presence and MemoryClear, and locate \r
+ It install callbacks for TPM physical presence and MemoryClear, and locate\r
SMM variable to be used in the callback function.\r
\r
- @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
@param[in] SystemTable A pointer to the EFI System Table.\r
- \r
+\r
@retval EFI_SUCCESS The entry point is executed successfully.\r
@retval Others Some error occurs when executing this entry point.\r
\r
return Status;\r
}\r
mTcgNvs->MemoryClear.SoftwareSmi = (UINT8) SwContext.SwSmiInputValue;\r
- \r
+\r
//\r
// Locate SmmVariableProtocol.\r
//\r