SecurityPkg: Tcg2Dxe: Log Startup Locality Event
authorZhang, Chao B <chao.b.zhang@intel.com>
Sun, 22 Jan 2017 04:47:51 +0000 (12:47 +0800)
committerZhang, Chao B <chao.b.zhang@intel.com>
Tue, 24 Jan 2017 02:22:25 +0000 (10:22 +0800)
Log Startup Locality Event according to TCG PC Client PFP 00.21.
Event should be placed before any extend to PCR[0]
http://www.trustedcomputinggroup.org/wp-content/uploads/PC-ClientSpecific_Platform_Profile_for_TPM_2p0_Systems_v21.pdf

Cc: Star Zeng <star.zeng@intel.com>
Cc: Yao Jiewen <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chao Zhang <chao.b.zhang@intel.com>
Reviewed-by: Yao Jiewen <jiewen.yao@intel.com>
SecurityPkg/Include/Guid/TcgEventHob.h
SecurityPkg/SecurityPkg.dec
SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf

index 1082807c360c7d116a1537cbaeecee82adc90cbc..943a7c601c32ac9c02bcfc22947c90a7b51e5355 100644 (file)
@@ -3,7 +3,7 @@
   a TPM DXE Driver. A GUIDed HOB is generated for each measurement \r
   made in the PEI Phase.\r
     \r
   a TPM DXE Driver. A GUIDed HOB is generated for each measurement \r
   made in the PEI Phase.\r
     \r
-Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2017, 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
 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
@@ -44,4 +44,15 @@ extern EFI_GUID gTcgEvent2EntryHobGuid;
 \r
 extern EFI_GUID gTpmErrorHobGuid;\r
 \r
 \r
 extern EFI_GUID gTpmErrorHobGuid;\r
 \r
+///\r
+/// The Global ID of a GUIDed HOB used to record TPM2 Startup Locality.\r
+/// HOB payload is UINT8 according to Startup Locality Event.\r
+///\r
+#define EFI_TPM2_STARTUP_LOCALITY_HOB_GUID \\r
+  { \\r
+    0xef598499, 0xb25e, 0x473a, { 0xbf, 0xaf, 0xe7, 0xe5, 0x7d, 0xce, 0x82, 0xc4 } \\r
+  }\r
+\r
+extern EFI_GUID gTpm2StartupLocalityHobGuid;\r
+\r
 #endif\r
 #endif\r
index 0c64d25b0cbcff6607e193e4ae3f6b88dab4511b..b556fb68da1cc406772ffc3eaca2400de39ac403 100644 (file)
   #  Include/Guid/TcgEventHob.h\r
   gTpmErrorHobGuid                   = { 0xef598499, 0xb25e, 0x473a, { 0xbf, 0xaf, 0xe7, 0xe5, 0x7d, 0xce, 0x82, 0xc4 }}\r
 \r
   #  Include/Guid/TcgEventHob.h\r
   gTpmErrorHobGuid                   = { 0xef598499, 0xb25e, 0x473a, { 0xbf, 0xaf, 0xe7, 0xe5, 0x7d, 0xce, 0x82, 0xc4 }}\r
 \r
+  ## HOB GUID used to record TPM2 startup locality\r
+  ## Include/Guid/TcgEventHob.h\r
+  gTpm2StartupLocalityHobGuid        = { 0x397b0c9, 0x22e8, 0x459e, { 0xa4, 0xff, 0x99, 0xbc, 0x65, 0x27, 0x9, 0x29 }}\r
+\r
   ## HOB GUID used to pass all PEI measured FV info to DXE Driver.\r
   #  Include/Guid/MeasuredFvHob.h\r
   gMeasuredFvHobGuid                 = { 0xb2360b42, 0x7173, 0x420a, { 0x86, 0x96, 0x46, 0xca, 0x6b, 0xab, 0x10, 0x60 }}\r
   ## HOB GUID used to pass all PEI measured FV info to DXE Driver.\r
   #  Include/Guid/MeasuredFvHob.h\r
   gMeasuredFvHobGuid                 = { 0xb2360b42, 0x7173, 0x420a, { 0x86, 0x96, 0x46, 0xca, 0x6b, 0xab, 0x10, 0x60 }}\r
