]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c
SecurityPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / SecurityPkg / Tcg / Tcg2Pei / Tcg2Pei.c
index a7ae3354b5bca3a1d81e8786bf29768b73aeef84..f28f33fdec8331ade083d6b58c49309797185c0d 100644 (file)
@@ -1,15 +1,9 @@
 /** @file\r
   Initialize TPM2 device and measure FVs before handing off control to DXE.\r
 \r
-Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
 Copyright (c) 2017, Microsoft 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
-http://opensource.org/licenses/bsd-license.php\r
-\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
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -18,7 +12,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <IndustryStandard/UefiTcgPlatform.h>\r
 #include <Ppi/FirmwareVolumeInfo.h>\r
 #include <Ppi/FirmwareVolumeInfo2.h>\r
-#include <Ppi/LockPhysicalPresence.h>\r
 #include <Ppi/TpmInitialized.h>\r
 #include <Ppi/FirmwareVolume.h>\r
 #include <Ppi/EndOfPeiPhase.h>\r
@@ -44,7 +37,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/ReportStatusCodeLib.h>\r
 #include <Library/ResetSystemLib.h>\r
-#include <Library/Tcg2PhysicalPresenceLib.h>\r
 \r
 #define PERF_ID_TCG2_PEI  0x3080\r
 \r
@@ -73,10 +65,17 @@ EFI_PEI_PPI_DESCRIPTOR  mTpmInitializationDonePpiList = {
   NULL\r
 };\r
 \r
+//\r
+// Number of firmware blobs to grow by each time we run out of room\r
+//\r
+#define FIRMWARE_BLOB_GROWTH_STEP 4\r
+\r
 EFI_PLATFORM_FIRMWARE_BLOB *mMeasuredBaseFvInfo;\r
+UINT32 mMeasuredMaxBaseFvIndex = 0;\r
 UINT32 mMeasuredBaseFvIndex = 0;\r
 \r
 EFI_PLATFORM_FIRMWARE_BLOB *mMeasuredChildFvInfo;\r
+UINT32 mMeasuredMaxChildFvIndex = 0;\r
 UINT32 mMeasuredChildFvIndex = 0;\r
 \r
 /**\r
@@ -121,12 +120,12 @@ EFI_PEI_NOTIFY_DESCRIPTOR           mNotifyList[] = {
   {\r
     EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,\r
     &gEfiPeiFirmwareVolumeInfoPpiGuid,\r
-    FirmwareVolmeInfoPpiNotifyCallback \r
+    FirmwareVolmeInfoPpiNotifyCallback\r
   },\r
   {\r
     EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,\r
     &gEfiPeiFirmwareVolumeInfo2PpiGuid,\r
-    FirmwareVolmeInfoPpiNotifyCallback \r
+    FirmwareVolmeInfoPpiNotifyCallback\r
   },\r
   {\r
     (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
@@ -138,7 +137,7 @@ EFI_PEI_NOTIFY_DESCRIPTOR           mNotifyList[] = {
 \r
 /**\r
   Record all measured Firmware Volum Information into a Guid Hob\r
-  Guid Hob payload layout is \r
+  Guid Hob payload layout is\r
 \r
      UINT32 *************************** FIRMWARE_BLOB number\r
      EFI_PLATFORM_FIRMWARE_BLOB******** BLOB Array\r
@@ -158,13 +157,15 @@ EndofPeiSignalNotifyCallBack (
   IN EFI_PEI_NOTIFY_DESCRIPTOR     *NotifyDescriptor,\r
   IN VOID                          *Ppi\r
   )\r
-{  \r
+{\r
   MEASURED_HOB_DATA *MeasuredHobData;\r
 \r
   MeasuredHobData = NULL;\r
 \r
+  PERF_CALLBACK_BEGIN (&gEfiEndOfPeiSignalPpiGuid);\r
+\r
   //\r
-  // Create a Guid hob to save all measured Fv \r
+  // Create a Guid hob to save all measured Fv\r
   //\r
   MeasuredHobData = BuildGuidHob(\r
                       &gMeasuredFvHobGuid,\r
@@ -188,6 +189,8 @@ EndofPeiSignalNotifyCallBack (
     CopyMem (&MeasuredHobData->MeasuredFvBuf[mMeasuredBaseFvIndex] , mMeasuredChildFvInfo, sizeof(EFI_PLATFORM_FIRMWARE_BLOB) * (mMeasuredChildFvIndex));\r
   }\r
 \r
+  PERF_CALLBACK_END (&gEfiEndOfPeiSignalPpiGuid);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -360,11 +363,11 @@ LogHashEvent (
   added into the Event Log.\r
 \r
   @param[in]      Flags         Bitmap providing additional information.\r
-  @param[in]      HashData      Physical address of the start of the data buffer \r
+  @param[in]      HashData      Physical address of the start of the data buffer\r
                                 to be hashed, extended, and logged.\r
   @param[in]      HashDataLen   The length, in bytes, of the buffer referenced by HashData.\r
-  @param[in]      NewEventHdr   Pointer to a TCG_PCR_EVENT_HDR data structure.  \r
-  @param[in]      NewEventData  Pointer to the new event data.  \r
+  @param[in]      NewEventHdr   Pointer to a TCG_PCR_EVENT_HDR data structure.\r
+  @param[in]      NewEventData  Pointer to the new event data.\r
 \r
   @retval EFI_SUCCESS           Operation completed successfully.\r
   @retval EFI_OUT_OF_RESOURCES  No enough memory to log the new event.\r
@@ -398,7 +401,7 @@ HashLogExtendEvent (
       Status = LogHashEvent (&DigestList, NewEventHdr, NewEventData);\r
     }\r
   }\r
-  \r
+\r
   if (Status == EFI_DEVICE_ERROR) {\r
     DEBUG ((EFI_D_ERROR, "HashLogExtendEvent - %r. Disable TPM.\n", Status));\r
     BuildGuidHob (&gTpmErrorHobGuid,0);\r
@@ -445,13 +448,13 @@ MeasureCRTMVersion (
 }\r
 \r
 /**\r
-  Measure FV image. \r
-  Add it into the measured FV list after the FV is measured successfully. \r
+  Measure FV image.\r
+  Add it into the measured FV list after the FV is measured successfully.\r
 \r
   @param[in]  FvBase            Base address of FV image.\r
   @param[in]  FvLength          Length of FV image.\r
 \r
-  @retval EFI_SUCCESS           Fv image is measured successfully \r
+  @retval EFI_SUCCESS           Fv image is measured successfully\r
                                 or it has been already measured.\r
   @retval EFI_OUT_OF_RESOURCES  No enough memory to log the new event.\r
   @retval EFI_DEVICE_ERROR      The command was unsuccessful.\r
@@ -613,13 +616,20 @@ MeasureFvImage (
   //\r
   // Add new FV into the measured FV list.\r
   //\r
-  ASSERT (mMeasuredBaseFvIndex < PcdGet32 (PcdPeiCoreMaxFvSupported));\r
-  if (mMeasuredBaseFvIndex < PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
-    mMeasuredBaseFvInfo[mMeasuredBaseFvIndex].BlobBase   = FvBase;\r
-    mMeasuredBaseFvInfo[mMeasuredBaseFvIndex].BlobLength = FvLength;\r
-    mMeasuredBaseFvIndex++;\r
+  if (mMeasuredBaseFvIndex >= mMeasuredMaxBaseFvIndex) {\r
+    mMeasuredBaseFvInfo = ReallocatePool (\r
+                            sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * mMeasuredMaxBaseFvIndex,\r
+                            sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * (mMeasuredMaxBaseFvIndex + FIRMWARE_BLOB_GROWTH_STEP),\r
+                            mMeasuredBaseFvInfo\r
+                            );\r
+    ASSERT (mMeasuredBaseFvInfo != NULL);\r
+    mMeasuredMaxBaseFvIndex = mMeasuredMaxBaseFvIndex + FIRMWARE_BLOB_GROWTH_STEP;\r
   }\r
 \r
+  mMeasuredBaseFvInfo[mMeasuredBaseFvIndex].BlobBase   = FvBase;\r
+  mMeasuredBaseFvInfo[mMeasuredBaseFvIndex].BlobLength = FvLength;\r
+  mMeasuredBaseFvIndex++;\r
+\r
   return Status;\r
 }\r
 \r
@@ -707,35 +717,41 @@ FirmwareVolmeInfoPpiNotifyCallback (
   // The PEI Core can not dispatch or load files from memory mapped FVs that do not support FvPpi.\r
   //\r
   Status = PeiServicesLocatePpi (\r
-             &Fv->FvFormat, \r
-             0, \r
+             &Fv->FvFormat,\r
+             0,\r
              NULL,\r
              (VOID**)&FvPpi\r
              );\r
   if (EFI_ERROR (Status)) {\r
     return EFI_SUCCESS;\r
   }\r
-  \r
+\r
   //\r
   // This is an FV from an FFS file, and the parent FV must have already been measured,\r
   // No need to measure twice, so just record the FV and return\r
   //\r
   if (Fv->ParentFvName != NULL || Fv->ParentFileName != NULL ) {\r
-    \r
-    ASSERT (mMeasuredChildFvIndex < PcdGet32 (PcdPeiCoreMaxFvSupported));\r
-    if (mMeasuredChildFvIndex < PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
-      //\r
-      // Check whether FV is in the measured child FV list.\r
-      //\r
-      for (Index = 0; Index < mMeasuredChildFvIndex; Index++) {\r
-        if (mMeasuredChildFvInfo[Index].BlobBase == (EFI_PHYSICAL_ADDRESS) (UINTN) Fv->FvInfo) {\r
-          return EFI_SUCCESS;\r
-        }\r
+\r
+    if (mMeasuredChildFvIndex >= mMeasuredMaxChildFvIndex) {\r
+      mMeasuredChildFvInfo = ReallocatePool (\r
+                               sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * mMeasuredMaxChildFvIndex,\r
+                               sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * (mMeasuredMaxChildFvIndex + FIRMWARE_BLOB_GROWTH_STEP),\r
+                               mMeasuredChildFvInfo\r
+                               );\r
+      ASSERT (mMeasuredChildFvInfo != NULL);\r
+      mMeasuredMaxChildFvIndex = mMeasuredMaxChildFvIndex + FIRMWARE_BLOB_GROWTH_STEP;\r
+    }\r
+    //\r
+    // Check whether FV is in the measured child FV list.\r
+    //\r
+    for (Index = 0; Index < mMeasuredChildFvIndex; Index++) {\r
+      if (mMeasuredChildFvInfo[Index].BlobBase == (EFI_PHYSICAL_ADDRESS) (UINTN) Fv->FvInfo) {\r
+        return EFI_SUCCESS;\r
       }\r
-      mMeasuredChildFvInfo[mMeasuredChildFvIndex].BlobBase   = (EFI_PHYSICAL_ADDRESS) (UINTN) Fv->FvInfo;\r
-      mMeasuredChildFvInfo[mMeasuredChildFvIndex].BlobLength = Fv->FvInfoSize;\r
-      mMeasuredChildFvIndex++;\r
     }\r
+    mMeasuredChildFvInfo[mMeasuredChildFvIndex].BlobBase   = (EFI_PHYSICAL_ADDRESS) (UINTN) Fv->FvInfo;\r
+    mMeasuredChildFvInfo[mMeasuredChildFvIndex].BlobLength = Fv->FvInfoSize;\r
+    mMeasuredChildFvIndex++;\r
     return EFI_SUCCESS;\r
   }\r
 \r
@@ -759,11 +775,6 @@ PeimEntryMP (
 {\r
   EFI_STATUS                        Status;\r
 \r
-  mMeasuredBaseFvInfo  = (EFI_PLATFORM_FIRMWARE_BLOB *) AllocateZeroPool (sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * PcdGet32 (PcdPeiCoreMaxFvSupported));\r
-  ASSERT (mMeasuredBaseFvInfo != NULL);\r
-  mMeasuredChildFvInfo = (EFI_PLATFORM_FIRMWARE_BLOB *) AllocateZeroPool (sizeof (EFI_PLATFORM_FIRMWARE_BLOB) * PcdGet32 (PcdPeiCoreMaxFvSupported));\r
-  ASSERT (mMeasuredChildFvInfo != NULL);\r
-  \r
   if (PcdGet8 (PcdTpm2ScrtmPolicy) == 1) {\r
     Status = MeasureCRTMVersion ();\r
   }\r
@@ -787,7 +798,7 @@ PeimEntryMP (
 /**\r
   Measure and log Separator event with error, and extend the measurement result into a specific PCR.\r
 \r
-  @param[in] PCRIndex         PCR index.  \r
+  @param[in] PCRIndex         PCR index.\r
 \r
   @retval EFI_SUCCESS         Operation completed successfully.\r
   @retval EFI_DEVICE_ERROR    The operation was unsuccessful.\r
@@ -887,7 +898,7 @@ PeimEntryMA (
         goto Done;\r
       }\r
     }\r
-    \r
+\r
     //\r
     // Update Tpm2HashMask according to PCR bank.\r
     //\r