]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1.Measure ACPI table data comes from flash event type EV_POST_CODE ACPI DATA to PCR[0]
authorczhang46 <czhang46@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 27 Nov 2012 05:16:15 +0000 (05:16 +0000)
committerczhang46 <czhang46@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 27 Nov 2012 05:16:15 +0000 (05:16 +0000)
2.Re-measure ACPI table after fix up with event type EV_EFI_HANDOFF_TABLES to PCR[1]

Signed-off-by : Chao Zhang<chao.b.zhang@intel.com>
Reviewed-by   : Dong Guo<guo.dong@intel.com>
Reviewed-by   : Yao Jiewen<jiewen.yao@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13964 6f19259b-4bc3-4df7-8a09-765794883524

SecurityPkg/Include/Library/TpmMeasurementLib.h [new file with mode: 0644]
SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.c [new file with mode: 0644]
SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf [new file with mode: 0644]
SecurityPkg/SecurityPkg.dsc
SecurityPkg/Tcg/TcgSmm/TcgSmm.c
SecurityPkg/Tcg/TcgSmm/TcgSmm.h
SecurityPkg/Tcg/TcgSmm/TcgSmm.inf

diff --git a/SecurityPkg/Include/Library/TpmMeasurementLib.h b/SecurityPkg/Include/Library/TpmMeasurementLib.h
new file mode 100644 (file)
index 0000000..9169329
--- /dev/null
@@ -0,0 +1,45 @@
+/** @file\r
+  This library is used by other modules to measure data to TPM.\r
+\r
+Copyright (c) 2012, Intel 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
+\r
+**/\r
+\r
+#ifndef _TPM_MEASUREMENT_LIB_H_\r
+#define _TPM_MEASUREMENT_LIB_H_\r
+\r
+/**\r
+  Tpm measure and log data, and extend the measurement result into a specific PCR.\r
+\r
+  @param[in]  PcrIndex         PCR Index.\r
+  @param[in]  EventType        Event type.\r
+  @param[in]  EventLog         Measurement event log.\r
+  @param[in]  LogLen           Event log length in bytes.\r
+  @param[in]  HashData         The start of the data buffer to be hashed, extended.\r
+  @param[in]  HashDataLen      The length, in bytes, of the buffer referenced by HashData\r
+\r
+  @retval EFI_SUCCESS           Operation completed successfully.\r
+  @retval EFI_UNSUPPORTED       TPM device not available.\r
+  @retval EFI_OUT_OF_RESOURCES  Out of memory.\r
+  @retval EFI_DEVICE_ERROR      The operation was unsuccessful.\r
+**/\r
+\r
+EFI_STATUS\r
+EFIAPI \r
+TpmMeasureAndLogData (\r
+  IN UINT32             PcrIndex,\r
+  IN UINT32             EventType,\r
+  IN VOID               *EventLog,\r
+  IN UINT32             LogLen,\r
+  IN VOID               *HashData,\r
+  IN UINT64             HashDataLen\r
+  );\r
+\r
+#endif\r
diff --git a/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.c b/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.c
new file mode 100644 (file)
index 0000000..310ebfc
--- /dev/null
@@ -0,0 +1,139 @@
+/** @file\r
+  This library is used by other modules to measure data to TPM.\r
+\r
+Copyright (c) 2012, Intel 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
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Protocol/TcgService.h>\r
+\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/TpmMeasurementLib.h>\r
+\r
+#include <Guid/Acpi.h>\r
+#include <IndustryStandard/Acpi.h>\r
+\r
+\r
+\r
+/**\r
+  Tpm12 measure and log data, and extend the measurement result into a specific PCR.\r
+\r
+  @param[in]  PcrIndex         PCR Index.\r
+  @param[in]  EventType        Event type.\r
+  @param[in]  EventLog         Measurement event log.\r
+  @param[in]  LogLen           Event log length in bytes.\r
+  @param[in]  HashData         The start of the data buffer to be hashed, extended.\r
+  @param[in]  HashDataLen      The length, in bytes, of the buffer referenced by HashData\r
+\r
+  @retval EFI_SUCCESS           Operation completed successfully.\r
+  @retval EFI_UNSUPPORTED       TPM device not available.\r
+  @retval EFI_OUT_OF_RESOURCES  Out of memory.\r
+  @retval EFI_DEVICE_ERROR      The operation was unsuccessful.\r
+**/\r
+\r
+EFI_STATUS\r
+Tpm12MeasureAndLogData (\r
+  IN UINT32             PcrIndex,\r
+  IN UINT32             EventType,\r
+  IN VOID               *EventLog,\r
+  IN UINT32             LogLen,\r
+  IN VOID               *HashData,\r
+  IN UINT64             HashDataLen\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_TCG_PROTOCOL          *TcgProtocol;\r
+  TCG_PCR_EVENT             *TcgEvent;\r
+  EFI_PHYSICAL_ADDRESS      EventLogLastEntry;\r
+  UINT32                    EventNumber;\r
+\r
+  TcgEvent = NULL;\r
+\r
+  //\r
+  // Tpm active/deactive state is checked in HashLogExtendEvent\r
+  //\r
+  Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &TcgProtocol);\r
+  if (EFI_ERROR(Status)){\r
+    return Status;\r
+  }\r
+\r
+  TcgEvent = (TCG_PCR_EVENT *)AllocateZeroPool (sizeof (TCG_PCR_EVENT_HDR) + LogLen);\r
+  if(TcgEvent == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  TcgEvent->PCRIndex  = PcrIndex;\r
+  TcgEvent->EventType = EventType;\r
+  TcgEvent->EventSize = LogLen;\r
+  CopyMem (&TcgEvent->Event[0], EventLog, LogLen);\r
+  EventNumber = 1;\r
+  Status = TcgProtocol->HashLogExtendEvent (\r
+                          TcgProtocol,\r
+                          (EFI_PHYSICAL_ADDRESS)(UINTN)HashData,\r
+                          HashDataLen,\r
+                          TPM_ALG_SHA,\r
+                          TcgEvent,\r
+                          &EventNumber,\r
+                          &EventLogLastEntry\r
+                          );\r
+\r
+  FreePool (TcgEvent);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Tpm measure and log data, and extend the measurement result into a specific PCR.\r
+\r
+  @param[in]  PcrIndex         PCR Index.\r
+  @param[in]  EventType        Event type.\r
+  @param[in]  EventLog         Measurement event log.\r
+  @param[in]  LogLen           Event log length in bytes.\r
+  @param[in]  HashData         The start of the data buffer to be hashed, extended.\r
+  @param[in]  HashDataLen      The length, in bytes, of the buffer referenced by HashData\r
+\r
+  @retval EFI_SUCCESS               Operation completed successfully.\r
+  @retval EFI_UNSUPPORTED       TPM device not available.\r
+  @retval EFI_OUT_OF_RESOURCES  Out of memory.\r
+  @retval EFI_DEVICE_ERROR      The operation was unsuccessful.\r
+**/\r
+\r
+EFI_STATUS\r
+EFIAPI \r
+TpmMeasureAndLogData (\r
+  IN UINT32             PcrIndex,\r
+  IN UINT32             EventType,\r
+  IN VOID               *EventLog,\r
+  IN UINT32             LogLen,\r
+  IN VOID               *HashData,\r
+  IN UINT64             HashDataLen\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Try to measure using Tpm1.2 protocol\r
+  //\r
+  Status = Tpm12MeasureAndLogData(\r
+               PcrIndex,\r
+               EventType,\r
+               EventLog,\r
+               LogLen,\r
+               HashData,\r
+               HashDataLen\r
+               );\r
+\r
+  return Status;\r
+}\r
diff --git a/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf b/SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf
new file mode 100644 (file)
index 0000000..a09900f
--- /dev/null
@@ -0,0 +1,43 @@
+## @file\r
+#  This library is used by other modules to measure data to TPM 1.2.\r
+#\r
+# Copyright (c) 2012, Intel 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
+# 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
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxeTpmMeasurementLib\r
+  FILE_GUID                      = 30930D10-AF5B-4abf-80E6-EB4FFC0AE9D1\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = TpmMeasurementLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  DxeTpmMeasurementLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  SecurityPkg/SecurityPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  MemoryAllocationLib\r
+  UefiBootServicesTableLib\r
+\r
+[Protocols]\r
+  gEfiTcgProtocolGuid
\ No newline at end of file
index 5f3b8d709f0597c2d2a71f2c8c4f6807b3e0d9ec..9c8c9060e88efaec2e3720d9b3d3455836c03482 100644 (file)
@@ -50,6 +50,7 @@
   TpmCommLib|SecurityPkg/Library/TpmCommLib/TpmCommLib.inf\r
   PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecureLibNull.inf\r
   TcgPhysicalPresenceLib|SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.inf\r
   TpmCommLib|SecurityPkg/Library/TpmCommLib/TpmCommLib.inf\r
   PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecureLibNull.inf\r
   TcgPhysicalPresenceLib|SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.inf\r
+  TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf\r
 \r
 [LibraryClasses.common.PEIM]\r
   PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf\r
 \r
 [LibraryClasses.common.PEIM]\r
   PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf\r
index 6fa383d46d640f0cd5fab86073b8948087815daa..7a16b9ca26278adedd2a3598c89adad2c1d7c723 100644 (file)
@@ -309,6 +309,20 @@ PublishAcpiTable (
              );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
              );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+\r
