[edk2-devel] [PATCH] SecurityPkg/Tcg2Config: remove TPM2_ChangEPS if is not supported.

Zhang, Qi posted 1 patch 3 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/edk2 tags/patchew/20200611054725.3370-1-qi1.zhang@intel.com
SecurityPkg/Include/Library/Tpm2CommandLib.h        | 16 ++++++++++++++++
SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c | 40 ++++++++++++++++++++++++++++++++++++++++
SecurityPkg/Tcg/Tcg2Config/Tcg2Config.vfr           |  2 ++
SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c         |  7 +++++++
SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigNvData.h       |  1 +
5 files changed, 66 insertions(+)
[edk2-devel] [PATCH] SecurityPkg/Tcg2Config: remove TPM2_ChangEPS if is not supported.
Posted by Zhang, Qi 3 years, 10 months ago
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2793

In current implementation TPM2_ChangeEPS command is always available
in the TPM2 operation pull down list in TCG2 Configuration, which
is confusing when the command is not supported by specific TPM chip.
As a user experience improvement, TPM2_ChangeEPS command should be
removed from the list when it is not supported.
Add a new function Tpm2GetCapabilityIsCmdImpl() to query if the command
is supported.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Chao Zhang <chao.b.zhang@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Zhang, Qi <qi1.zhang@intel.com>
---
 SecurityPkg/Include/Library/Tpm2CommandLib.h        | 16 ++++++++++++++++
 SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c | 40 ++++++++++++++++++++++++++++++++++++++++
 SecurityPkg/Tcg/Tcg2Config/Tcg2Config.vfr           |  2 ++
 SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c         |  7 +++++++
 SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigNvData.h       |  1 +
 5 files changed, 66 insertions(+)

diff --git a/SecurityPkg/Include/Library/Tpm2CommandLib.h b/SecurityPkg/Include/Library/Tpm2CommandLib.h
index ce381e786b..ce7290c0f5 100644
--- a/SecurityPkg/Include/Library/Tpm2CommandLib.h
+++ b/SecurityPkg/Include/Library/Tpm2CommandLib.h
@@ -790,6 +790,22 @@ Tpm2GetCapabilityAlgorithmSet (
   OUT     UINT32      *AlgorithmSet
   );
 
