From nobody Thu Dec 26 13:00:38 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1503561206412133.01966557400385; Thu, 24 Aug 2017 00:53:26 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9BAF921D2E63C; Thu, 24 Aug 2017 00:50:46 -0700 (PDT) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 88BA621D2E62B for ; Thu, 24 Aug 2017 00:50:45 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Aug 2017 00:53:20 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.2]) by fmsmga001.fm.intel.com with ESMTP; 24 Aug 2017 00:53:18 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,420,1498546800"; d="scan'208";a="1187625607" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Thu, 24 Aug 2017 15:53:17 +0800 Message-Id: <20170824075317.336300-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.12.2.windows.2 Subject: [edk2] [PATCH v2] SecurityPkg/Tcg2Dxe: Properly shutdown TPM before reset X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chao B Zhang MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Chao B Zhang Reviewed-by : Chao Zhang --- SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c | 68 +++++++++++++++++++++++++++++++++= ++++ SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf | 1 + 2 files changed, 69 insertions(+) diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c b/SecurityPkg/Tcg/Tcg2Dxe/Tc= g2Dxe.c index c2c52e32b8..e2f346217a 100644 --- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c +++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c @@ -31,6 +31,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER= EXPRESS OR IMPLIED. #include #include #include +#include =20 #include #include @@ -2413,6 +2414,68 @@ OnExitBootServicesFailed ( } =20 /** + This routine is called to properly shutdown the TPM before system reset. + It follow chapter "12.2.3 Startup State" in Trusted Platform Module Libr= ary + Part 1: Architecture, Revision 01.16. + + @param[in] ResetType The type of reset to perform. + @param[in] ResetStatus The status code for the reset. + @param[in] DataSize The size, in bytes, of ResetData. + @param[in] ResetData For a ResetType of EfiResetCold, EfiResetW= arm, or + EfiResetShutdown the data buffer starts wi= th a Null-terminated + string, optionally followed by additional = binary data. + The string is a description that the calle= r may use to further + indicate the reason for the system reset. = ResetData is only + valid if ResetStatus is something other th= an EFI_SUCCESS + unless the ResetType is EfiResetPlatformSp= ecific + where a minimum amount of ResetData is alw= ays required. + For a ResetType of EfiResetPlatformSpecifi= c the data buffer + also starts with a Null-terminated string = that is followed + by an EFI_GUID that describes the specific= type of reset to perform. +**/ +VOID +EFIAPI +ShutdownTpmOnReset ( + IN EFI_RESET_TYPE ResetType, + IN EFI_STATUS ResetStatus, + IN UINTN DataSize, + IN VOID *ResetData OPTIONAL + ) +{ + EFI_STATUS Status; + Status =3D Tpm2Shutdown (TPM_SU_CLEAR); + DEBUG ((DEBUG_VERBOSE, "Tpm2Shutdown (SU_CLEAR) - %r\n", Status)); +} + +/** + Hook the system reset to properly shutdown TPM. + It follow chapter "12.2.3 Startup State" in Trusted Platform Module Libr= ary + Part 1: Architecture, Revision 01.16. + + @param[in] Event Event whose notification function is being invoked + @param[in] Context Pointer to the notification function's context +**/ +VOID +EFIAPI +OnResetNotificationInstall ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + EFI_RESET_NOTIFICATION_PROTOCOL *ResetNotify; + + Status =3D gBS->LocateProtocol (&gEfiResetNotificationProtocolGuid, NULL= , (VOID **) &ResetNotify); + if (!EFI_ERROR (Status)) { + Status =3D ResetNotify->RegisterResetNotify (ResetNotify, ShutdownTpmO= nReset); + ASSERT_EFI_ERROR (Status); + DEBUG ((DEBUG_VERBOSE, "TCG2: Hook system reset to properly shutdown T= PM.\n")); + + gBS->CloseEvent (Event); + } +} + +/** The function install Tcg2 protocol. =20 @retval EFI_SUCCESS Tcg2 protocol is installed. @@ -2609,6 +2672,11 @@ DriverEntry ( // may update SecureBoot value based on last setting. // EfiCreateProtocolNotifyEvent (&gEfiVariableWriteArchProtocolGuid, TPL_= CALLBACK, MeasureSecureBootPolicy, NULL, &Registration); + + // + // Hook the system reset to properly shutdown TPM. + // + EfiCreateProtocolNotifyEvent (&gEfiResetNotificationProtocolGuid, TPL_= CALLBACK, OnResetNotificationInstall, NULL, &Registration); } =20 // diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf b/SecurityPkg/Tcg/Tcg2Dxe/= Tcg2Dxe.inf index 85415e8bc1..59d6dc3dfb 100644 --- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf +++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf @@ -95,6 +95,7 @@ [Protocols] gEfiAcpiTableProtocolGuid ## NOTIFY gEfiMpServiceProtocolGuid ## SOMETIMES_CONSUMES gEfiVariableWriteArchProtocolGuid ## NOTIFY + gEfiResetNotificationProtocolGuid ## CONSUMES =20 [Pcd] gEfiSecurityPkgTokenSpaceGuid.PcdTpmPlatformClass = ## SOMETIMES_CONSUMES --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel