From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com [40.92.4.72]) by mx.groups.io with SMTP id smtpd.web08.1099.1610663818213183656 for ; Thu, 14 Jan 2021 14:36:58 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@outlook.com header.s=selector1 header.b=jHGyFh1K; spf=pass (domain: outlook.com, ip: 40.92.4.72, mailfrom: kun.q@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L19W7Y6sLHOXa2HDH8Me6Ga+z/g40VzsiI416f3Vq2pKRYJ2mJBDwE5vqDWzyT4wTWMgIx/SGYYVqci+Cx9FWTeTV6dX+YmZfX6YtQj+w4cZnXCzjQZjtuvEY8NAuuY0RL4w3VRjAjQ3sLZQbzrByCBhMljET822dieF4FfYqBk7/kfJmf526miYJWrjhfbekDfUjLm/Q3vUkGBX/9dwXhurtKGAhEkiHy/bXkCZEFnZyozdski2Oa5MqvnS5Ad1GOzjbcs4SHgRyi/QammA/4bGnGHiysEmic4xQIBA2TBidxSQRtRwQ232kp0U87BYZdY9WzqZFdWBpShe4q/APw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9Np6DQi5V0v8IPUkx6qRpF+GbevSRyO0xOwoJ9F/1n0=; b=are4cW8rK5/q5NDCAOvzvwDLF68GLO5OQnkBKoHi7bYFhugbakqXxXieAvgZkmZG/w3ukaHgD9qLyjaK4ogf9iWmqzwfYVCtFp81RqkTeB1jKaeHs9KQHbQSQ8BvijIyVQTEm2VdOFVagEJfbevDgZ2MbU7g8eH3+lsh0vc05RnYIHr8ohpHW3fxb64itQj+slTCXv4dfIdBVC6aNkOOwsx94iVWahWRhw8/9cYp/XjJN+8n/Lv04cQwQKJNDwbA66iNSNVFmwoq2UcISqDbNPT0+ZQ/Fb6UJObNl+rNpIBZ4ED3DjDt7cL/JE/NZLbyrz/T2KAjdnJyqpu/KQjvZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9Np6DQi5V0v8IPUkx6qRpF+GbevSRyO0xOwoJ9F/1n0=; b=jHGyFh1KyZy2LftEGaDRxZMh6C+Xq5EfBZ1FWpLLFwSZ1kZhdsEa+494Axyr7yG1soXqA4UCmuJpMk38uh4Y7yFEWw8Y4LHQ/w1qAuHzVwT4jQGjASuKCQKlgP3nxIORnllRh6Dw6tgJNPWiOSF9HYPqxMyanNQFZGEN0eV0Iuvt2SkNZfSL1N1w1xTccyaGHD+RIq2hEfky61+UxOww/Pc00RiLS/itmVNbIfam9vllLDKi3D0q6TpA3aCyt+/7oARgq8azLQQim1OHQ/FT7/qhIF4Pce5wk6oL4uATg3WA27aEA6jXiH7KkA+X3BAMqGmFWvoVov/h4kSkXkbsaw== Received: from CY1NAM02FT023.eop-nam02.prod.protection.outlook.com (10.152.74.60) by CY1NAM02HT150.eop-nam02.prod.protection.outlook.com (10.152.74.215) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Thu, 14 Jan 2021 22:36:57 +0000 Received: from MWHPR06MB3102.namprd06.prod.outlook.com (2a01:111:e400:7e45::41) by CY1NAM02FT023.mail.protection.outlook.com (2a01:111:e400:7e45::237) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Thu, 14 Jan 2021 22:36:57 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:FF0F61840128A103F790350BDAFEBA59C1C58AD70C657A087279A6BBF0F59B71;UpperCasedChecksum:E037C9125ACE57743306AF230F5A82631EDB170D32C679FFE6AAE74F8A0EEE06;SizeAsReceived:7532;Count:47 Received: from MWHPR06MB3102.namprd06.prod.outlook.com ([fe80::acb3:ab69:563d:b0d6]) by MWHPR06MB3102.namprd06.prod.outlook.com ([fe80::acb3:ab69:563d:b0d6%5]) with mapi id 15.20.3742.012; Thu, 14 Jan 2021 22:36:57 +0000 From: "Kun Qin" To: devel@edk2.groups.io CC: Jiewen Yao , Jian J Wang , Qi Zhang , Rahul Kumar , Jiewen Yao Subject: [PATCH v3 13/18] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce StandaloneMm instance Date: Thu, 14 Jan 2021 14:36:32 -0800 Message-ID: X-Mailer: git-send-email 2.30.0.windows.1 In-Reply-To: <20210114223637.2737-1-kun.q@outlook.com> References: <20210114223637.2737-1-kun.q@outlook.com> X-TMN: [KWYDJ3uuQEaK6jNhroSF/Di2iMuQuamx] X-ClientProxiedBy: MW4PR04CA0389.namprd04.prod.outlook.com (2603:10b6:303:81::34) To MWHPR06MB3102.namprd06.prod.outlook.com (2603:10b6:301:3e::35) Return-Path: kun.q@outlook.com X-Microsoft-Original-Message-ID: <20210114223637.2737-9-kun.q@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (50.35.88.161) by MW4PR04CA0389.namprd04.prod.outlook.com (2603:10b6:303:81::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.10 via Frontend Transport; Thu, 14 Jan 2021 22:36:56 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 47 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 640ca150-a9ff-4f05-bb87-08d8b8dce672 X-MS-TrafficTypeDiagnostic: CY1NAM02HT150: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SrV31fBYGicZmGsC2r1ekZ4HuLaywOFm7kBFoWBT716uwEXuZSOupezv07OlJDLUttJx4q1ZxCNZ1lDM2q5k9LPSNKARjda+HMLuahEXHIhGR1B5rrs3Q5/KwXa7OovY2XuRNgB0I22+eOzz6gNXxOjwnBLANo/BIxxNk6+CxaWQCEN4gJz+0we5g7/sRq6VKWulug1PTgDon8yYpP/kISpbQwBjmVow/HDJCRic8QHzv0Xv/md/PcmQJZAe6QLP X-MS-Exchange-AntiSpam-MessageData: y1+NIe2a0lkQhlSKesPbcJfdDJhJVHlOdGmoLhpctnXyaTkXMxL6mYcZLv9ErD6uWNwHGcej9v7V4HnKrO3kozAhXp9DDyTfvLTOWzM3YdQjlijNw/a2Ry7AXwk3qC+KtqdaWzH7OI+vPXQh9kcvpA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2021 22:36:57.0520 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-Network-Message-Id: 640ca150-a9ff-4f05-bb87-08d8b8dce672 X-MS-Exchange-CrossTenant-AuthSource: CY1NAM02FT023.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1NAM02HT150 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain This change added a new instance of Tcg2PhysicalPresenceLib to support MM_STANDALONE type drivers. It centralizes the common routines into shared files and abstract the library constructor into corresponding files to implement each constructor function prototypes. Cc: Jiewen Yao Cc: Jian J Wang Cc: Qi Zhang Cc: Rahul Kumar Signed-off-by: Kun Qin Reviewed-by: Jiewen Yao --- Notes: v3: - Previously reviewed. No change. =20 v2: - Added Reviewed-by tag [Jiewen] - Removed "EFIAPI" for internal functions - Updated internal function description SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/{SmmTcg2PhysicalPresenceLib= .c =3D> MmTcg2PhysicalPresenceLibCommon.c} | 33 +- SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.= c | 368 +------------------- SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPre= senceLib.c | 42 +++ SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCo= mmon.h | 34 ++ SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.= inf | 6 +- SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/{SmmTcg2PhysicalPresenceLib= .inf =3D> StandaloneMmTcg2PhysicalPresenceLib.inf} | 22 +- SecurityPkg/SecurityPkg.dsc = | 2 + 7 files changed, 113 insertions(+), 394 deletions(-) diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2Physical= PresenceLib.c b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2Physic= alPresenceLibCommon.c similarity index 90% copy from SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPre= senceLib.c copy to SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresen= ceLibCommon.c index 8afaa0a7857d..3788537db318 100644 --- a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenc= eLib.c +++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresence= LibCommon.c @@ -15,7 +15,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 -#include +#include =20 #include =20 @@ -25,7 +25,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include -#include +#include =20 #define PP_INF_VERSION_1_2 "1.2" =20 @@ -55,7 +55,7 @@ Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunctio= n ( UINTN DataSize; EFI_TCG2_PHYSICAL_PRESENCE PpData; =20 - DEBUG ((EFI_D_INFO, "[TPM2] ReturnOperationResponseToOsFunction\n")); + DEBUG ((DEBUG_INFO, "[TPM2] ReturnOperationResponseToOsFunction\n")); =20 // // Get the Physical Presence variable @@ -71,7 +71,7 @@ Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunctio= n ( if (EFI_ERROR (Status)) { *MostRecentRequest =3D 0; *Response =3D 0; - DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status =3D %r\n"= , Status)); + DEBUG ((DEBUG_ERROR, "[TPM2] Get PP variable failure! Status =3D %r\n"= , Status)); return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_FAILURE; } =20 @@ -108,7 +108,7 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx ( EFI_TCG2_PHYSICAL_PRESENCE PpData; EFI_TCG2_PHYSICAL_PRESENCE_FLAGS Flags; =20 - DEBUG ((EFI_D_INFO, "[TPM2] SubmitRequestToPreOSFunction, Request =3D %x= , %x\n", *OperationRequest, *RequestParameter)); + DEBUG ((DEBUG_INFO, "[TPM2] SubmitRequestToPreOSFunction, Request =3D %x= , %x\n", *OperationRequest, *RequestParameter)); ReturnCode =3D TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS; =20 // @@ -123,7 +123,7 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx ( &PpData ); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status =3D %r\n"= , Status)); + DEBUG ((DEBUG_ERROR, "[TPM2] Get PP variable failure! Status =3D %r\n"= , Status)); ReturnCode =3D TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE; goto EXIT; } @@ -147,7 +147,7 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx ( &PpData ); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "[TPM2] Set PP variable failure! Status =3D %r\= n", Status)); + DEBUG ((DEBUG_ERROR, "[TPM2] Set PP variable failure! Status =3D %r\= n", Status)); ReturnCode =3D TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE; goto EXIT; } @@ -173,7 +173,7 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx ( // Sync PPRQ/PPRM from PP Variable if PP submission fails // if (ReturnCode !=3D TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) { - DEBUG ((EFI_D_ERROR, "[TPM2] Submit PP Request failure! Sync PPRQ/PPRM= with PP variable.\n", Status)); + DEBUG ((DEBUG_ERROR, "[TPM2] Submit PP Request failure! Sync PPRQ/PPRM= with PP variable.\n", Status)); DataSize =3D sizeof (EFI_TCG2_PHYSICAL_PRESENCE); ZeroMem(&PpData, DataSize); Status =3D mTcg2PpSmmVariable->SmmGetVariable ( @@ -245,7 +245,7 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunctio= n ( EFI_TCG2_PHYSICAL_PRESENCE_FLAGS Flags; BOOLEAN RequestConfirmed; =20 - DEBUG ((EFI_D_INFO, "[TPM2] GetUserConfirmationStatusFunction, Request = =3D %x\n", OperationRequest)); + DEBUG ((DEBUG_INFO, "[TPM2] GetUserConfirmationStatusFunction, Request = =3D %x\n", OperationRequest)); =20 // // Get the Physical Presence variable @@ -259,7 +259,7 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunctio= n ( &PpData ); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status =3D %r\n"= , Status)); + DEBUG ((DEBUG_ERROR, "[TPM2] Get PP variable failure! Status =3D %r\n"= , Status)); return TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION; } // @@ -274,7 +274,7 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunctio= n ( &Flags ); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "[TPM2] Get PP flags failure! Status =3D %r\n", S= tatus)); + DEBUG ((DEBUG_ERROR, "[TPM2] Get PP flags failure! Status =3D %r\n", S= tatus)); return TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION; } =20 @@ -372,17 +372,12 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunct= ion ( =20 It will ASSERT() if that operation fails and it will always return EFI_S= UCCESS. =20 - @param ImageHandle The firmware allocated handle for the EFI image. - @param SystemTable A pointer to the EFI System Table. - @retval EFI_SUCCESS The constructor successfully added string package. @retval Other value The constructor can't add string package. **/ EFI_STATUS -EFIAPI -Tcg2PhysicalPresenceLibConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +Tcg2PhysicalPresenceLibCommonConstructor ( + VOID ) { EFI_STATUS Status; @@ -394,7 +389,7 @@ Tcg2PhysicalPresenceLibConstructor ( // // Locate SmmVariableProtocol. // - Status =3D gSmst->SmmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL,= (VOID**)&mTcg2PpSmmVariable); + Status =3D gMmst->MmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, = (VOID**)&mTcg2PpSmmVariable); ASSERT_EFI_ERROR (Status); =20 mTcg2PhysicalPresenceFlags =3D PcdGet32(PcdTcg2PhysicalPresenceFlags); diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2Physical= PresenceLib.c b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2Physi= calPresenceLib.c index 8afaa0a7857d..36d8b89dcdd9 100644 --- a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenc= eLib.c +++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenc= eLib.c @@ -17,355 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include =20 -#include - -#include - -#include -#include -#include -#include -#include - -#define PP_INF_VERSION_1_2 "1.2" - -EFI_SMM_VARIABLE_PROTOCOL *mTcg2PpSmmVariable; -BOOLEAN mIsTcg2PPVerLowerThan_1_3 =3D FALSE; -UINT32 mTcg2PhysicalPresenceFlags; - -/** - The handler for TPM physical presence function: - Return TPM Operation Response to OS Environment. - - This API should be invoked in OS runtime phase to interface with ACPI me= thod. - - @param[out] MostRecentRequest Most recent operation request. - @param[out] Response Response to the most recent operation = request. - - @return Return Code for Return TPM Operation Response to OS Environment. -**/ -UINT32 -EFIAPI -Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction ( - OUT UINT32 *MostRecentRequest, - OUT UINT32 *Response - ) -{ - EFI_STATUS Status; - UINTN DataSize; - EFI_TCG2_PHYSICAL_PRESENCE PpData; - - DEBUG ((EFI_D_INFO, "[TPM2] ReturnOperationResponseToOsFunction\n")); - - // - // Get the Physical Presence variable - // - DataSize =3D sizeof (EFI_TCG2_PHYSICAL_PRESENCE); - Status =3D mTcg2PpSmmVariable->SmmGetVariable ( - TCG2_PHYSICAL_PRESENCE_VARIABLE, - &gEfiTcg2PhysicalPresenceGuid, - NULL, - &DataSize, - &PpData - ); - if (EFI_ERROR (Status)) { - *MostRecentRequest =3D 0; - *Response =3D 0; - DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status =3D %r\n"= , Status)); - return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_FAILURE; - } - - *MostRecentRequest =3D PpData.LastPPRequest; - *Response =3D PpData.PPResponse; - - return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_SUCCESS; -} - -/** - The handler for TPM physical presence function: - Submit TPM Operation Request to Pre-OS Environment and - Submit TPM Operation Request to Pre-OS Environment 2. - - This API should be invoked in OS runtime phase to interface with ACPI me= thod. - - Caution: This function may receive untrusted input. - - @param[in, out] Pointer to OperationRequest TPM physical presence opera= tion request. - @param[in, out] Pointer to RequestParameter TPM physical presence opera= tion request parameter. - - @return Return Code for Submit TPM Operation Request to Pre-OS Environme= nt and - Submit TPM Operation Request to Pre-OS Environment 2. - **/ -UINT32 -Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx ( - IN OUT UINT32 *OperationRequest, - IN OUT UINT32 *RequestParameter - ) -{ - EFI_STATUS Status; - UINT32 ReturnCode; - UINTN DataSize; - EFI_TCG2_PHYSICAL_PRESENCE PpData; - EFI_TCG2_PHYSICAL_PRESENCE_FLAGS Flags; - - DEBUG ((EFI_D_INFO, "[TPM2] SubmitRequestToPreOSFunction, Request =3D %x= , %x\n", *OperationRequest, *RequestParameter)); - ReturnCode =3D TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS; - - // - // Get the Physical Presence variable - // - DataSize =3D sizeof (EFI_TCG2_PHYSICAL_PRESENCE); - Status =3D mTcg2PpSmmVariable->SmmGetVariable ( - TCG2_PHYSICAL_PRESENCE_VARIABLE, - &gEfiTcg2PhysicalPresenceGuid, - NULL, - &DataSize, - &PpData - ); - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status =3D %r\n"= , Status)); - ReturnCode =3D TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE; - goto EXIT; - } - - if ((*OperationRequest > TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) && - (*OperationRequest < TCG2_PHYSICAL_PRESENCE_STORAGE_MANAGEMENT_BEGIN= ) ) { - ReturnCode =3D TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED; - goto EXIT; - } - - if ((PpData.PPRequest !=3D *OperationRequest) || - (PpData.PPRequestParameter !=3D *RequestParameter)) { - PpData.PPRequest =3D (UINT8)*OperationRequest; - PpData.PPRequestParameter =3D *RequestParameter; - DataSize =3D sizeof (EFI_TCG2_PHYSICAL_PRESENCE); - Status =3D mTcg2PpSmmVariable->SmmSetVariable ( - TCG2_PHYSICAL_PRESENCE_VARIABLE, - &gEfiTcg2PhysicalPresenceGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABL= E_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - DataSize, - &PpData - ); - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "[TPM2] Set PP variable failure! Status =3D %r\= n", Status)); - ReturnCode =3D TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE; - goto EXIT; - } - } - - if (*OperationRequest >=3D TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERAT= ION) { - DataSize =3D sizeof (EFI_TCG2_PHYSICAL_PRESENCE_FLAGS); - Status =3D mTcg2PpSmmVariable->SmmGetVariable ( - TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE, - &gEfiTcg2PhysicalPresenceGuid, - NULL, - &DataSize, - &Flags - ); - if (EFI_ERROR (Status)) { - Flags.PPFlags =3D mTcg2PhysicalPresenceFlags; - } - ReturnCode =3D Tcg2PpVendorLibSubmitRequestToPreOSFunction (*Operation= Request, Flags.PPFlags, *RequestParameter); - } - -EXIT: - // - // Sync PPRQ/PPRM from PP Variable if PP submission fails - // - if (ReturnCode !=3D TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) { - DEBUG ((EFI_D_ERROR, "[TPM2] Submit PP Request failure! Sync PPRQ/PPRM= with PP variable.\n", Status)); - DataSize =3D sizeof (EFI_TCG2_PHYSICAL_PRESENCE); - ZeroMem(&PpData, DataSize); - Status =3D mTcg2PpSmmVariable->SmmGetVariable ( - TCG2_PHYSICAL_PRESENCE_VARIABLE, - &gEfiTcg2PhysicalPresenceGuid, - NULL, - &DataSize, - &PpData - ); - *OperationRequest =3D (UINT32)PpData.PPRequest; - *RequestParameter =3D PpData.PPRequestParameter; - } - - return ReturnCode; -} - -/** - The handler for TPM physical presence function: - Submit TPM Operation Request to Pre-OS Environment and - Submit TPM Operation Request to Pre-OS Environment 2. - - This API should be invoked in OS runtime phase to interface with ACPI me= thod. - - Caution: This function may receive untrusted input. - - @param[in] OperationRequest TPM physical presence operation request= . - @param[in] RequestParameter TPM physical presence operation request= parameter. - - @return Return Code for Submit TPM Operation Request to Pre-OS Environme= nt and - Submit TPM Operation Request to Pre-OS Environment 2. -**/ -UINT32 -EFIAPI -Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction ( - IN UINT32 OperationRequest, - IN UINT32 RequestParameter - ) -{ - UINT32 TempOperationRequest; - UINT32 TempRequestParameter; - - TempOperationRequest =3D OperationRequest; - TempRequestParameter =3D RequestParameter; - - return Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx(&TempOperat= ionRequest, &TempRequestParameter); -} - -/** - The handler for TPM physical presence function: - Get User Confirmation Status for Operation. - - This API should be invoked in OS runtime phase to interface with ACPI me= thod. - - Caution: This function may receive untrusted input. - - @param[in] OperationRequest TPM physical presence operation request= . - - @return Return Code for Get User Confirmation Status for Operation. -**/ -UINT32 -EFIAPI -Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction ( - IN UINT32 OperationRequest - ) -{ - EFI_STATUS Status; - UINTN DataSize; - EFI_TCG2_PHYSICAL_PRESENCE PpData; - EFI_TCG2_PHYSICAL_PRESENCE_FLAGS Flags; - BOOLEAN RequestConfirmed; - - DEBUG ((EFI_D_INFO, "[TPM2] GetUserConfirmationStatusFunction, Request = =3D %x\n", OperationRequest)); - - // - // Get the Physical Presence variable - // - DataSize =3D sizeof (EFI_TCG2_PHYSICAL_PRESENCE); - Status =3D mTcg2PpSmmVariable->SmmGetVariable ( - TCG2_PHYSICAL_PRESENCE_VARIABLE, - &gEfiTcg2PhysicalPresenceGuid, - NULL, - &DataSize, - &PpData - ); - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status =3D %r\n"= , Status)); - return TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION; - } - // - // Get the Physical Presence flags - // - DataSize =3D sizeof (EFI_TCG2_PHYSICAL_PRESENCE_FLAGS); - Status =3D mTcg2PpSmmVariable->SmmGetVariable ( - TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE, - &gEfiTcg2PhysicalPresenceGuid, - NULL, - &DataSize, - &Flags - ); - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "[TPM2] Get PP flags failure! Status =3D %r\n", S= tatus)); - return TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION; - } - - RequestConfirmed =3D FALSE; - - switch (OperationRequest) { - case TCG2_PHYSICAL_PRESENCE_CLEAR: - case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR: - case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_2: - case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_3: - if ((Flags.PPFlags & TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_C= LEAR) =3D=3D 0) { - RequestConfirmed =3D TRUE; - } - break; - - case TCG2_PHYSICAL_PRESENCE_NO_ACTION: - case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_CLEAR_TRUE: - RequestConfirmed =3D TRUE; - break; - - case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_CLEAR_FALSE: - break; - - case TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS: - if ((Flags.PPFlags & TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_C= HANGE_PCRS) =3D=3D 0) { - RequestConfirmed =3D TRUE; - } - break; - - case TCG2_PHYSICAL_PRESENCE_CHANGE_EPS: - if ((Flags.PPFlags & TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_C= HANGE_EPS) =3D=3D 0) { - RequestConfirmed =3D TRUE; - } - break; - - case TCG2_PHYSICAL_PRESENCE_LOG_ALL_DIGESTS: - RequestConfirmed =3D TRUE; - break; - - case TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID: - if ((Flags.PPFlags & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_F= OR_ENABLE_BLOCK_SID) =3D=3D 0) { - RequestConfirmed =3D TRUE; - } - break; - - case TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID: - if ((Flags.PPFlags & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_F= OR_DISABLE_BLOCK_SID) =3D=3D 0) { - RequestConfirmed =3D TRUE; - } - break; - - case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_= TRUE: - case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC= _TRUE: - RequestConfirmed =3D TRUE; - break; - - case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_= FALSE: - case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC= _FALSE: - break; - - default: - if (!mIsTcg2PPVerLowerThan_1_3) { - if (OperationRequest < TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPER= ATION) { - // - // TCG2 PP1.3 spec defined operations that are reserved or un-im= plemented - // - return TCG_PP_GET_USER_CONFIRMATION_NOT_IMPLEMENTED; - } - } else { - // - // TCG PP lower than 1.3. (1.0, 1.1, 1.2) - // - if (OperationRequest <=3D TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) { - RequestConfirmed =3D TRUE; - } else if (OperationRequest < TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFI= C_OPERATION) { - return TCG_PP_GET_USER_CONFIRMATION_NOT_IMPLEMENTED; - } - } - break; - } - - if (OperationRequest >=3D TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATI= ON) { - return Tcg2PpVendorLibGetUserConfirmationStatusFunction (OperationRequ= est, Flags.PPFlags); - } - - if (RequestConfirmed) { - return TCG_PP_GET_USER_CONFIRMATION_ALLOWED_AND_PPUSER_NOT_REQUIRED; - } else { - return TCG_PP_GET_USER_CONFIRMATION_ALLOWED_AND_PPUSER_REQUIRED; - } -} +#include "MmTcg2PhysicalPresenceLibCommon.h" =20 /** The constructor function locates SmmVariable protocol. @@ -380,24 +32,10 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFuncti= on ( **/ EFI_STATUS EFIAPI -Tcg2PhysicalPresenceLibConstructor ( +Tcg2PhysicalPresenceLibTraditionalConstructor ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { - EFI_STATUS Status; - - if (AsciiStrnCmp(PP_INF_VERSION_1_2, (CHAR8 *)PcdGetPtr(PcdTcgPhysicalPr= esenceInterfaceVer), sizeof(PP_INF_VERSION_1_2) - 1) >=3D 0) { - mIsTcg2PPVerLowerThan_1_3 =3D TRUE; - } - - // - // Locate SmmVariableProtocol. - // - Status =3D gSmst->SmmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL,= (VOID**)&mTcg2PpSmmVariable); - ASSERT_EFI_ERROR (Status); - - mTcg2PhysicalPresenceFlags =3D PcdGet32(PcdTcg2PhysicalPresenceFlags); - - return EFI_SUCCESS; + return Tcg2PhysicalPresenceLibCommonConstructor (); } diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg= 2PhysicalPresenceLib.c b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/Sta= ndaloneMmTcg2PhysicalPresenceLib.c new file mode 100644 index 000000000000..5c298a8d5720 --- /dev/null +++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2Physic= alPresenceLib.c @@ -0,0 +1,42 @@ +/** @file + Handle TPM 2.0 physical presence requests from OS. + + This library will handle TPM 2.0 physical presence request from OS. + + Caution: This module requires additional review when modified. + This driver will have external input - variable. + This external input must be validated carefully to avoid security issue. + + Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction() and Tcg2PhysicalPr= esenceLibGetUserConfirmationStatusFunction() + will receive untrusted input and do validation. + +Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.
+Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include "MmTcg2PhysicalPresenceLibCommon.h" + +/** + The constructor function locates SmmVariable protocol. + + It will ASSERT() if that operation fails and it will always return EFI_S= UCCESS. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor successfully added string package. + @retval Other value The constructor can't add string package. +**/ +EFI_STATUS +EFIAPI +Tcg2PhysicalPresenceLibStandaloneMmConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_MM_SYSTEM_TABLE *SystemTable + ) +{ + return Tcg2PhysicalPresenceLibCommonConstructor (); +} diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalP= resenceLibCommon.h b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2P= hysicalPresenceLibCommon.h new file mode 100644 index 000000000000..a0182739e9c8 --- /dev/null +++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresence= LibCommon.h @@ -0,0 +1,34 @@ +/** @file + Handle TPM 2.0 physical presence requests from OS. + + This library will handle TPM 2.0 physical presence request from OS. + + Caution: This module requires additional review when modified. + This driver will have external input - variable. + This external input must be validated carefully to avoid security issue. + + Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction() and Tcg2PhysicalPr= esenceLibGetUserConfirmationStatusFunction() + will receive untrusted input and do validation. + +Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _MM_TCG2_PHYSICAL_PRESENCE_LIB_COMMON_H_ +#define _MM_TCG2_PHYSICAL_PRESENCE_LIB_COMMON_H_ + +/** + The constructor function locates MmVariable protocol. + + It will ASSERT() if that operation fails and it will always return EFI_S= UCCESS. + + @retval EFI_SUCCESS The constructor successfully added string package. + @retval Other value The constructor can't add string package. +**/ +EFI_STATUS +Tcg2PhysicalPresenceLibCommonConstructor ( + VOID + ); + +#endif diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2Physical= PresenceLib.inf b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2Phy= sicalPresenceLib.inf index 6a9bdf66f0a6..d911adbdb648 100644 --- a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenc= eLib.inf +++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenc= eLib.inf @@ -20,7 +20,7 @@ [Defines] MODULE_TYPE =3D DXE_SMM_DRIVER VERSION_STRING =3D 1.0 LIBRARY_CLASS =3D Tcg2PhysicalPresenceLib|DXE_SMM_DRIVE= R - CONSTRUCTOR =3D Tcg2PhysicalPresenceLibConstructor + CONSTRUCTOR =3D Tcg2PhysicalPresenceLibTraditionalCon= structor =20 # # The following information is for reference only and not required by the = build tools. @@ -30,6 +30,8 @@ [Defines] =20 [Sources] SmmTcg2PhysicalPresenceLib.c + MmTcg2PhysicalPresenceLibCommon.c + MmTcg2PhysicalPresenceLibCommon.h =20 [Packages] MdePkg/MdePkg.dec @@ -39,7 +41,7 @@ [Packages] [LibraryClasses] DebugLib Tcg2PpVendorLib - SmmServicesTableLib + MmServicesTableLib BaseMemoryLib =20 [Guids] diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2Physical= PresenceLib.inf b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/Standalone= MmTcg2PhysicalPresenceLib.inf similarity index 64% copy from SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPre= senceLib.inf copy to SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2Phys= icalPresenceLib.inf index 6a9bdf66f0a6..6d11b6b9f198 100644 --- a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenc= eLib.inf +++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2Physic= alPresenceLib.inf @@ -8,19 +8,20 @@ # This external input must be validated carefully to avoid security issue= . # # Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.
+# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: BSD-2-Clause-Patent # ## =20 [Defines] INF_VERSION =3D 0x00010005 - BASE_NAME =3D SmmTcg2PhysicalPresenceLib - MODULE_UNI_FILE =3D SmmTcg2PhysicalPresenceLib.uni - FILE_GUID =3D AAE02741-858B-4964-9887-CA870489D944 - MODULE_TYPE =3D DXE_SMM_DRIVER + BASE_NAME =3D StandaloneMmTcg2PhysicalPresenceLib + FILE_GUID =3D 75E3D07B-689C-4F42-A8A0-46AFAE868A6F + MODULE_TYPE =3D MM_STANDALONE + PI_SPECIFICATION_VERSION =3D 0x00010032 VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D Tcg2PhysicalPresenceLib|DXE_SMM_DRIVE= R - CONSTRUCTOR =3D Tcg2PhysicalPresenceLibConstructor + LIBRARY_CLASS =3D Tcg2PhysicalPresenceLib|MM_STANDALONE + CONSTRUCTOR =3D Tcg2PhysicalPresenceLibStandaloneMmCo= nstructor =20 # # The following information is for reference only and not required by the = build tools. @@ -29,7 +30,9 @@ [Defines] # =20 [Sources] - SmmTcg2PhysicalPresenceLib.c + StandaloneMmTcg2PhysicalPresenceLib.c + MmTcg2PhysicalPresenceLibCommon.c + MmTcg2PhysicalPresenceLibCommon.h =20 [Packages] MdePkg/MdePkg.dec @@ -39,7 +42,7 @@ [Packages] [LibraryClasses] DebugLib Tcg2PpVendorLib - SmmServicesTableLib + MmServicesTableLib BaseMemoryLib =20 [Guids] @@ -48,6 +51,9 @@ [Guids] ## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresenceFlags" gEfiTcg2PhysicalPresenceGuid =20 +[Protocols] + gEfiSmmVariableProtocolGuid ## CON= SUMES + [Pcd] gEfiSecurityPkgTokenSpaceGuid.PcdTcgPhysicalPresenceInterfaceVer ## CON= SUMES gEfiSecurityPkgTokenSpaceGuid.PcdTcg2PhysicalPresenceFlags ## SOM= ETIMES_CONSUMES diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index 36d15b79f928..7240b2573e4e 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -150,6 +150,7 @@ [LibraryClasses.common.UEFI_DRIVER, LibraryClasses.comm= on.UEFI_APPLICATION] [LibraryClasses.common.DXE_SMM_DRIVER] HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableL= ib.inf + MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableLib.= inf MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAlloc= ationLib.inf ReportStatusCodeLib|MdeModulePkg/Library/SmmReportStatusCodeLib/SmmRepor= tStatusCodeLib.inf SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf @@ -316,6 +317,7 @@ [Components.IA32, Components.X64] SecurityPkg/Tcg/TcgSmm/TcgSmm.inf SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLi= b.inf + SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalP= resenceLib.inf =20 # # Random Number Generator --=20 2.30.0.windows.1