]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SecurityPkg: Tcg2Smm: Added support for Standalone Mm
authorKun Qin <kun.q@outlook.com>
Fri, 5 Mar 2021 04:14:14 +0000 (20:14 -0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 5 Mar 2021 15:25:07 +0000 (15:25 +0000)
https://bugzilla.tianocore.org/show_bug.cgi?id=3169

This change added Standalone MM instance of Tcg2. The notify function for
Standalone MM instance is left empty.

A dependency DXE driver with a Depex of gEfiMmCommunication2ProtocolGuid
was created to indicate the readiness of Standalone MM Tcg2 driver.

Lastly, the support of CI build for Tcg2 Standalone MM module is added.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Qi Zhang <qi1.zhang@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
Message-Id: <MWHPR06MB3102C3F99CBADFCC5F8A821CF3969@MWHPR06MB3102.namprd06.prod.outlook.com>

SecurityPkg/SecurityPkg.ci.yaml
SecurityPkg/SecurityPkg.dec
SecurityPkg/SecurityPkg.dsc
SecurityPkg/Tcg/Tcg2Smm/Tcg2MmDependencyDxe.c [new file with mode: 0644]
SecurityPkg/Tcg/Tcg2Smm/Tcg2MmDependencyDxe.inf [new file with mode: 0644]
SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.c [new file with mode: 0644]
SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf [new file with mode: 0644]

index 03be2e94ca9747a8bdce6833798e379dbdae4ea7..d7b9e1f4e239daf72cb1b4565ad7f0fdd2c24efd 100644 (file)
@@ -31,6 +31,7 @@
             "MdePkg/MdePkg.dec",\r
             "MdeModulePkg/MdeModulePkg.dec",\r
             "SecurityPkg/SecurityPkg.dec",\r
+            "StandaloneMmPkg/StandaloneMmPkg.dec",\r
             "CryptoPkg/CryptoPkg.dec"\r
         ],\r
         # For host based unit tests\r
index 0970cae5c75e482ca4ef6a6f8493952be635bbda..dfbbb0365a2bd98d08c9e343b41a70f5d4fa7ca5 100644 (file)
   gEfiSecurityPkgTokenSpaceGuid.PcdTpmScrtmPolicy|1|UINT8|0x0001000E\r
 \r
   ## Guid name to identify TPM instance.<BR><BR>\r
+  #  NOTE: This Pcd must be FixedAtBuild if Standalone MM is used\r
   #  TPM_DEVICE_INTERFACE_NONE means disable.<BR>\r
   #  TPM_DEVICE_INTERFACE_TPM12 means TPM 1.2 DTPM.<BR>\r
   #  TPM_DEVICE_INTERFACE_DTPM2 means TPM 2.0 DTPM.<BR>\r
index 928bff72baa35336ba9b02dfa837c5625caf5d71..74ec429662739b7aa068180b981c36e0c3434ae6 100644 (file)
   Tcg2PhysicalPresenceLib|SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf\r
   SmmIoLib|MdePkg/Library/SmmIoLib/SmmIoLib.inf\r
 \r
+[LibraryClasses.common.MM_STANDALONE]\r
+  StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint.inf\r
+  MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.inf\r
+  Tcg2PhysicalPresenceLib|SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.inf\r
+  MemLib|StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf\r
+  HobLib|StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.inf\r
+  MemoryAllocationLib|StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.inf\r
+\r
 [PcdsDynamicDefault.common.DEFAULT]\r
   gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid|{0xb6, 0xe5, 0x01, 0x8b, 0x19, 0x4f, 0xe8, 0x46, 0xab, 0x93, 0x1c, 0x53, 0x67, 0x1b, 0x90, 0xcc}\r
   gEfiSecurityPkgTokenSpaceGuid.PcdTpm2InitializationPolicy|1\r
   SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockSmm.inf\r
   SecurityPkg/Tcg/TcgSmm/TcgSmm.inf\r
   SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf\r
