]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SecurityPkg: Update final event log calculation.
authorYao, Jiewen <jiewen.yao@intel.com>
Mon, 18 Jan 2016 05:51:18 +0000 (05:51 +0000)
committerjyao1 <jyao1@Edk2>
Mon, 18 Jan 2016 05:51:18 +0000 (05:51 +0000)
This patch updated final event log calculation based on
TCG EFI PROTOCOL rev9, 7.1.2 "All options implementation".
The previous logic is to save event to final event log
once GetEventLog() is called. 7.1.1 shows that we should
save event log to both normal even log area and final event
log area after GetEventLog() is called.
And there is no need to record TCG12 format log to final
event log area, and normal event log area can be BootServices
memory because OS will not access it directly.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: "Yao, Jiewen" <jiewen.yao@intel.com>
Reviewed-by: "Zhang, Chao B" <chao.b.zhang@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19661 6f19259b-4bc3-4df7-8a09-765794883524

SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c

index c4926f63ba0477d9b6ed913f38c29cfa930e3cbe..b1c885e407bc17beb12b0cac6883e7eddbd8f917 100644 (file)
@@ -817,11 +817,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 +837,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
@@ -1466,7 +1500,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 +1598,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