index 3534fd13bf66f00a493153e514ad8e2651de0635..6ea3631b025b2f360bb74ae5ece113300e973346 100644 (file)
@@ -1381,11 +1381,12 @@ SetupEventLog (
   UINT32                          HashAlgorithmMaskCopied;\r
   TCG_EfiSpecIDEventStruct        *TcgEfiSpecIdEventStruct;\r
   UINT8                           TempBuf[sizeof(TCG_EfiSpecIDEventStruct) + sizeof(UINT32) + (HASH_COUNT * sizeof(TCG_EfiSpecIdEventAlgorithmSize)) + sizeof(UINT8)];\r
   UINT32                          HashAlgorithmMaskCopied;\r
   TCG_EfiSpecIDEventStruct        *TcgEfiSpecIdEventStruct;\r
   UINT8                           TempBuf[sizeof(TCG_EfiSpecIDEventStruct) + sizeof(UINT32) + (HASH_COUNT * sizeof(TCG_EfiSpecIdEventAlgorithmSize)) + sizeof(UINT8)];\r
-  TCG_PCR_EVENT_HDR               FirstPcrEvent;\r
+  TCG_PCR_EVENT_HDR               NoActionEvent;\r
   TCG_EfiSpecIdEventAlgorithmSize *DigestSize;\r
   TCG_EfiSpecIdEventAlgorithmSize *TempDigestSize;\r
   UINT8                           *VendorInfoSize;\r
   UINT32                          NumberOfAlgorithms;\r
   TCG_EfiSpecIdEventAlgorithmSize *DigestSize;\r
   TCG_EfiSpecIdEventAlgorithmSize *TempDigestSize;\r
   UINT8                           *VendorInfoSize;\r
   UINT32                          NumberOfAlgorithms;\r
+  TCG_EfiStartupLocalityEvent     StartupLocalityEvent;\r
 \r
   DEBUG ((EFI_D_INFO, "SetupEventLog\n"));\r
 \r
 \r
   DEBUG ((EFI_D_INFO, "SetupEventLog\n"));\r
 \r
@@ -1468,24 +1469,53 @@ SetupEventLog (
         VendorInfoSize = (UINT8 *)TempDigestSize;\r
         *VendorInfoSize = 0;\r
 \r
         VendorInfoSize = (UINT8 *)TempDigestSize;\r
         *VendorInfoSize = 0;\r
 \r
-        //\r
-        // FirstPcrEvent\r
-        //\r
-        FirstPcrEvent.PCRIndex = 0;\r
-        FirstPcrEvent.EventType = EV_NO_ACTION;\r
-        ZeroMem (&FirstPcrEvent.Digest, sizeof(FirstPcrEvent.Digest));\r
-        FirstPcrEvent.EventSize = (UINT32)GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct);\r
+        NoActionEvent.PCRIndex = 0;\r
+        NoActionEvent.EventType = EV_NO_ACTION;\r
+        ZeroMem (&NoActionEvent.Digest, sizeof(NoActionEvent.Digest));\r
+        NoActionEvent.EventSize = (UINT32)GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct);\r
 \r
         //\r
 \r
         //\r
-        // Record\r
+        // Log TcgEfiSpecIdEventStruct as the first Event\r
+        //   TCG PC Client PFP spec. Section 9.2 Measurement Event Entries and Log\r
         //\r
         Status = TcgDxeLogEvent (\r
                    mTcg2EventInfo[Index].LogFormat,\r
         //\r
         Status = TcgDxeLogEvent (\r
                    mTcg2EventInfo[Index].LogFormat,\r
-                   &FirstPcrEvent,\r
-                   sizeof(FirstPcrEvent),\r
+                   &NoActionEvent,\r
+                   sizeof(NoActionEvent),\r
                    (UINT8 *)TcgEfiSpecIdEventStruct,\r
                    (UINT8 *)TcgEfiSpecIdEventStruct,\r
-                   FirstPcrEvent.EventSize\r
+                   NoActionEvent.EventSize\r
                    );\r
                    );\r
+\r
+        //\r
+        // EfiStartupLocalityEvent\r
+        //\r
+        GuidHob.Guid = GetFirstGuidHob (&gTpm2StartupLocalityHobGuid);\r
+        if (GuidHob.Guid != NULL) {\r
+          //\r
+          // Get Locality Indicator from StartupLocality HOB\r
+          //\r
+          StartupLocalityEvent.StartupLocality = *(UINT8 *)(GET_GUID_HOB_DATA (GuidHob.Guid));\r
+          CopyMem (StartupLocalityEvent.Signature, TCG_EfiStartupLocalityEvent_SIGNATURE, sizeof(StartupLocalityEvent.Signature));\r
+\r
+          NoActionEvent.PCRIndex = 0;\r
+          NoActionEvent.EventType = EV_NO_ACTION;\r
+          ZeroMem (&NoActionEvent.Digest, sizeof(NoActionEvent.Digest));\r
+          NoActionEvent.EventSize = sizeof(StartupLocalityEvent);\r
+\r
+          DEBUG ((DEBUG_INFO, "SetupEventLog: Set Locality from HOB into StartupLocalityEvent 0x%02x\n", StartupLocalityEvent.StartupLocality));\r
+\r
+          //\r
+          // Log EfiStartupLocalityEvent as the second Event\r
+          //   TCG PC Client PFP spec. Section 9.3.4.3 Startup Locality Event\r
+          //\r
+          Status = TcgDxeLogEvent (\r
+                     mTcg2EventInfo[Index].LogFormat,\r
+                     &NoActionEvent,\r
+                     sizeof(NoActionEvent),\r
+                     (UINT8 *)&StartupLocalityEvent,\r
+                     NoActionEvent.EventSize\r
+                     );\r
+        }\r
       }\r
     }\r
   }\r
       }\r
     }\r
   }\r
index 6b4c15ffdd7d41299453dbc0ec919f19ab604085..8efc4e3aad835b3d411c460d28a9f96d9de824e1 100644 (file)
@@ -7,7 +7,7 @@
 #  This external input must be validated carefully to avoid security issue like\r
 #  buffer overflow, integer overflow.\r
 #\r
 #  This external input must be validated carefully to avoid security issue like\r
 #  buffer overflow, integer overflow.\r
 #\r
-# Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2015 - 2017, 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
 # 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
@@ -80,6 +80,7 @@
   gEfiTpmDeviceInstanceTpm12Guid                     ## SOMETIMES_CONSUMES  ## GUID       # TPM device identifier\r
 \r
   gTcgEvent2EntryHobGuid                             ## SOMETIMES_CONSUMES  ## HOB\r
   gEfiTpmDeviceInstanceTpm12Guid                     ## SOMETIMES_CONSUMES  ## GUID       # TPM device identifier\r
 \r
   gTcgEvent2EntryHobGuid                             ## SOMETIMES_CONSUMES  ## HOB\r
+  gTpm2StartupLocalityHobGuid                        ## SOMETIMES_CONSUMES  ## HOB\r
 \r
 [Protocols]\r
   gEfiTcg2ProtocolGuid                               ## PRODUCES\r
 \r
 [Protocols]\r
   gEfiTcg2ProtocolGuid                               ## PRODUCES\r