+/**
+  This function will query if the command is supported.
+
+  @param[In]  Command         TPM_CC command starts from TPM_CC_FIRST.
+  @param[out] IsCmdImpl       The command is supported or not.
+
+  @retval EFI_SUCCESS            Operation completed successfully.
+  @retval EFI_DEVICE_ERROR       The command was unsuccessful.
+**/
+EFI_STATUS
+EFIAPI
+Tpm2GetCapabilityIsCmdImpl (
+  IN      TPM_CC      Command,
+  OUT     BOOLEAN     *IsCmdImpl
+  );
+
 /**
   This command is used to check to see if specific combinations of algorithm parameters are supported.
 
diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c
index 85b11c7715..0c8f980e69 100644
--- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c
+++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c
@@ -39,6 +39,8 @@ typedef struct {
 
 #pragma pack()
 
+#define TPMA_CC_COMMANDINDEX_MASK  0x2000FFFF
+
 /**
   This command returns various information regarding the TPM and its current state.
 
@@ -628,6 +630,44 @@ Tpm2GetCapabilityAlgorithmSet (
   return EFI_SUCCESS;
 }
 
+/**
+  This function will query if the command is supported.
+
+  @param[In]  Command         TPM_CC command starts from TPM_CC_FIRST.
+  @param[out] IsCmdImpl       The command is supported or not.
+
+  @retval EFI_SUCCESS            Operation completed successfully.
+  @retval EFI_DEVICE_ERROR       The command was unsuccessful.
+**/
+EFI_STATUS
+EFIAPI
+Tpm2GetCapabilityIsCmdImpl (
+  IN      TPM_CC      Command,
+  OUT     BOOLEAN     *IsCmdImpl
+  )
+{
+  TPMS_CAPABILITY_DATA    TpmCap;
+  TPMI_YES_NO             MoreData;
+  EFI_STATUS              Status;
+  UINT32                  Attribute;
+
+  Status = Tpm2GetCapability (
+             TPM_CAP_COMMANDS,
+             Command,
+             1,
+             &MoreData,
+             &TpmCap
+             );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  CopyMem (&Attribute, &TpmCap.data.command.commandAttributes[0], sizeof (UINT32));
+  *IsCmdImpl = (Command == (SwapBytes32(Attribute) & TPMA_CC_COMMANDINDEX_MASK));
+
+  return EFI_SUCCESS;
+}
+
 /**
   This command is used to check to see if specific combinations of algorithm parameters are supported.
 
diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2Config.vfr b/SecurityPkg/Tcg/Tcg2Config/Tcg2Config.vfr
index 91a463997c..47d63b009d 100644
--- a/SecurityPkg/Tcg/Tcg2Config/Tcg2Config.vfr
+++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2Config.vfr
@@ -144,7 +144,9 @@ formset
             option text = STRING_TOKEN(STR_TCG2_DISABLE), value = TCG2_PHYSICAL_PRESENCE_DISABLE, flags = RESET_REQUIRED;
             option text = STRING_TOKEN(STR_TCG2_CLEAR), value = TCG2_PHYSICAL_PRESENCE_CLEAR, flags = RESET_REQUIRED;
             option text = STRING_TOKEN(STR_TCG2_SET_PCD_BANKS), value = TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS, flags = RESET_REQUIRED;
+            suppressif ideqval TCG2_CONFIGURATION_INFO.ChangeEPSSupported == 0;
             option text = STRING_TOKEN(STR_TCG2_CHANGE_EPS), value = TCG2_PHYSICAL_PRESENCE_CHANGE_EPS, flags = RESET_REQUIRED;
+            endif
             option text = STRING_TOKEN(STR_TCG2_LOG_ALL_DIGESTS), value = TCG2_PHYSICAL_PRESENCE_LOG_ALL_DIGESTS, flags = RESET_REQUIRED;
             option text = STRING_TOKEN(STR_TCG2_DISABLE_ENDORSEMENT_ENABLE_STORAGE_HIERARCHY), value = TCG2_PHYSICAL_PRESENCE_DISABLE_ENDORSEMENT_ENABLE_STORAGE_HIERARCHY, flags = RESET_REQUIRED;
     endoneof;
diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c
index baa8fcd08d..464cacc207 100644
--- a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c
+++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c
@@ -788,6 +788,7 @@ InstallTcg2ConfigForm (
   CHAR16                          TempBuffer[1024];
   TCG2_CONFIGURATION_INFO         Tcg2ConfigInfo;
   TPM2_PTP_INTERFACE_TYPE         TpmDeviceInterfaceDetected;
+  BOOLEAN                         IsCmdImp = FALSE;
 
   DriverHandle = NULL;
   ConfigAccess = &PrivateData->ConfigAccess;
@@ -870,6 +871,12 @@ InstallTcg2ConfigForm (
     HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT), TempBuffer, NULL);
   }
 
+  Status = Tpm2GetCapabilityIsCmdImpl(TPM_CC_ChangeEPS, &IsCmdImp);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((EFI_D_ERROR, "Tpm2GetCapabilityIsCmdImpl fails %r\n", Status));
+  }
+  Tcg2ConfigInfo.ChangeEPSSupported = IsCmdImp;
+
   FillBufferWithBootHashAlg (TempBuffer, sizeof(TempBuffer), PcdGet32 (PcdTcg2HashAlgorithmBitmap));
   HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_BIOS_HASH_ALGO_CONTENT), TempBuffer, NULL);
 
diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigNvData.h b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigNvData.h
index a91c052850..b84af40a04 100644
--- a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigNvData.h
+++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigNvData.h
@@ -70,6 +70,7 @@ typedef struct {
   UINT8    TpmDeviceInterfaceAttempt;
   BOOLEAN  TpmDeviceInterfacePtpFifoSupported;
   BOOLEAN  TpmDeviceInterfacePtpCrbSupported;
+  BOOLEAN  ChangeEPSSupported;
 } TCG2_CONFIGURATION_INFO;
 
 //
-- 
2.26.2.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#61146): https://edk2.groups.io/g/devel/message/61146
Mute This Topic: https://groups.io/mt/74819043/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-