+  //\r
+  // Measure to PCR[0] with event EV_POST_CODE ACPI DATA\r
+  //\r
+  TpmMeasureAndLogData(\r
+    0,\r
+    EV_POST_CODE,\r
+    EV_POSTCODE_INFO_ACPI_DATA,\r
+    ACPI_DATA_LEN,\r
+    Table,\r
+    TableSize\r
+    );\r
+\r
+\r
   ASSERT (Table->OemTableId == SIGNATURE_64 ('T', 'c', 'g', 'T', 'a', 'b', 'l', 'e'));\r
   mTcgNvs = AssignOpRegion (Table, SIGNATURE_32 ('T', 'N', 'V', 'S'), (UINT16) sizeof (TCG_NVS));\r
   ASSERT (mTcgNvs != NULL);\r
   ASSERT (Table->OemTableId == SIGNATURE_64 ('T', 'c', 'g', 'T', 'a', 'b', 'l', 'e'));\r
   mTcgNvs = AssignOpRegion (Table, SIGNATURE_32 ('T', 'N', 'V', 'S'), (UINT16) sizeof (TCG_NVS));\r
   ASSERT (mTcgNvs != NULL);\r
index 1706132d39750e0320f463200e61c0d7abac5b25..b03e49d6c9996c79259f55cba5a81dd24d7122e0 100644 (file)
@@ -17,8 +17,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <PiDxe.h>\r
 #include <IndustryStandard/Acpi.h>\r
 \r
 #include <PiDxe.h>\r
 #include <IndustryStandard/Acpi.h>\r
