From 6f785cfcc304c48ec04e542ee429df95e7b51bc5 Mon Sep 17 00:00:00 2001 From: "Yao, Jiewen" Date: Mon, 12 Jan 2015 03:21:00 +0000 Subject: Handle TPM device error and avoid deadloop in BDS. If TPM error happens, set TPM flag to NOT present, so that trusted boot patch is disabled. Also report status code for failure, so that platform may register handler to apply policy like force system reset, or disable TPM permanently. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: "Yao, Jiewen" Reviewed-by: "Dong, Guo" git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16598 6f19259b-4bc3-4df7-8a09-765794883524 --- SecurityPkg/Tcg/TrEEPei/TrEEPei.c | 46 ++++++++++++++----------------------- SecurityPkg/Tcg/TrEEPei/TrEEPei.inf | 5 +++- 2 files changed, 21 insertions(+), 30 deletions(-) (limited to 'SecurityPkg/Tcg/TrEEPei') diff --git a/SecurityPkg/Tcg/TrEEPei/TrEEPei.c b/SecurityPkg/Tcg/TrEEPei/TrEEPei.c index 8e2bc748ff..eea40847c5 100644 --- a/SecurityPkg/Tcg/TrEEPei/TrEEPei.c +++ b/SecurityPkg/Tcg/TrEEPei/TrEEPei.c @@ -1,7 +1,7 @@ /** @file Initialize TPM2 device and measure FVs before handing off control to DXE. -Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -40,19 +40,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #define PERF_ID_TREE_PEI 0x3080 typedef struct { EFI_GUID *EventGuid; TREE_EVENT_LOG_FORMAT LogFormat; - UINT32 BootHashAlg; - UINT16 DigestAlgID; - TPMI_ALG_HASH TpmHashAlgo; } TREE_EVENT_INFO_STRUCT; TREE_EVENT_INFO_STRUCT mTreeEventInfo[] = { - {&gTcgEventEntryHobGuid, TREE_EVENT_LOG_FORMAT_TCG_1_2, TREE_BOOT_HASH_ALG_SHA1, 0, TPM_ALG_SHA1}, + {&gTcgEventEntryHobGuid, TREE_EVENT_LOG_FORMAT_TCG_1_2}, }; BOOLEAN mImageInMemory = FALSE; @@ -128,28 +126,6 @@ EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList[] = { EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI *mMeasurementExcludedFvPpi; -/** - This function return hash algorithm from event log format. - - @param[in] EventLogFormat Event log format. - - @return hash algorithm. -**/ -TPMI_ALG_HASH -TrEEGetHashAlgoFromLogFormat ( - IN TREE_EVENT_LOG_FORMAT EventLogFormat - ) -{ - UINTN Index; - - for (Index = 0; Index < sizeof(mTreeEventInfo)/sizeof(mTreeEventInfo[0]); Index++) { - if (mTreeEventInfo[Index].LogFormat == EventLogFormat) { - return mTreeEventInfo[Index].TpmHashAlgo; - } - } - return TPM_ALG_SHA1; -} - /** This function get digest from digest list. @@ -318,6 +294,10 @@ HashLogExtendEvent ( EFI_STATUS Status; TPML_DIGEST_VALUES DigestList; + if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) { + return EFI_DEVICE_ERROR; + } + Status = HashAndExtend ( NewEventHdr->PCRIndex, HashData, @@ -329,6 +309,16 @@ HashLogExtendEvent ( Status = LogHashEvent (&DigestList, NewEventHdr, NewEventData); } } + + if (Status == EFI_DEVICE_ERROR) { + DEBUG ((EFI_D_ERROR, "HashLogExtendEvent - %r. Disable TPM.\n", Status)); + BuildGuidHob (&gTpmErrorHobGuid,0); + REPORT_STATUS_CODE ( + EFI_ERROR_CODE | EFI_ERROR_MINOR, + (PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR) + ); + } + return Status; } @@ -431,7 +421,6 @@ MeasureFvImage ( &TcgEventHdr, (UINT8*) &FvBlob ); - ASSERT_EFI_ERROR (Status); // // Add new FV into the measured FV list. @@ -600,7 +589,6 @@ PeimEntryMP ( if (PcdGet8 (PcdTpm2ScrtmPolicy) == 1) { Status = MeasureCRTMVersion (); - ASSERT_EFI_ERROR (Status); } Status = MeasureMainBios (); diff --git a/SecurityPkg/Tcg/TrEEPei/TrEEPei.inf b/SecurityPkg/Tcg/TrEEPei/TrEEPei.inf index faa9fb33b0..4d91dfe02d 100644 --- a/SecurityPkg/Tcg/TrEEPei/TrEEPei.inf +++ b/SecurityPkg/Tcg/TrEEPei/TrEEPei.inf @@ -3,7 +3,7 @@ # # This module will initialize TPM device, measure reported FVs and BIOS version. # -# Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -51,9 +51,11 @@ HashLib PerformanceLib MemoryAllocationLib + ReportStatusCodeLib [Guids] gTcgEventEntryHobGuid ## PRODUCES ## HOB + gTpmErrorHobGuid ## SOMETIMES_PRODUCES ## HOB gMeasuredFvHobGuid ## PRODUCES ## HOB gEfiTpmDeviceInstanceNoneGuid ## SOMETIMES_PRODUCES ## GUID # TPM device identifier gEfiTpmDeviceInstanceTpm12Guid ## SOMETIMES_PRODUCES ## GUID # TPM device identifier @@ -72,6 +74,7 @@ gEfiSecurityPkgTokenSpaceGuid.PcdTpm2SelfTestPolicy ## SOMETIMES_CONSUMES gEfiSecurityPkgTokenSpaceGuid.PcdTpm2ScrtmPolicy ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported ## CONSUMES + gEfiSecurityPkgTokenSpaceGuid.PcdStatusCodeSubClassTpmDevice ## SOMETIMES_CONSUMES [Depex] gEfiPeiMasterBootModePpiGuid AND -- cgit v1.2.3