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 2946921CF94F5 for ; Mon, 31 Jul 2017 00:50:57 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jul 2017 00:53:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,441,1496127600"; d="scan'208";a="1157212684" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga001.jf.intel.com with ESMTP; 31 Jul 2017 00:53:02 -0700 Received: from fmsmsx152.amr.corp.intel.com (10.18.125.5) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 31 Jul 2017 00:52:58 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX152.amr.corp.intel.com (10.18.125.5) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 31 Jul 2017 00:52:57 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.146]) by SHSMSX104.ccr.corp.intel.com ([10.239.4.70]) with mapi id 14.03.0319.002; Mon, 31 Jul 2017 15:52:56 +0800 From: "Gao, Liming" To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: "Yao, Jiewen" , "Zeng, Star" Thread-Topic: [edk2] [PATCH] MdeModulePkg PiSmmCoreMemoryAllocLib: Fix a FreePool() assertion issue Thread-Index: AQHTCdF0K3QiyNmKlk6kYWCmznD9taJtkGPA Date: Mon, 31 Jul 2017 07:52:56 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14D75D7F2@shsmsx102.ccr.corp.intel.com> References: <1501487240-37524-1-git-send-email-star.zeng@intel.com> In-Reply-To: <1501487240-37524-1-git-send-email-star.zeng@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [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: , X-List-Received-Date: Mon, 31 Jul 2017 07:50:57 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao >-----Original Message----- >From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Sta= r >Zeng >Sent: Monday, July 31, 2017 3:47 PM >To: edk2-devel@lists.01.org >Cc: Yao, Jiewen ; Gao, Liming >; Zeng, Star >Subject: [edk2] [PATCH] MdeModulePkg PiSmmCoreMemoryAllocLib: Fix a >FreePool() assertion issue > >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/mSmmCoreMemoryAllocLibSmra >mRangeCount >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 >--- > .../MemoryAllocationLib.c | 32 +++++++++++++++++= ++--- > 1 file changed, 28 insertions(+), 4 deletions(-) > >diff --git >a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocati >onLib.c >b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocati >onLib.c >index 96cb275cc9d7..4216a12d18f5 100644 >--- >a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocati >onLib.c >+++ >b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocati >onLib.c >@@ -1068,20 +1068,44 @@ PiSmmCoreMemoryAllocationLibConstructor ( > IN EFI_SYSTEM_TABLE *SystemTable > ) > { >+ EFI_STATUS Status; > SMM_CORE_PRIVATE_DATA *SmmCorePrivate; > UINTN Size; >+ VOID *BootServicesData; > > SmmCorePrivate =3D (SMM_CORE_PRIVATE_DATA *)ImageHandle; >+ > // >- // Initialize memory service using free SMRAM >+ // The FreePool()/FreePages() will need use SmramRanges data to know >whether >+ // the buffer to free is in SMRAM range or not. And there may be >FreePool()/ >+ // FreePages() indrectly during calling SmmInitializeMemoryServices(), = but >+ // no SMRAM could be allocated before calling >SmmInitializeMemoryServices(), >+ // so temporarily use BootServicesData to hold the SmramRanges data. > // >- SmmInitializeMemoryServices (SmmCorePrivate->SmramRangeCount, >SmmCorePrivate->SmramRanges); >- > mSmmCoreMemoryAllocLibSmramRangeCount =3D SmmCorePrivate- >>SmramRangeCount; > Size =3D mSmmCoreMemoryAllocLibSmramRangeCount * sizeof >(EFI_SMRAM_DESCRIPTOR); >- mSmmCoreMemoryAllocLibSmramRanges =3D (EFI_SMRAM_DESCRIPTOR *) >AllocatePool (Size); >+ Status =3D gBS->AllocatePool (EfiBootServicesData, Size, (VOID **) >&mSmmCoreMemoryAllocLibSmramRanges); >+ ASSERT_EFI_ERROR (Status); > ASSERT (mSmmCoreMemoryAllocLibSmramRanges !=3D NULL); > CopyMem (mSmmCoreMemoryAllocLibSmramRanges, SmmCorePrivate- >>SmramRanges, Size); > >+ // >+ // Initialize memory service using free SMRAM >+ // >+ SmmInitializeMemoryServices (SmmCorePrivate->SmramRangeCount, >SmmCorePrivate->SmramRanges); >+ >+ // >+ // Move the SmramRanges data from BootServicesData to SMRAM. >+ // >+ BootServicesData =3D mSmmCoreMemoryAllocLibSmramRanges; >+ mSmmCoreMemoryAllocLibSmramRanges =3D (EFI_SMRAM_DESCRIPTOR *) >AllocateCopyPool (Size, (VOID *) BootServicesData); >+ ASSERT (mSmmCoreMemoryAllocLibSmramRanges !=3D NULL); >+ >+ // >+ // Free the temporarily used BootServicesData. >+ // >+ Status =3D gBS->FreePool (BootServicesData); >+ ASSERT_EFI_ERROR (Status); >+ > return EFI_SUCCESS; > } >-- >2.7.0.windows.1 > >_______________________________________________ >edk2-devel mailing list >edk2-devel@lists.01.org >https://lists.01.org/mailman/listinfo/edk2-devel