From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=eric.dong@intel.com; receiver=edk2-devel@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 9CF31210FBEE9 for ; Wed, 22 Aug 2018 05:56:26 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Aug 2018 05:56:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,274,1531810800"; d="scan'208";a="68206562" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga006.jf.intel.com with ESMTP; 22 Aug 2018 05:56:25 -0700 Received: from fmsmsx117.amr.corp.intel.com (10.18.116.17) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 22 Aug 2018 05:56:25 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx117.amr.corp.intel.com (10.18.116.17) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 22 Aug 2018 05:56:24 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.226]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.150]) with mapi id 14.03.0319.002; Wed, 22 Aug 2018 20:56:22 +0800 From: "Dong, Eric" To: "Zeng, Star" , "edk2-devel@lists.01.org" Thread-Topic: [Patch v2] MdeModulePkg/PiSmmCore: Check valid memory range. Thread-Index: AQHUOgja+0L6kxwlk0q4rQq8oOArzKTLustw Date: Wed, 22 Aug 2018 12:56:21 +0000 Message-ID: References: <20180821122440.10384-1-eric.dong@intel.com> <0C09AFA07DD0434D9E2A0C6AEB0483103BBB0E98@shsmsx102.ccr.corp.intel.com> In-Reply-To: <0C09AFA07DD0434D9E2A0C6AEB0483103BBB0E98@shsmsx102.ccr.corp.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 v2] MdeModulePkg/PiSmmCore: Check valid memory range. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Aug 2018 12:56:26 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Star, Agree, will update to that name when check in the code. Thanks, Eric > -----Original Message----- > From: Zeng, Star > Sent: Wednesday, August 22, 2018 7:11 PM > To: Dong, Eric ; edk2-devel@lists.01.org > Cc: Zeng, Star > Subject: RE: [Patch v2] MdeModulePkg/PiSmmCore: Check valid memory > range. >=20 > Suggest use "InMemMap" instead of "InSmmRange", Reviewed-by: Star Zeng > with it. >=20 >=20 > Thanks, > Star > -----Original Message----- > From: Dong, Eric > Sent: Tuesday, August 21, 2018 8:25 PM > To: edk2-devel@lists.01.org > Cc: Zeng, Star > Subject: [Patch v2] MdeModulePkg/PiSmmCore: Check valid memory range. >=20 > Call BS.AllocatePages in DXE driver and call SMM FreePages with the addre= ss > of the buffer allocated in the DXE driver. SMM FreePages success and add = a > non-SMRAM range into SMM heap list. This is not an expected behavior. > SMM FreePages should return error for this case and not free the pages. >=20 > V2 changes: > Adjust "Last" variable value from "Last =3D Memory + EFI_PAGES_TO_SIZE > (NumberOfPages);" to "Last =3D Memory + EFI_PAGES_TO_SIZE > (NumberOfPages) - 1;" >=20 > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1098 >=20 > Pass test: > 1. Call SmmAllocatePages, to allocate pages, then call SmmFreePages to fr= ee > same pages return success. > 2. Call AllocatePages in Dxe then call SmmFreePages to free same pages, > return failure. >=20 > Cc: Star Zeng > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Eric Dong > --- > MdeModulePkg/Core/PiSmmCore/Page.c | 39 > ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 39 insertions(+) >=20 > diff --git a/MdeModulePkg/Core/PiSmmCore/Page.c > b/MdeModulePkg/Core/PiSmmCore/Page.c > index 3699af7424..e9fcf01ecc 100644 > --- a/MdeModulePkg/Core/PiSmmCore/Page.c > +++ b/MdeModulePkg/Core/PiSmmCore/Page.c > @@ -983,6 +983,41 @@ SmmInternalFreePages ( > return SmmInternalFreePagesEx (Memory, NumberOfPages, FALSE); } >=20 > +/** > + Check whether the input range is in smram. > + > + @param Memory Base address of memory being inputed. > + @param NumberOfPages The number of pages. > + > + @retval TRUE In the smram. > + @retval FALSE Not in the smram. > + > +**/ > +BOOLEAN > +InSmmRange ( > + IN EFI_PHYSICAL_ADDRESS Memory, > + IN UINTN NumberOfPages > + ) > +{ > + LIST_ENTRY *Link; > + MEMORY_MAP *Entry; > + EFI_PHYSICAL_ADDRESS Last; > + > + Last =3D Memory + EFI_PAGES_TO_SIZE (NumberOfPages) - 1; > + > + Link =3D gMemoryMap.ForwardLink; > + while (Link !=3D &gMemoryMap) { > + Entry =3D CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE); > + Link =3D Link->ForwardLink; > + > + if ((Entry->Start <=3D Memory) && (Entry->End >=3D Last)) { > + return TRUE; > + } > + } > + > + return FALSE; > +} > + > /** > Frees previous allocated pages. >=20 > @@ -1004,6 +1039,10 @@ SmmFreePages ( > EFI_STATUS Status; > BOOLEAN IsGuarded; >=20 > + if (!InSmmRange(Memory, NumberOfPages)) { > + return EFI_NOT_FOUND; > + } > + > IsGuarded =3D IsHeapGuardEnabled () && IsMemoryGuarded (Memory); > Status =3D SmmInternalFreePages (Memory, NumberOfPages, IsGuarded); > if (!EFI_ERROR (Status)) { > -- > 2.15.0.windows.1