+#include <IndustryStandard/UefiTcgPlatform.h>\r
+\r
 #include <Guid/PhysicalPresenceData.h>\r
 #include <Guid/MemoryOverwriteControl.h>\r
 #include <Guid/PhysicalPresenceData.h>\r
 #include <Guid/MemoryOverwriteControl.h>\r
+\r
 #include <Protocol/SmmSwDispatch2.h>\r
 #include <Protocol/AcpiTable.h>\r
 #include <Protocol/SmmVariable.h>\r
 #include <Protocol/SmmSwDispatch2.h>\r
 #include <Protocol/AcpiTable.h>\r
 #include <Protocol/SmmVariable.h>\r
@@ -30,6 +33,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/UefiDriverEntryPoint.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/DxeServicesLib.h>\r
 #include <Library/UefiDriverEntryPoint.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/DxeServicesLib.h>\r
+#include <Library/TpmMeasurementLib.h>\r
 \r
 #pragma pack(1)\r
 typedef struct {\r
 \r
 #pragma pack(1)\r
 typedef struct {\r
index 9c023cfa90da1e429d122f9381d7cecc47428056..ff20a43193009316cd916b1202fa7507da793aaa 100644 (file)
@@ -44,6 +44,7 @@
   UefiBootServicesTableLib\r
   DebugLib\r
   DxeServicesLib\r
   UefiBootServicesTableLib\r
   DebugLib\r
   DxeServicesLib\r
+  TpmMeasurementLib\r
 \r
 [Guids]\r
   gEfiPhysicalPresenceGuid\r
 \r
 [Guids]\r
   gEfiPhysicalPresenceGuid\r