From nobody Fri Dec 27 04:06:28 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) 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 1500619240104645.9015492285608; Thu, 20 Jul 2017 23:40:40 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5768121D0DE6D; Thu, 20 Jul 2017 23:38:39 -0700 (PDT) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 CB0F321CE7474 for ; Thu, 20 Jul 2017 23:38:37 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP; 20 Jul 2017 23:40:34 -0700 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.9.12]) by orsmga004.jf.intel.com with ESMTP; 20 Jul 2017 23:40:33 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,388,1496127600"; d="scan'208";a="110360755" From: Star Zeng To: edk2-devel@lists.01.org Date: Fri, 21 Jul 2017 14:40:21 +0800 Message-Id: <1500619221-300708-1-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 Subject: [edk2] [PATCH] MdeModulePkg SmmLockBoxDxeLib: Get SmmCommRegion for COMM buffer 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: Baraneedharan Anbazhagan , Jiewen Yao , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D593 Currently, SmmCommunciate fails in RestoreLockBox after SmmReadyToLock since COMM buffer is in stack instead of using SmmCommRegion by gEdkiiPiSmmCommunicationRegionTableGuid. This patch is to get SmmCommRegion by gEdkiiPiSmmCommunicationRegionTableGuid for COMM buffer Cc: Jiewen Yao Cc: Baraneedharan Anbazhagan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng Reviewed-by: Jiewen.yao@intel.com --- .../Library/SmmLockBoxLib/SmmLockBoxDxeLib.c | 199 +++++++++++++++--= ---- .../Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf | 6 +- 2 files changed, 147 insertions(+), 58 deletions(-) diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c b/MdeMod= ulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c index 9659f014e937..b75f81e69e04 100644 --- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c +++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c @@ -1,6 +1,6 @@ /** @file =20 -Copyright (c) 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
=20 This program and the accompanying materials are licensed and made available under the terms and conditions @@ -20,11 +20,108 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EIT= HER EXPRESS OR IMPLIED. #include #include #include +#include #include #include +#include =20 #include "SmmLockBoxLibPrivate.h" =20 +EFI_SMM_COMMUNICATION_PROTOCOL *mLockBoxSmmCommProtocol =3D NULL; +UINT8 *mLockBoxSmmCommBuffer =3D NULL; + +/** + Get smm communication protocol for lockbox. + + @return Pointer to smm communication protocol, NULL if not found. + +**/ +EFI_SMM_COMMUNICATION_PROTOCOL * +LockBoxGetSmmCommProtocol ( + VOID + ) +{ + EFI_STATUS Status; + + // + // If the protocol has been got previously, return it. + // + if (mLockBoxSmmCommProtocol !=3D NULL) { + return mLockBoxSmmCommProtocol; + } + + Status =3D gBS->LocateProtocol ( + &gEfiSmmCommunicationProtocolGuid, + NULL, + (VOID **)&mLockBoxSmmCommProtocol + ); + if (EFI_ERROR (Status)) { + mLockBoxSmmCommProtocol =3D NULL; + } + return mLockBoxSmmCommProtocol; +} + +/** + Get smm communication buffer for lockbox. + + @return Pointer to smm communication buffer, NULL if not found. + +**/ +UINT8 * +LockBoxGetSmmCommBuffer ( + VOID + ) +{ + EFI_STATUS Status; + UINTN MinimalSizeNeeded; + EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationRegionTable; + UINT32 Index; + EFI_MEMORY_DESCRIPTOR *Entry; + UINTN Size; + + // + // If the buffer has been got previously, return it. + // + if (mLockBoxSmmCommBuffer !=3D NULL) { + return mLockBoxSmmCommBuffer; + } + + MinimalSizeNeeded =3D sizeof (EFI_GUID) + + sizeof (UINTN) + + MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SAVE), + MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SET_ATT= RIBUTES), + MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_UP= DATE), + MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMET= ER_RESTORE), + sizeof (EFI_SMM_LOCK_BOX_PARAMET= ER_RESTORE_ALL_IN_PLACE))))); + + Status =3D EfiGetSystemConfigurationTable ( + &gEdkiiPiSmmCommunicationRegionTableGuid, + (VOID **) &PiSmmCommunicationRegionTable + ); + if (EFI_ERROR (Status)) { + mLockBoxSmmCommBuffer =3D NULL; + return mLockBoxSmmCommBuffer; + } + ASSERT (PiSmmCommunicationRegionTable !=3D NULL); + Entry =3D (EFI_MEMORY_DESCRIPTOR *) (PiSmmCommunicationRegionTable + 1); + Size =3D 0; + for (Index =3D 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries= ; Index++) { + if (Entry->Type =3D=3D EfiConventionalMemory) { + Size =3D EFI_PAGES_TO_SIZE ((UINTN) Entry->NumberOfPages); + if (Size >=3D MinimalSizeNeeded) { + break; + } + } + Entry =3D (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) Entry + PiSmmCommunicat= ionRegionTable->DescriptorSize); + } + if (Index >=3D PiSmmCommunicationRegionTable->NumberOfEntries) { + mLockBoxSmmCommBuffer =3D NULL; + } else { + mLockBoxSmmCommBuffer =3D (UINT8 *) (UINTN) Entry->PhysicalStart; + } + return mLockBoxSmmCommBuffer; +} + /** This function will save confidential information to lockbox. =20 @@ -52,7 +149,8 @@ SaveLockBox ( EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication; EFI_SMM_LOCK_BOX_PARAMETER_SAVE *LockBoxParameterSave; EFI_SMM_COMMUNICATE_HEADER *CommHeader; - UINT8 CommBuffer[sizeof(EFI_GUID) + sizeof(UIN= TN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE)]; + UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof= (UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE)]; + UINT8 *CommBuffer; UINTN CommSize; =20 DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib SaveLockBox - Enter\n")); @@ -64,21 +162,18 @@ SaveLockBox ( return EFI_INVALID_PARAMETER; } =20 - // - // Get needed resource - // - Status =3D gBS->LocateProtocol ( - &gEfiSmmCommunicationProtocolGuid, - NULL, - (VOID **)&SmmCommunication - ); - if (EFI_ERROR (Status)) { + SmmCommunication =3D LockBoxGetSmmCommProtocol (); + if (SmmCommunication =3D=3D NULL) { return EFI_NOT_STARTED; } =20 // // Prepare parameter // + CommBuffer =3D LockBoxGetSmmCommBuffer (); + if (CommBuffer =3D=3D NULL) { + CommBuffer =3D &TempCommBuffer[0]; + } CommHeader =3D (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, size= of(gEfiSmmLockBoxCommunicationGuid)); CommHeader->MessageLength =3D sizeof(*LockBoxParameterSave); @@ -94,7 +189,7 @@ SaveLockBox ( // // Send command // - CommSize =3D sizeof(CommBuffer); + CommSize =3D sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_= PARAMETER_SAVE); Status =3D SmmCommunication->Communicate ( SmmCommunication, &CommBuffer[0], @@ -136,7 +231,8 @@ SetLockBoxAttributes ( EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication; EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES *LockBoxParameterSetAttributes; EFI_SMM_COMMUNICATE_HEADER *CommHeader; - UINT8 CommBuffer[sizeof(EFI_GUID) + = sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES)]; + UINT8 TempCommBuffer[sizeof(EFI_GUID= ) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES)]; + UINT8 *CommBuffer; UINTN CommSize; =20 DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib SetLockBoxAttributes - Enter\n")); @@ -149,21 +245,18 @@ SetLockBoxAttributes ( return EFI_INVALID_PARAMETER; } =20 - // - // Get needed resource - // - Status =3D gBS->LocateProtocol ( - &gEfiSmmCommunicationProtocolGuid, - NULL, - (VOID **)&SmmCommunication - ); - if (EFI_ERROR (Status)) { + SmmCommunication =3D LockBoxGetSmmCommProtocol (); + if (SmmCommunication =3D=3D NULL) { return EFI_NOT_STARTED; } =20 // // Prepare parameter // + CommBuffer =3D LockBoxGetSmmCommBuffer (); + if (CommBuffer =3D=3D NULL) { + CommBuffer =3D &TempCommBuffer[0]; + } CommHeader =3D (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, size= of(gEfiSmmLockBoxCommunicationGuid)); CommHeader->MessageLength =3D sizeof(*LockBoxParameterSetAttributes); @@ -178,7 +271,7 @@ SetLockBoxAttributes ( // // Send command // - CommSize =3D sizeof(CommBuffer); + CommSize =3D sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_= PARAMETER_SET_ATTRIBUTES); Status =3D SmmCommunication->Communicate ( SmmCommunication, &CommBuffer[0], @@ -225,7 +318,8 @@ UpdateLockBox ( EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication; EFI_SMM_LOCK_BOX_PARAMETER_UPDATE *LockBoxParameterUpdate; EFI_SMM_COMMUNICATE_HEADER *CommHeader; - UINT8 CommBuffer[sizeof(EFI_GUID) + sizeof(U= INTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE)]; + UINT8 TempCommBuffer[sizeof(EFI_GUID) + size= of(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE)]; + UINT8 *CommBuffer; UINTN CommSize; =20 DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib UpdateLockBox - Enter\n")); @@ -237,21 +331,18 @@ UpdateLockBox ( return EFI_INVALID_PARAMETER; } =20 - // - // Get needed resource - // - Status =3D gBS->LocateProtocol ( - &gEfiSmmCommunicationProtocolGuid, - NULL, - (VOID **)&SmmCommunication - ); - if (EFI_ERROR (Status)) { + SmmCommunication =3D LockBoxGetSmmCommProtocol (); + if (SmmCommunication =3D=3D NULL) { return EFI_NOT_STARTED; } =20 // // Prepare parameter // + CommBuffer =3D LockBoxGetSmmCommBuffer (); + if (CommBuffer =3D=3D NULL) { + CommBuffer =3D &TempCommBuffer[0]; + } CommHeader =3D (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, size= of(gEfiSmmLockBoxCommunicationGuid)); CommHeader->MessageLength =3D sizeof(*LockBoxParameterUpdate); @@ -268,7 +359,7 @@ UpdateLockBox ( // // Send command // - CommSize =3D sizeof(CommBuffer); + CommSize =3D sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_= PARAMETER_UPDATE); Status =3D SmmCommunication->Communicate ( SmmCommunication, &CommBuffer[0], @@ -316,7 +407,8 @@ RestoreLockBox ( EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication; EFI_SMM_LOCK_BOX_PARAMETER_RESTORE *LockBoxParameterRestore; EFI_SMM_COMMUNICATE_HEADER *CommHeader; - UINT8 CommBuffer[sizeof(EFI_GUID) + sizeof(= UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE)]; + UINT8 TempCommBuffer[sizeof(EFI_GUID) + siz= eof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE)]; + UINT8 *CommBuffer; UINTN CommSize; =20 DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib RestoreLockBox - Enter\n")); @@ -330,21 +422,18 @@ RestoreLockBox ( return EFI_INVALID_PARAMETER; } =20 - // - // Get needed resource - // - Status =3D gBS->LocateProtocol ( - &gEfiSmmCommunicationProtocolGuid, - NULL, - (VOID **)&SmmCommunication - ); - if (EFI_ERROR (Status)) { + SmmCommunication =3D LockBoxGetSmmCommProtocol (); + if (SmmCommunication =3D=3D NULL) { return EFI_NOT_STARTED; } =20 // // Prepare parameter // + CommBuffer =3D LockBoxGetSmmCommBuffer (); + if (CommBuffer =3D=3D NULL) { + CommBuffer =3D &TempCommBuffer[0]; + } CommHeader =3D (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, size= of(gEfiSmmLockBoxCommunicationGuid)); CommHeader->MessageLength =3D sizeof(*LockBoxParameterRestore); @@ -364,7 +453,7 @@ RestoreLockBox ( // // Send command // - CommSize =3D sizeof(CommBuffer); + CommSize =3D sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_= PARAMETER_RESTORE); Status =3D SmmCommunication->Communicate ( SmmCommunication, &CommBuffer[0], @@ -403,26 +492,24 @@ RestoreAllLockBoxInPlace ( EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication; EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE *LockBoxParameterRestore= AllInPlace; EFI_SMM_COMMUNICATE_HEADER *CommHeader; - UINT8 CommBuffer[sizeof(EFI_GU= ID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLAC= E)]; + UINT8 TempCommBuffer[sizeof(EF= I_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_= PLACE)]; + UINT8 *CommBuffer; UINTN CommSize; =20 DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib RestoreAllLockBoxInPlace - Enter\n= ")); =20 - // - // Get needed resource - // - Status =3D gBS->LocateProtocol ( - &gEfiSmmCommunicationProtocolGuid, - NULL, - (VOID **)&SmmCommunication - ); - if (EFI_ERROR (Status)) { + SmmCommunication =3D LockBoxGetSmmCommProtocol (); + if (SmmCommunication =3D=3D NULL) { return EFI_NOT_STARTED; } =20 // // Prepare parameter // + CommBuffer =3D LockBoxGetSmmCommBuffer (); + if (CommBuffer =3D=3D NULL) { + CommBuffer =3D &TempCommBuffer[0]; + } CommHeader =3D (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, size= of(gEfiSmmLockBoxCommunicationGuid)); CommHeader->MessageLength =3D sizeof(*LockBoxParameterRestoreAllInPlace); @@ -435,7 +522,7 @@ RestoreAllLockBoxInPlace ( // // Send command // - CommSize =3D sizeof(CommBuffer); + CommSize =3D sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_= PARAMETER_RESTORE_ALL_IN_PLACE); Status =3D SmmCommunication->Communicate ( SmmCommunication, &CommBuffer[0], diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf b/MdeM= odulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf index 48cdb9c66ab7..f3120ccb42d5 100644 --- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf +++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf @@ -1,7 +1,7 @@ ## @file # DXE LockBox library instance. # -# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions @@ -42,9 +42,11 @@ [LibraryClasses] BaseLib BaseMemoryLib DebugLib + UefiLib =20 [Guids] - gEfiSmmLockBoxCommunicationGuid ## SOMETIMES_CONSUMES ## GUID # Us= ed to do smm communication + gEfiSmmLockBoxCommunicationGuid ## SOMETIMES_CONSUMES ## GUID= # Used to do smm communication + gEdkiiPiSmmCommunicationRegionTableGuid ## SOMETIMES_CONSUMES ## Syst= emTable =20 [Protocols] gEfiSmmCommunicationProtocolGuid ## SOMETIMES_CONSUMES --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel