public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] SecurityPkg/Tcg2Smm: Measure the table before patch.
@ 2019-12-07 13:43 Yao, Jiewen
  2019-12-09 15:47 ` Zhang, Chao B
  0 siblings, 1 reply; 2+ messages in thread
From: Yao, Jiewen @ 2019-12-07 13:43 UTC (permalink / raw)
  To: devel; +Cc: Jian J Wang, Chao Zhang, Jiewen Yao

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1940

According to TCG PFP specification: the ACPI table must be
measured prior to any modification, and the measurement
must be same cross every boot cycle.

There is a fix 3a63c17ebc853cbb27d190729d01e27f68e65b94
for the HID data. However that is not enough.
The LAML/LASA and PCD configuration change may also cause
similar problem.

We need measure the table before any update.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Chao Zhang <chao.b.zhang@intel.com>
Signed-off-by: Jiewen Yao <Jiewen.Yao@intel.com>
---
 SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c | 57 ++++++++++++++++---------------
 1 file changed, 30 insertions(+), 27 deletions(-)

diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
index 54966c83ce..91aebb62b8 100644
--- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
+++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
@@ -651,23 +651,11 @@ PublishAcpiTable (
              );
   ASSERT_EFI_ERROR (Status);
 
-  //
-  // Update Table version before measuring it to PCR
-  //
-  Status = UpdatePPVersion(Table, (CHAR8 *)PcdGetPtr(PcdTcgPhysicalPresenceInterfaceVer));
-  ASSERT_EFI_ERROR (Status);
-
-  DEBUG ((
-    DEBUG_INFO,
-    "Current physical presence interface version - %a\n",
-    (CHAR8 *) PcdGetPtr(PcdTcgPhysicalPresenceInterfaceVer)
-    ));
-
   //
   // Measure to PCR[0] with event EV_POST_CODE ACPI DATA.
-  // The measurement has to be done before UpdateHID since TPM2 ACPI HID
-  // imply TPM Firmware Version. Otherwise, the PCR record would be
-  // different after TPM FW update.
+  // The measurement has to be done before any update.
+  // Otherwise, the PCR record would be different after TPM FW update
+  // or the PCD configuration change.
   //
   TpmMeasureAndLogData(
     0,
@@ -678,6 +666,18 @@ PublishAcpiTable (
     TableSize
     );
 
+  //
+  // Update Table version before measuring it to PCR
+  //
+  Status = UpdatePPVersion(Table, (CHAR8 *)PcdGetPtr(PcdTcgPhysicalPresenceInterfaceVer));
+  ASSERT_EFI_ERROR (Status);
+
+  DEBUG ((
+    DEBUG_INFO,
+    "Current physical presence interface version - %a\n",
+    (CHAR8 *) PcdGetPtr(PcdTcgPhysicalPresenceInterfaceVer)
+    ));
+
   //
   // Update TPM2 HID after measuring it to PCR
   //
@@ -753,6 +753,21 @@ PublishTpm2 (
   EFI_TPM2_ACPI_CONTROL_AREA     *ControlArea;
   TPM2_PTP_INTERFACE_TYPE        InterfaceType;
 
+  //
+  // Measure to PCR[0] with event EV_POST_CODE ACPI DATA.
+  // The measurement has to be done before any update.
+  // Otherwise, the PCR record would be different after event log update
+  // or the PCD configuration change.
+  //
+  TpmMeasureAndLogData(
+    0,
+    EV_POST_CODE,
+    EV_POSTCODE_INFO_ACPI_DATA,
+    ACPI_DATA_LEN,
+    &mTpm2AcpiTemplate,
+    mTpm2AcpiTemplate.Header.Length
+    );
+
   mTpm2AcpiTemplate.Header.Revision = PcdGet8(PcdTpm2AcpiTableRev);
   DEBUG((DEBUG_INFO, "Tpm2 ACPI table revision is %d\n", mTpm2AcpiTemplate.Header.Revision));
 
@@ -776,18 +791,6 @@ PublishTpm2 (
     mTpm2AcpiTemplate.Header.Length = sizeof(EFI_TPM2_ACPI_TABLE);
   }
 
-  //
-  // Measure to PCR[0] with event EV_POST_CODE ACPI DATA
-  //
-  TpmMeasureAndLogData(
-    0,
-    EV_POST_CODE,
-    EV_POSTCODE_INFO_ACPI_DATA,
-    ACPI_DATA_LEN,
-    &mTpm2AcpiTemplate,
-    mTpm2AcpiTemplate.Header.Length
-    );
-
   InterfaceType = PcdGet8(PcdActiveTpmInterfaceType);
   switch (InterfaceType) {
   case Tpm2PtpInterfaceCrb:
-- 
2.19.2.windows.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] SecurityPkg/Tcg2Smm: Measure the table before patch.
  2019-12-07 13:43 [PATCH] SecurityPkg/Tcg2Smm: Measure the table before patch Yao, Jiewen
@ 2019-12-09 15:47 ` Zhang, Chao B
  0 siblings, 0 replies; 2+ messages in thread
From: Zhang, Chao B @ 2019-12-09 15:47 UTC (permalink / raw)
  To: Yao, Jiewen, devel@edk2.groups.io; +Cc: Wang, Jian J

Hi Jiewen:
  Reviewed-by: Chao Zhang <chao.b.zhang@intel.com>

-----Original Message-----
From: Yao, Jiewen <jiewen.yao@intel.com> 
Sent: Saturday, December 7, 2019 9:44 PM
To: devel@edk2.groups.io
Cc: Wang, Jian J <jian.j.wang@intel.com>; Zhang, Chao B <chao.b.zhang@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>
Subject: [PATCH] SecurityPkg/Tcg2Smm: Measure the table before patch.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1940

According to TCG PFP specification: the ACPI table must be measured prior to any modification, and the measurement must be same cross every boot cycle.

There is a fix 3a63c17ebc853cbb27d190729d01e27f68e65b94
for the HID data. However that is not enough.
The LAML/LASA and PCD configuration change may also cause similar problem.

We need measure the table before any update.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Chao Zhang <chao.b.zhang@intel.com>
Signed-off-by: Jiewen Yao <Jiewen.Yao@intel.com>
---
 SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c | 57 ++++++++++++++++---------------
 1 file changed, 30 insertions(+), 27 deletions(-)

diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
index 54966c83ce..91aebb62b8 100644
--- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
+++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
@@ -651,23 +651,11 @@ PublishAcpiTable (
              );
   ASSERT_EFI_ERROR (Status);
 
-  //
-  // Update Table version before measuring it to PCR
-  //
-  Status = UpdatePPVersion(Table, (CHAR8 *)PcdGetPtr(PcdTcgPhysicalPresenceInterfaceVer));
-  ASSERT_EFI_ERROR (Status);
-
-  DEBUG ((
-    DEBUG_INFO,
-    "Current physical presence interface version - %a\n",
-    (CHAR8 *) PcdGetPtr(PcdTcgPhysicalPresenceInterfaceVer)
-    ));
-
   //
   // Measure to PCR[0] with event EV_POST_CODE ACPI DATA.
-  // The measurement has to be done before UpdateHID since TPM2 ACPI HID
-  // imply TPM Firmware Version. Otherwise, the PCR record would be
-  // different after TPM FW update.
+  // The measurement has to be done before any update.
+  // Otherwise, the PCR record would be different after TPM FW update  
+ // or the PCD configuration change.
   //
   TpmMeasureAndLogData(
     0,
@@ -678,6 +666,18 @@ PublishAcpiTable (
     TableSize
     );
 
+  //
+  // Update Table version before measuring it to PCR  //  Status = 
+ UpdatePPVersion(Table, (CHAR8 
+ *)PcdGetPtr(PcdTcgPhysicalPresenceInterfaceVer));
+  ASSERT_EFI_ERROR (Status);
+
+  DEBUG ((
+    DEBUG_INFO,
+    "Current physical presence interface version - %a\n",
+    (CHAR8 *) PcdGetPtr(PcdTcgPhysicalPresenceInterfaceVer)
+    ));
+
   //
   // Update TPM2 HID after measuring it to PCR
   //
@@ -753,6 +753,21 @@ PublishTpm2 (
   EFI_TPM2_ACPI_CONTROL_AREA     *ControlArea;
   TPM2_PTP_INTERFACE_TYPE        InterfaceType;
 
+  //
+  // Measure to PCR[0] with event EV_POST_CODE ACPI DATA.
+  // The measurement has to be done before any update.
+  // Otherwise, the PCR record would be different after event log 
+ update  // or the PCD configuration change.
+  //
+  TpmMeasureAndLogData(
+    0,
+    EV_POST_CODE,
+    EV_POSTCODE_INFO_ACPI_DATA,
+    ACPI_DATA_LEN,
+    &mTpm2AcpiTemplate,
+    mTpm2AcpiTemplate.Header.Length
+    );
+
   mTpm2AcpiTemplate.Header.Revision = PcdGet8(PcdTpm2AcpiTableRev);
   DEBUG((DEBUG_INFO, "Tpm2 ACPI table revision is %d\n", mTpm2AcpiTemplate.Header.Revision));
 
@@ -776,18 +791,6 @@ PublishTpm2 (
     mTpm2AcpiTemplate.Header.Length = sizeof(EFI_TPM2_ACPI_TABLE);
   }
 
-  //
-  // Measure to PCR[0] with event EV_POST_CODE ACPI DATA
-  //
-  TpmMeasureAndLogData(
-    0,
-    EV_POST_CODE,
-    EV_POSTCODE_INFO_ACPI_DATA,
-    ACPI_DATA_LEN,
-    &mTpm2AcpiTemplate,
-    mTpm2AcpiTemplate.Header.Length
-    );
-
   InterfaceType = PcdGet8(PcdActiveTpmInterfaceType);
   switch (InterfaceType) {
   case Tpm2PtpInterfaceCrb:
--
2.19.2.windows.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-09 15:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-07 13:43 [PATCH] SecurityPkg/Tcg2Smm: Measure the table before patch Yao, Jiewen
2019-12-09 15:47 ` Zhang, Chao B

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox