From nobody Fri Dec 27 01:31:56 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 1501487266819124.86062656701233; Mon, 31 Jul 2017 00:47:46 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4E31121CF94EF; Mon, 31 Jul 2017 00:45:36 -0700 (PDT) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 95F6521CF94ED for ; Mon, 31 Jul 2017 00:45:35 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jul 2017 00:47:43 -0700 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.9.12]) by orsmga003.jf.intel.com with ESMTP; 31 Jul 2017 00:47:31 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,441,1496127600"; d="scan'208";a="999040737" From: Star Zeng To: edk2-devel@lists.01.org Date: Mon, 31 Jul 2017 15:47:20 +0800 Message-Id: <1501487240-37524-1-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 Subject: [edk2] [PATCH] MdeModulePkg PiSmmCoreMemoryAllocLib: Fix a FreePool() assertion issue 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: Jiewen Yao , Liming Gao , 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" When PiSmmCore links against PeiDxeDebugLibReportStatusCode, the code flow below will cause a FreePool() assertion issue. PiSmmCoreMemoryAllocationLibConstructor() -> SmmInitializeMemoryServices() -> DEBUG ((DEBUG_INFO, "SmmAddMemoryRegion\n")) in SmmAddMemoryRegion() -> DebugPrint() -> REPORT_STATUS_CODE_EX() -> ReportStatusCodeEx() -> AllocatePool()/FreePool(PiSmmCoreMemoryAllocLib) -> ASSERT() at Head =3D CR (Buffer, POOL_HEAD, Data, POOL_HEAD_SIGNATURE) in CoreFreePoolI() of DxeCore Pool.c It is because at the point of FreePool() in the code flow above, mSmmCoreMemoryAllocLibSmramRanges/mSmmCoreMemoryAllocLibSmramRangeCount are not been initialized yet, the FreePool() will be directed to gBS->FreePool(), that is wrong. This patch is to temporarily use BootServicesData to hold the SmramRanges data before calling SmmInitializeMemoryServices(). Cc: Liming Gao Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng Reviewed-by: Liming Gao --- .../MemoryAllocationLib.c | 32 ++++++++++++++++++= +--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAlloca= tionLib.c b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocat= ionLib.c index 96cb275cc9d7..4216a12d18f5 100644 --- a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib= .c +++ b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib= .c @@ -1068,20 +1068,44 @@ PiSmmCoreMemoryAllocationLibConstructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { + EFI_STATUS Status; SMM_CORE_PRIVATE_DATA *SmmCorePrivate; UINTN Size; + VOID *BootServicesData; =20 SmmCorePrivate =3D (SMM_CORE_PRIVATE_DATA *)ImageHandle; + // - // Initialize memory service using free SMRAM + // The FreePool()/FreePages() will need use SmramRanges data to know whe= ther + // the buffer to free is in SMRAM range or not. And there may be FreePoo= l()/ + // FreePages() indrectly during calling SmmInitializeMemoryServices(), b= ut + // no SMRAM could be allocated before calling SmmInitializeMemoryService= s(), + // so temporarily use BootServicesData to hold the SmramRanges data. // - SmmInitializeMemoryServices (SmmCorePrivate->SmramRangeCount, SmmCorePri= vate->SmramRanges); - mSmmCoreMemoryAllocLibSmramRangeCount =3D SmmCorePrivate->SmramRangeCoun= t; Size =3D mSmmCoreMemoryAllocLibSmramRangeCount * sizeof (EFI_SMRAM_DESCR= IPTOR); - mSmmCoreMemoryAllocLibSmramRanges =3D (EFI_SMRAM_DESCRIPTOR *) AllocateP= ool (Size); + Status =3D gBS->AllocatePool (EfiBootServicesData, Size, (VOID **) &mSmm= CoreMemoryAllocLibSmramRanges); + ASSERT_EFI_ERROR (Status); ASSERT (mSmmCoreMemoryAllocLibSmramRanges !=3D NULL); CopyMem (mSmmCoreMemoryAllocLibSmramRanges, SmmCorePrivate->SmramRanges,= Size); =20 + // + // Initialize memory service using free SMRAM + // + SmmInitializeMemoryServices (SmmCorePrivate->SmramRangeCount, SmmCorePri= vate->SmramRanges); + + // + // Move the SmramRanges data from BootServicesData to SMRAM. + // + BootServicesData =3D mSmmCoreMemoryAllocLibSmramRanges; + mSmmCoreMemoryAllocLibSmramRanges =3D (EFI_SMRAM_DESCRIPTOR *) AllocateC= opyPool (Size, (VOID *) BootServicesData); + ASSERT (mSmmCoreMemoryAllocLibSmramRanges !=3D NULL); + + // + // Free the temporarily used BootServicesData. + // + Status =3D gBS->FreePool (BootServicesData); + ASSERT_EFI_ERROR (Status); + return EFI_SUCCESS; } --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel