]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
SecurityPkg/Tcg: Fix bug that prevented SubmitCommand buffers from being Max size
[mirror_edk2.git] / SecurityPkg / Tcg / Tcg2Dxe / Tcg2Dxe.c
index c4926f63ba0477d9b6ed913f38c29cfa930e3cbe..7720c2708db9128c66f1370c081151b7d32e9074 100644 (file)
@@ -2,6 +2,7 @@
   This module implements Tcg2 Protocol.\r
   \r
 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<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
@@ -332,14 +333,14 @@ Tcg2GetCapability (
   IN OUT EFI_TCG2_BOOT_SERVICE_CAPABILITY *ProtocolCapability\r
   )\r
 {\r
-  DEBUG ((EFI_D_INFO, "Tcg2GetCapability ...\n"));\r
+  DEBUG ((DEBUG_VERBOSE, "Tcg2GetCapability ...\n"));\r
 \r
   if ((This == NULL) || (ProtocolCapability == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   \r
-  DEBUG ((EFI_D_INFO, "Size - 0x%x\n", ProtocolCapability->Size));\r
-  DEBUG ((EFI_D_INFO, " 1.1 - 0x%x, 1.0 - 0x%x\n", sizeof(EFI_TCG2_BOOT_SERVICE_CAPABILITY), sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0)));\r
+  DEBUG ((DEBUG_VERBOSE, "Size - 0x%x\n", ProtocolCapability->Size));\r
+  DEBUG ((DEBUG_VERBOSE, " 1.1 - 0x%x, 1.0 - 0x%x\n", sizeof(EFI_TCG2_BOOT_SERVICE_CAPABILITY), sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0)));\r
 \r
   if (ProtocolCapability->Size < mTcgDxeData.BsCap.Size) {\r
     //\r
@@ -363,7 +364,7 @@ Tcg2GetCapability (
   }\r
 \r
   CopyMem (ProtocolCapability, &mTcgDxeData.BsCap, mTcgDxeData.BsCap.Size);\r
-  DEBUG ((EFI_D_INFO, "Tcg2GetCapability - %r\n", EFI_SUCCESS));\r
+  DEBUG ((DEBUG_VERBOSE, "Tcg2GetCapability - %r\n", EFI_SUCCESS));\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -817,11 +818,10 @@ TcgDxeLogEvent (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (!mTcgDxeData.GetEventLogCalled[Index]) {\r
-    EventLogAreaStruct = &mTcgDxeData.EventLogAreaStruct[Index];\r
-  } else {\r
-    EventLogAreaStruct = &mTcgDxeData.FinalEventLogAreaStruct[Index];\r
-  }\r
+  //\r
+  // Record to normal event log\r
+  //\r
+  EventLogAreaStruct = &mTcgDxeData.EventLogAreaStruct[Index];\r
 \r
   if (EventLogAreaStruct->EventLogTruncated) {\r
     return EFI_VOLUME_FULL;\r
@@ -838,15 +838,50 @@ TcgDxeLogEvent (
              NewEventSize\r
              );\r
   \r
-  if (Status == EFI_DEVICE_ERROR) {\r
-    return EFI_DEVICE_ERROR;\r
-  } else if (Status == EFI_OUT_OF_RESOURCES) {\r
+  if (Status == EFI_OUT_OF_RESOURCES) {\r
     EventLogAreaStruct->EventLogTruncated = TRUE;\r
     return EFI_VOLUME_FULL;\r
   } else if (Status == EFI_SUCCESS) {\r
     EventLogAreaStruct->EventLogStarted = TRUE;\r
-    if (mTcgDxeData.GetEventLogCalled[Index]) {\r
+  }\r
+\r
+  //\r
+  // If GetEventLog is called, record to FinalEventsTable, too.\r
+  //\r
+  if (mTcgDxeData.GetEventLogCalled[Index]) {\r
+    if (mTcgDxeData.FinalEventsTable[Index] == NULL) {\r
+      //\r
+      // no need for FinalEventsTable\r
+      //\r
+      return EFI_SUCCESS;\r
+    }\r
+    EventLogAreaStruct = &mTcgDxeData.FinalEventLogAreaStruct[Index];\r
+\r
+    if (EventLogAreaStruct->EventLogTruncated) {\r
+      return EFI_VOLUME_FULL;\r
+    }\r
+\r
+    EventLogAreaStruct->LastEvent = (UINT8*)(UINTN)EventLogAreaStruct->Lasa;\r
+    Status = TcgCommLogEvent (\r
+               &EventLogAreaStruct->LastEvent,\r
+               &EventLogAreaStruct->EventLogSize,\r
+               (UINTN)EventLogAreaStruct->Laml,\r
+               NewEventHdr,\r
+               NewEventHdrSize,\r
+               NewEventData,\r
+               NewEventSize\r
+               );\r
+    if (Status == EFI_OUT_OF_RESOURCES) {\r
+      EventLogAreaStruct->EventLogTruncated = TRUE;\r
+      return EFI_VOLUME_FULL;\r
+    } else if (Status == EFI_SUCCESS) {\r
+      EventLogAreaStruct->EventLogStarted = TRUE;\r
+      //\r
+      // Increase the NumberOfEvents in FinalEventsTable\r
+      //\r
       (mTcgDxeData.FinalEventsTable[Index])->NumberOfEvents ++;\r
+      DEBUG ((EFI_D_INFO, "FinalEventsTable->NumberOfEvents - 0x%x\n", (mTcgDxeData.FinalEventsTable[Index])->NumberOfEvents));\r
+      DEBUG ((EFI_D_INFO, "  Size - 0x%x\n", (UINTN)EventLogAreaStruct->LastEvent - (UINTN)mTcgDxeData.FinalEventsTable[Index]));\r
     }\r
   }\r
 \r
@@ -1203,7 +1238,7 @@ Tcg2HashLogExtendEvent (
   TCG_PCR_EVENT_HDR  NewEventHdr;\r
   TPML_DIGEST_VALUES DigestList;\r
 \r
-  DEBUG ((EFI_D_INFO, "Tcg2HashLogExtendEvent ...\n"));\r
+  DEBUG ((DEBUG_VERBOSE, "Tcg2HashLogExtendEvent ...\n"));\r
 \r
   if ((This == NULL) || (DataToHash == 0) || (Event == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1253,7 +1288,7 @@ Tcg2HashLogExtendEvent (
                Event->Event\r
                );\r
   }\r
-  DEBUG ((EFI_D_INFO, "Tcg2HashLogExtendEvent - %r\n", Status));\r
+  DEBUG ((DEBUG_VERBOSE, "Tcg2HashLogExtendEvent - %r\n", Status));\r
   return Status;\r
 }\r
 \r
@@ -1295,10 +1330,10 @@ Tcg2SubmitCommand (
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
-  if (InputParameterBlockSize >= mTcgDxeData.BsCap.MaxCommandSize) {\r
+  if (InputParameterBlockSize > mTcgDxeData.BsCap.MaxCommandSize) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  if (OutputParameterBlockSize >= mTcgDxeData.BsCap.MaxResponseSize) {\r
+  if (OutputParameterBlockSize > mTcgDxeData.BsCap.MaxResponseSize) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -1448,7 +1483,7 @@ SetupEventLog (
   UINT32                          DigestListBinSize;\r
   UINT32                          EventSize;\r
   TCG_EfiSpecIDEventStruct        *TcgEfiSpecIdEventStruct;\r
-  UINT8                           TempBuf[sizeof(TCG_EfiSpecIDEventStruct) + (HASH_COUNT * sizeof(TCG_EfiSpecIdEventAlgorithmSize)) + sizeof(UINT8)];\r
+  UINT8                           TempBuf[sizeof(TCG_EfiSpecIDEventStruct) + sizeof(UINT32) + (HASH_COUNT * sizeof(TCG_EfiSpecIdEventAlgorithmSize)) + sizeof(UINT8)];\r
   TCG_PCR_EVENT_HDR               FirstPcrEvent;\r
   TCG_EfiSpecIdEventAlgorithmSize *DigestSize;\r
   TCG_EfiSpecIdEventAlgorithmSize *TempDigestSize;\r
@@ -1466,7 +1501,7 @@ SetupEventLog (
       Lasa = (EFI_PHYSICAL_ADDRESS) (SIZE_4GB - 1);\r
       Status = gBS->AllocatePages (\r
                       AllocateMaxAddress,\r
-                      EfiACPIMemoryNVS,\r
+                      EfiBootServicesData,\r
                       EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcgLogAreaMinLen)),\r
                       &Lasa\r
                       );\r
@@ -1564,41 +1599,53 @@ SetupEventLog (
   //\r
   for (Index = 0; Index < sizeof(mTcg2EventInfo)/sizeof(mTcg2EventInfo[0]); Index++) {\r
     if ((mTcgDxeData.BsCap.SupportedEventLogs & mTcg2EventInfo[Index].LogFormat) != 0) {\r
-      Lasa = (EFI_PHYSICAL_ADDRESS) (SIZE_4GB - 1);\r
-      Status = gBS->AllocatePages (\r
-                      AllocateMaxAddress,\r
-                      EfiACPIMemoryNVS,\r
-                      EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcg2FinalLogAreaLen)),\r
-                      &Lasa\r
-                      );\r
-      if (EFI_ERROR (Status)) {\r
-        return Status;\r
-      }\r
-      SetMem ((VOID *)(UINTN)Lasa, PcdGet32 (PcdTcg2FinalLogAreaLen), 0xFF);\r
+      if (mTcg2EventInfo[Index].LogFormat == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) {\r
+        Lasa = (EFI_PHYSICAL_ADDRESS) (SIZE_4GB - 1);\r
+        Status = gBS->AllocatePages (\r
+                        AllocateMaxAddress,\r
+                        EfiACPIMemoryNVS,\r
+                        EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcg2FinalLogAreaLen)),\r
+                        &Lasa\r
+                        );\r
+        if (EFI_ERROR (Status)) {\r
+          return Status;\r
+        }\r
+        SetMem ((VOID *)(UINTN)Lasa, PcdGet32 (PcdTcg2FinalLogAreaLen), 0xFF);\r
 \r
-      //\r
-      // Initialize\r
-      //\r
-      mTcgDxeData.FinalEventsTable[Index] = (VOID *)(UINTN)Lasa;\r
-      (mTcgDxeData.FinalEventsTable[Index])->Version = EFI_TCG2_FINAL_EVENTS_TABLE_VERSION;\r
-      (mTcgDxeData.FinalEventsTable[Index])->NumberOfEvents = 0;\r
-\r
-      mTcgDxeData.FinalEventLogAreaStruct[Index].EventLogFormat = mTcg2EventInfo[Index].LogFormat;\r
-      mTcgDxeData.FinalEventLogAreaStruct[Index].Lasa = Lasa + sizeof(EFI_TCG2_FINAL_EVENTS_TABLE);\r
-      mTcgDxeData.FinalEventLogAreaStruct[Index].Laml = PcdGet32 (PcdTcg2FinalLogAreaLen) - sizeof(EFI_TCG2_FINAL_EVENTS_TABLE);\r
-      mTcgDxeData.FinalEventLogAreaStruct[Index].EventLogSize = 0;\r
-      mTcgDxeData.FinalEventLogAreaStruct[Index].LastEvent = (VOID *)(UINTN)mTcgDxeData.FinalEventLogAreaStruct[Index].Lasa;\r
-      mTcgDxeData.FinalEventLogAreaStruct[Index].EventLogStarted = FALSE;\r
-      mTcgDxeData.FinalEventLogAreaStruct[Index].EventLogTruncated = FALSE;\r
+        //\r
+        // Initialize\r
+        //\r
+        mTcgDxeData.FinalEventsTable[Index] = (VOID *)(UINTN)Lasa;\r
+        (mTcgDxeData.FinalEventsTable[Index])->Version = EFI_TCG2_FINAL_EVENTS_TABLE_VERSION;\r
+        (mTcgDxeData.FinalEventsTable[Index])->NumberOfEvents = 0;\r
+\r
+        mTcgDxeData.FinalEventLogAreaStruct[Index].EventLogFormat = mTcg2EventInfo[Index].LogFormat;\r
+        mTcgDxeData.FinalEventLogAreaStruct[Index].Lasa = Lasa + sizeof(EFI_TCG2_FINAL_EVENTS_TABLE);\r
+        mTcgDxeData.FinalEventLogAreaStruct[Index].Laml = PcdGet32 (PcdTcg2FinalLogAreaLen) - sizeof(EFI_TCG2_FINAL_EVENTS_TABLE);\r
+        mTcgDxeData.FinalEventLogAreaStruct[Index].EventLogSize = 0;\r
+        mTcgDxeData.FinalEventLogAreaStruct[Index].LastEvent = (VOID *)(UINTN)mTcgDxeData.FinalEventLogAreaStruct[Index].Lasa;\r
+        mTcgDxeData.FinalEventLogAreaStruct[Index].EventLogStarted = FALSE;\r
+        mTcgDxeData.FinalEventLogAreaStruct[Index].EventLogTruncated = FALSE;\r
 \r
-      if (mTcg2EventInfo[Index].LogFormat == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) {\r
         //\r
-        // Install to configuration table\r
+        // Install to configuration table for EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 \r
         //\r
-        Status = gBS->InstallConfigurationTable (&gEfiTcg2FinalEventsTableGuid, (VOID *)mTcgDxeData.FinalEventsTable[1]);\r
+        Status = gBS->InstallConfigurationTable (&gEfiTcg2FinalEventsTableGuid, (VOID *)mTcgDxeData.FinalEventsTable[Index]);\r
         if (EFI_ERROR (Status)) {\r
           return Status;\r
         }\r
+      } else {\r
+        //\r
+        // No need to handle EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2\r
+        //\r
+        mTcgDxeData.FinalEventsTable[Index] = NULL;\r
+        mTcgDxeData.FinalEventLogAreaStruct[Index].EventLogFormat = mTcg2EventInfo[Index].LogFormat;\r
+        mTcgDxeData.FinalEventLogAreaStruct[Index].Lasa = 0;\r
+        mTcgDxeData.FinalEventLogAreaStruct[Index].Laml = 0;\r
+        mTcgDxeData.FinalEventLogAreaStruct[Index].EventLogSize = 0;\r
+        mTcgDxeData.FinalEventLogAreaStruct[Index].LastEvent = 0;\r
+        mTcgDxeData.FinalEventLogAreaStruct[Index].EventLogStarted = FALSE;\r
+        mTcgDxeData.FinalEventLogAreaStruct[Index].EventLogTruncated = FALSE;\r
       }\r
     }\r
   }\r