X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=SecurityPkg%2FTcg%2FTrEEDxe%2FTrEEDxe.c;h=a30cd5161d40210ac297124bd13be644c5b52ad1;hp=54e505d136d06c76030646e00dddfdb6a0771f78;hb=87f66b63d409fde7d2ea018b65a63986ba413f1f;hpb=61959fa9baeed976adefa2043390f2ad208d894e diff --git a/SecurityPkg/Tcg/TrEEDxe/TrEEDxe.c b/SecurityPkg/Tcg/TrEEDxe/TrEEDxe.c index 54e505d136..a30cd5161d 100644 --- a/SecurityPkg/Tcg/TrEEDxe/TrEEDxe.c +++ b/SecurityPkg/Tcg/TrEEDxe/TrEEDxe.c @@ -1,7 +1,7 @@ /** @file This module implements TrEE Protocol. -Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2013 - 2016, 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 @@ -15,11 +15,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include -#include #include #include -#include #include #include #include @@ -48,6 +46,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #define PERF_ID_TREE_DXE 0x3120 @@ -56,24 +55,19 @@ typedef struct { EFI_GUID *VendorGuid; } VARIABLE_TYPE; -#define EFI_TCG_LOG_AREA_SIZE 0x10000 - #define TREE_DEFAULT_MAX_COMMAND_SIZE 0x1000 #define TREE_DEFAULT_MAX_RESPONSE_SIZE 0x1000 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}, }; -#define TCG_EVENT_LOG_AREA_COUNT_MAX 5 +#define TCG_EVENT_LOG_AREA_COUNT_MAX 2 typedef struct { TREE_EVENT_LOG_FORMAT EventLogFormat; @@ -628,72 +622,6 @@ TcgDxeLogEvent ( return Status; } -/** - 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 return hash algorithm ID from event log format. - - @param[in] EventLogFormat Event log format. - - @return hash algorithm ID. -**/ -UINT16 -TrEEGetAlgIDFromLogFormat ( - 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].DigestAlgID; - } - } - return 0; -} - -/** - This function return boot hash algorithm from event log format. - - @param[in] EventLogFormat Event log format. - - @return boot hash algorithm. -**/ -UINT32 -TrEEGetBootHashAlgFromLogFormat ( - 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].BootHashAlg; - } - } - return TREE_BOOT_HASH_ALG_SHA1; -} - /** This function get digest from digest list. @@ -811,6 +739,10 @@ TcgDxeHashLogExtendEvent ( { EFI_STATUS Status; TPML_DIGEST_VALUES DigestList; + + if (!mTcgDxeData.BsCap.TrEEPresentFlag) { + return EFI_DEVICE_ERROR; + } Status = HashAndExtend ( NewEventHdr->PCRIndex, @@ -824,6 +756,15 @@ TcgDxeHashLogExtendEvent ( } } + if (Status == EFI_DEVICE_ERROR) { + DEBUG ((EFI_D_ERROR, "TcgDxeHashLogExtendEvent - %r. Disable TPM.\n", Status)); + mTcgDxeData.BsCap.TrEEPresentFlag = FALSE; + REPORT_STATUS_CODE ( + EFI_ERROR_CODE | EFI_ERROR_MINOR, + (PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR) + ); + } + return Status; } @@ -893,6 +834,14 @@ TreeHashLogExtendEvent ( Status = TcgDxeLogHashEvent (&DigestList, &NewEventHdr, Event->Event); } } + if (Status == EFI_DEVICE_ERROR) { + DEBUG ((EFI_D_ERROR, "MeasurePeImageAndExtend - %r. Disable TPM.\n", Status)); + mTcgDxeData.BsCap.TrEEPresentFlag = FALSE; + REPORT_STATUS_CODE ( + EFI_ERROR_CODE | EFI_ERROR_MINOR, + (PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR) + ); + } } else { Status = TcgDxeHashLogExtendEvent ( Flags, @@ -944,10 +893,10 @@ TreeSubmitCommand ( return EFI_UNSUPPORTED; } - if (InputParameterBlockSize >= mTcgDxeData.BsCap.MaxCommandSize) { + if (InputParameterBlockSize > mTcgDxeData.BsCap.MaxCommandSize) { return EFI_INVALID_PARAMETER; } - if (OutputParameterBlockSize >= mTcgDxeData.BsCap.MaxResponseSize) { + if (OutputParameterBlockSize > mTcgDxeData.BsCap.MaxResponseSize) { return EFI_INVALID_PARAMETER; } @@ -998,19 +947,19 @@ SetupEventLog ( Status = gBS->AllocatePages ( AllocateMaxAddress, EfiACPIMemoryNVS, - EFI_SIZE_TO_PAGES (EFI_TCG_LOG_AREA_SIZE), + EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcgLogAreaMinLen)), &Lasa ); if (EFI_ERROR (Status)) { return Status; } mTcgDxeData.EventLogAreaStruct[Index].Lasa = Lasa; - mTcgDxeData.EventLogAreaStruct[Index].Laml = EFI_TCG_LOG_AREA_SIZE; + mTcgDxeData.EventLogAreaStruct[Index].Laml = PcdGet32 (PcdTcgLogAreaMinLen); // // To initialize them as 0xFF is recommended // because the OS can know the last entry for that. // - SetMem ((VOID *)(UINTN)Lasa, EFI_TCG_LOG_AREA_SIZE, 0xFF); + SetMem ((VOID *)(UINTN)Lasa, PcdGet32 (PcdTcgLogAreaMinLen), 0xFF); } // @@ -1018,10 +967,10 @@ SetupEventLog ( // if (PcdGet8 (PcdTpmPlatformClass) == TCG_PLATFORM_TYPE_CLIENT) { mTcgClientAcpiTemplate.Lasa = mTcgDxeData.EventLogAreaStruct[0].Lasa; - mTcgClientAcpiTemplate.Laml = EFI_TCG_LOG_AREA_SIZE; + mTcgClientAcpiTemplate.Laml = PcdGet32 (PcdTcgLogAreaMinLen); } else { mTcgServerAcpiTemplate.Lasa = mTcgDxeData.EventLogAreaStruct[0].Lasa; - mTcgServerAcpiTemplate.Laml = EFI_TCG_LOG_AREA_SIZE; + mTcgServerAcpiTemplate.Laml = PcdGet32 (PcdTcgLogAreaMinLen); } // @@ -1093,42 +1042,13 @@ MeasureHandoffTables ( ) { EFI_STATUS Status; - SMBIOS_TABLE_ENTRY_POINT *SmbiosTable; TCG_PCR_EVENT_HDR TcgEvent; EFI_HANDOFF_TABLE_POINTERS HandoffTables; UINTN ProcessorNum; EFI_CPU_PHYSICAL_LOCATION *ProcessorLocBuf; ProcessorLocBuf = NULL; - - // - // Measure SMBIOS with EV_EFI_HANDOFF_TABLES to PCR[1] - // - Status = EfiGetSystemConfigurationTable ( - &gEfiSmbiosTableGuid, - (VOID **) &SmbiosTable - ); - - if (!EFI_ERROR (Status) && SmbiosTable != NULL) { - TcgEvent.PCRIndex = 1; - TcgEvent.EventType = EV_EFI_HANDOFF_TABLES; - TcgEvent.EventSize = sizeof (HandoffTables); - - HandoffTables.NumberOfTables = 1; - HandoffTables.TableEntry[0].VendorGuid = gEfiSmbiosTableGuid; - HandoffTables.TableEntry[0].VendorTable = SmbiosTable; - - DEBUG ((DEBUG_INFO, "The Smbios Table starts at: 0x%x\n", SmbiosTable->TableAddress)); - DEBUG ((DEBUG_INFO, "The Smbios Table size: 0x%x\n", SmbiosTable->TableLength)); - - Status = TcgDxeHashLogExtendEvent ( - 0, - (UINT8*)(UINTN)SmbiosTable->TableAddress, - SmbiosTable->TableLength, - &TcgEvent, - (UINT8*)&HandoffTables - ); - } + Status = EFI_SUCCESS; if (PcdGet8 (PcdTpmPlatformClass) == TCG_PLATFORM_TYPE_SERVER) { // @@ -1253,26 +1173,14 @@ MeasureVariable ( ); } - if (EventType == EV_EFI_VARIABLE_DRIVER_CONFIG) { - // - // Digest is the event data (EFI_VARIABLE_DATA_TREE) - // - Status = TcgDxeHashLogExtendEvent ( - 0, - (UINT8*)VarLog, - TcgEvent.EventSize, - &TcgEvent, - (UINT8*)VarLog - ); - } else { - Status = TcgDxeHashLogExtendEvent ( - 0, - (UINT8*)VarData, - VarSize, - &TcgEvent, - (UINT8*)VarLog - ); - } + Status = TcgDxeHashLogExtendEvent ( + 0, + (UINT8*)VarLog, + TcgEvent.EventSize, + &TcgEvent, + (UINT8*)VarLog + ); + FreePool (VarLog); return Status; } @@ -1614,6 +1522,9 @@ OnReadyToBoot ( Status = TcgMeasureAction ( EFI_CALLING_EFI_APPLICATION ); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "%a not Measured. Error!\n", EFI_CALLING_EFI_APPLICATION)); + } // // 2. Draw a line between pre-boot env and entering post-boot env. @@ -1621,6 +1532,9 @@ OnReadyToBoot ( // for (PcrIndex = 0; PcrIndex < 7; PcrIndex++) { Status = MeasureSeparatorEvent (PcrIndex); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "Seperator Event not Measured. Error!\n")); + } } // @@ -1641,6 +1555,9 @@ OnReadyToBoot ( Status = TcgMeasureAction ( EFI_RETURNING_FROM_EFI_APPLICATOIN ); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "%a not Measured. Error!\n", EFI_RETURNING_FROM_EFI_APPLICATOIN)); + } } DEBUG ((EFI_D_INFO, "TPM2 TrEEDxe Measure Data when ReadyToBoot\n")); @@ -1752,7 +1669,7 @@ OnExitBootServices ( EFI_EXIT_BOOT_SERVICES_INVOCATION ); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "%s not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_INVOCATION)); + DEBUG ((EFI_D_ERROR, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_INVOCATION)); } // @@ -1762,7 +1679,7 @@ OnExitBootServices ( EFI_EXIT_BOOT_SERVICES_SUCCEEDED ); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "%s not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_SUCCEEDED)); + DEBUG ((EFI_D_ERROR, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_SUCCEEDED)); } } @@ -1791,7 +1708,7 @@ OnExitBootServicesFailed ( EFI_EXIT_BOOT_SERVICES_FAILED ); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "%s not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_FAILED)); + DEBUG ((EFI_D_ERROR, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_FAILED)); } } @@ -1853,12 +1770,17 @@ DriverEntry ( return EFI_UNSUPPORTED; } + if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) { + DEBUG ((EFI_D_ERROR, "TPM2 error!\n")); + return EFI_DEVICE_ERROR; + } + Status = Tpm2RequestUseTpm (); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "TPM not detected!\n")); + DEBUG ((EFI_D_ERROR, "TPM2 not detected!\n")); return Status; } - + // // Fill information //