+  SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf\r
+  SecurityPkg/Tcg/Tcg2Smm/Tcg2MmDependencyDxe.inf\r
   SecurityPkg/Tcg/Tcg2Acpi/Tcg2Acpi.inf\r
   SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf\r
   SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.inf\r
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2MmDependencyDxe.c b/SecurityPkg/Tcg/Tcg2Smm/Tcg2MmDependencyDxe.c
new file mode 100644 (file)
index 0000000..4f2d7c5
--- /dev/null
@@ -0,0 +1,48 @@
+/** @file\r
+  Runtime DXE part corresponding to StandaloneMM Tcg2 module.\r
+\r
+This module installs gTcg2MmSwSmiRegisteredGuid to notify readiness of\r
+StandaloneMM Tcg2 module.\r
+\r
+Copyright (c) 2019 - 2021, Arm Ltd. All rights reserved.\r
+Copyright (c) Microsoft Corporation.\r
+\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+/**\r
+  The constructor function installs gTcg2MmSwSmiRegisteredGuid to notify\r
+  readiness of StandaloneMM Tcg2 module.\r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the Management mode System Table.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Tcg2MmDependencyDxeEntryPoint (\r
+  IN EFI_HANDLE                           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE                     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_HANDLE            Handle;\r
+\r
+  Handle = NULL;\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Handle,\r
+                  &gTcg2MmSwSmiRegisteredGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2MmDependencyDxe.inf b/SecurityPkg/Tcg/Tcg2Smm/Tcg2MmDependencyDxe.inf
new file mode 100644 (file)
index 0000000..44c64cc
--- /dev/null
@@ -0,0 +1,43 @@
+## @file\r
+#  Runtime DXE part corresponding to StandaloneMM Tcg2 module.\r
+#\r
+#  This module installs gTcg2MmSwSmiRegisteredGuid to notify readiness of\r
+#  StandaloneMM Tcg2 module.\r
+#\r
+# Copyright (c) Microsoft Corporation.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x0001001A\r
+  BASE_NAME                      = Tcg2MmDependencyDxe\r
+  FILE_GUID                      = 94C210EA-3113-4563-ADEB-76FE759C2F46\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  ENTRY_POINT                    = Tcg2MmDependencyDxeEntryPoint\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64\r
+#\r
+#\r
+\r
+[Sources]\r
+  Tcg2MmDependencyDxe.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  SecurityPkg/SecurityPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  UefiBootServicesTableLib\r
+  UefiDriverEntryPoint\r
+\r
+[Guids]\r
+  gTcg2MmSwSmiRegisteredGuid         ## PRODUCES             ## GUID # Install protocol\r
+\r
+[Depex]\r
+  gEfiMmCommunication2ProtocolGuid\r
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.c b/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.c
new file mode 100644 (file)
index 0000000..9e0095e
--- /dev/null
@@ -0,0 +1,71 @@
+/** @file\r
+  TCG2 Standalone MM driver that updates TPM2 items in ACPI table and registers\r
+  SMI2 callback functions for Tcg2 physical presence, ClearMemory, and\r
+  sample for dTPM StartMethod.\r
+\r
+  Caution: This module requires additional review when modified.\r
+  This driver will have external input - variable and ACPINvs data in SMM mode.\r
+  This external input must be validated carefully to avoid security issue.\r
+\r
+  PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check.\r
+\r
+Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) Microsoft Corporation.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include "Tcg2Smm.h"\r
+#include <Library/StandaloneMmMemLib.h>\r
+\r
+/**\r
+  Notify the system that the SMM variable driver is ready.\r
+**/\r
+VOID\r
+Tcg2NotifyMmReady (\r
+  VOID\r
+  )\r
+{\r
+  // Do nothing\r
+}\r
+\r
+/**\r
+  This function is an abstraction layer for implementation specific Mm buffer validation routine.\r
+\r
+  @param Buffer  The buffer start address to be checked.\r
+  @param Length  The buffer length to be checked.\r
+\r
+  @retval TRUE  This buffer is valid per processor architecture and not overlap with SMRAM.\r
+  @retval FALSE This buffer is not valid per processor architecture or overlap with SMRAM.\r
+**/\r
+BOOLEAN\r
+IsBufferOutsideMmValid (\r
+  IN EFI_PHYSICAL_ADDRESS  Buffer,\r
+  IN UINT64                Length\r
+  )\r
+{\r
+  return MmIsBufferOutsideMmValid (Buffer, Length);\r
+}\r
+\r
+/**\r
+  The driver's entry point.\r
+\r
+  It install callbacks for TPM physical presence and MemoryClear, and locate\r
+  SMM variable to be used in the callback function.\r
+\r
+  @param[in] ImageHandle  The firmware allocated handle for the EFI image.\r
+  @param[in] SystemTable  A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS     The entry point is executed successfully.\r
+  @retval Others          Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeTcgStandaloneMm (\r
+  IN EFI_HANDLE                  ImageHandle,\r
+  IN EFI_MM_SYSTEM_TABLE         *SystemTable\r
+  )\r
+{\r
+  return InitializeTcgCommon ();\r
+}\r
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf b/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf
new file mode 100644 (file)
index 0000000..746eda3
--- /dev/null
@@ -0,0 +1,77 @@
+## @file\r
+#  Provides ACPI methods for TPM 2.0 support\r
+#\r
+#  Spec Compliance Info:\r
+#     "TCG ACPI Specification Version 1.2 Revision 8"\r
+#     "Physical Presence Interface Specification Version 1.30 Revision 00.52"\r
+#       along with\r
+#     "Errata Version 0.4 for TCG PC Client Platform Physical Presence Interface Specification"\r
+#     "Platform Reset Attack Mitigation Specification Version 1.00"\r
+#    TPM2.0 ACPI device object\r
+#     "TCG PC Client Platform Firmware Profile Specification for TPM Family 2.0 Level 00 Revision 1.03 v51"\r
+#       along with\r
+#     "Errata for PC Client Specific Platform Firmware Profile Specification Version 1.0 Revision 1.03"\r
+#\r
+#  This driver implements TPM 2.0 definition block in ACPI table and\r
+#  registers SMI callback functions for Tcg2 physical presence and\r
+#  MemoryClear to handle the requests from ACPI method.\r
+#\r
+#  Caution: This module requires additional review when modified.\r
+#  This driver will have external input - variable and ACPINvs data in SMM mode.\r
+#  This external input must be validated carefully to avoid security issue.\r
+#\r
+# Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) Microsoft Corporation.<BR>\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = Tcg2StandaloneMm\r
+  FILE_GUID                      = D40F321F-5349-4724-B667-131670587861\r
+  MODULE_TYPE                    = MM_STANDALONE\r
+  PI_SPECIFICATION_VERSION       = 0x00010032\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = InitializeTcgStandaloneMm\r
+\r
+[Sources]\r
+  Tcg2Smm.h\r
+  Tcg2Smm.c\r
+  Tcg2StandaloneMm.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  SecurityPkg/SecurityPkg.dec\r
+  StandaloneMmPkg/StandaloneMmPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  BaseMemoryLib\r
+  StandaloneMmDriverEntryPoint\r
+  MmServicesTableLib\r
+  DebugLib\r
+  Tcg2PhysicalPresenceLib\r
+  PcdLib\r
+  MemLib\r
+\r
+[Guids]\r
+  ## SOMETIMES_PRODUCES ## Variable:L"MemoryOverwriteRequestControl"\r
+  ## SOMETIMES_CONSUMES ## Variable:L"MemoryOverwriteRequestControl"\r
+  gEfiMemoryOverwriteControlDataGuid\r
+\r
+  gEfiTpmDeviceInstanceTpm20DtpmGuid                            ## PRODUCES           ## GUID       # TPM device identifier\r
+  gTpmNvsMmGuid                                                 ## CONSUMES\r
+\r
+[Protocols]\r
+  gEfiSmmSwDispatch2ProtocolGuid                                ## CONSUMES\r
+  gEfiSmmVariableProtocolGuid                                   ## CONSUMES\r
+  gEfiMmReadyToLockProtocolGuid                                 ## CONSUMES\r
+\r
+[Pcd]\r
+  gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid              ## CONSUMES\r
+\r
+[Depex]\r
+  gEfiSmmSwDispatch2ProtocolGuid AND\r
+  gEfiSmmVariableProtocolGuid\r