From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 C6FCC21E47D55 for ; Thu, 24 Aug 2017 00:04:04 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Aug 2017 00:06:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,420,1498546800"; d="scan'208";a="143995836" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga006.fm.intel.com with ESMTP; 24 Aug 2017 00:06:38 -0700 Received: from fmsmsx115.amr.corp.intel.com (10.18.116.19) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 24 Aug 2017 00:06:38 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx115.amr.corp.intel.com (10.18.116.19) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 24 Aug 2017 00:06:38 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.183]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.128]) with mapi id 14.03.0319.002; Thu, 24 Aug 2017 15:06:36 +0800 From: "Zhang, Chao B" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" Thread-Topic: [edk2] [PATCH] SecurityPkg/Tcg2Dxe: Properly shutdown TPM before reset Thread-Index: AQHTHKWmkCrz9pf7/kScvECnI0QvrqKTEizw Date: Thu, 24 Aug 2017 07:06:35 +0000 Message-ID: References: <20170824065235.263800-1-ruiyu.ni@intel.com> In-Reply-To: <20170824065235.263800-1-ruiyu.ni@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 10.0.102.7 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] 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: , X-List-Received-Date: Thu, 24 Aug 2017 07:04:05 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: quoted-printable Ruiyu=1B$B!'=1B(B 3 comments=20 1. Please add debug message for TPM2_SHUTDOWN command execution status 2. Please add spec info for this behavior.=20 3. Please use protocol notify to RegisterResetNotify -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ruiy= u Ni Sent: Thursday, August 24, 2017 2:53 PM To: edk2-devel@lists.01.org Cc: Zhang, Chao B Subject: [edk2] [PATCH] SecurityPkg/Tcg2Dxe: Properly shutdown TPM before r= eset Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Chao B Zhang --- SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c | 43 +++++++++++++++++++++++++++++++++= ++++ SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf | 1 + 2 files changed, 44 insertions(+) diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c b/SecurityPkg/Tcg/Tcg2Dxe/Tc= g2Dxe.c index c2c52e32b8..e4be8f75a8 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 @@ -2437,6 +2438,36 @@ InstallTcg2 ( } =20 /** + This routine is called to properly shutdown the TPM per TCG spec. + + @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 + ) +{ + Tpm2Shutdown (TPM_SU_CLEAR); +} + +/** The driver's entry point. It publishes EFI Tcg2 Protocol. =20 @param[in] ImageHandle The firmware allocated handle for the EFI image.= =20 @@ -2461,6 +2492,7 @@ DriverEntry ( EFI_TCG2_EVENT_ALGORITHM_BITMAP TpmHashAlgorithmBitmap; UINT32 ActivePCRBanks; UINT32 NumberOfPCRBanks; + EFI_RESET_NOTIFICATION_PROTOCOL *ResetNotify; =20 mImageHandle =3D ImageHandle; =20 @@ -2609,6 +2641,17 @@ DriverEntry ( // may update SecureBoot value based on last setting. // EfiCreateProtocolNotifyEvent (&gEfiVariableWriteArchProtocolGuid, TPL_= CALLBACK, MeasureSecureBootPolicy, NULL, &Registration); + + // + // Hook the system reset to properly shutdown TPM. + // + Status =3D gBS->LocateProtocol (&gEfiResetNotificationProtocolGuid, NU= LL, (VOID **) &ResetNotify); + if (!EFI_ERROR (Status)) { + Status =3D ResetNotify->RegisterResetNotify (ResetNotify, ShutdownTp= mOnReset); + ASSERT_EFI_ERROR (Status); + } else { + DEBUG ((DEBUG_WARN, "TCG2: ResetNotification absent! Shutdown notifi= cation cannot be performed!\n")); + } } =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