From: "Dong, Eric" <eric.dong@intel.com>
To: "Zeng, Star" <star.zeng@intel.com>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: Re: [Patch] MdeModulePkg/PiSmmCore: Check valid memory range.
Date: Tue, 21 Aug 2018 12:27:36 +0000 [thread overview]
Message-ID: <ED077930C258884BBCB450DB737E66224AC930F1@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <0C09AFA07DD0434D9E2A0C6AEB0483103BBB032F@shsmsx102.ccr.corp.intel.com>
Hi Star,
Good catch. I tried to boot an test platform and it passed. I assume it has cases to free the smm memory. Seems like actually it doesn't.
I will add test code to verify the patch and send v2 change.
Thanks,
Eric
> -----Original Message-----
> From: Zeng, Star
> Sent: Tuesday, August 21, 2018 5:35 PM
> To: Dong, Eric <eric.dong@intel.com>; edk2-devel@lists.01.org
> Cc: Zeng, Star <star.zeng@intel.com>
> Subject: RE: [Patch] MdeModulePkg/PiSmmCore: Check valid memory range.
>
> Hi Eric,
>
> About
> + EFI_PHYSICAL_ADDRESS Last;
> + Last = Memory + EFI_PAGES_TO_SIZE (NumberOfPages);
>
> Shouldn't "-1" be also added like the code below in
> ConvertSmmMemoryMapEntry()?
> EFI_PHYSICAL_ADDRESS End;
> End = Memory + EFI_PAGES_TO_SIZE(NumberOfPages) - 1;
>
> Could you double check the normal functionality (SMM AllocatePages +
> FreePages) with the patch?
>
>
> Thanks,
> Star
> -----Original Message-----
> From: Dong, Eric
> Sent: Tuesday, August 21, 2018 2:46 PM
> To: edk2-devel@lists.01.org
> Cc: Zeng, Star <star.zeng@intel.com>
> Subject: [Patch] MdeModulePkg/PiSmmCore: Check valid memory range.
>
> Call BS.AllocatePages in DXE driver and call SMM FreePages with the address
> 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.
>
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1098
>
> Cc: Star Zeng <star.zeng@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Eric Dong <eric.dong@intel.com>
> ---
> MdeModulePkg/Core/PiSmmCore/Page.c | 39
> ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 39 insertions(+)
>
> diff --git a/MdeModulePkg/Core/PiSmmCore/Page.c
> b/MdeModulePkg/Core/PiSmmCore/Page.c
> index 3699af7424..630678ccc3 100644
> --- a/MdeModulePkg/Core/PiSmmCore/Page.c
> +++ b/MdeModulePkg/Core/PiSmmCore/Page.c
> @@ -983,6 +983,41 @@ SmmInternalFreePages (
> return SmmInternalFreePagesEx (Memory, NumberOfPages, FALSE); }
>
> +/**
> + 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 = Memory + EFI_PAGES_TO_SIZE (NumberOfPages);
> +
> + Link = gMemoryMap.ForwardLink;
> + while (Link != &gMemoryMap) {
> + Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
> + Link = Link->ForwardLink;
> +
> + if ((Entry->Start <= Memory) && (Entry->End >= Last)) {
> + return TRUE;
> + }
> + }
> +
> + return FALSE;
> +}
> +
> /**
> Frees previous allocated pages.
>
> @@ -1004,6 +1039,10 @@ SmmFreePages (
> EFI_STATUS Status;
> BOOLEAN IsGuarded;
>
> + if (!InSmmRange(Memory, NumberOfPages)) {
> + return EFI_NOT_FOUND;
> + }
> +
> IsGuarded = IsHeapGuardEnabled () && IsMemoryGuarded (Memory);
> Status = SmmInternalFreePages (Memory, NumberOfPages, IsGuarded);
> if (!EFI_ERROR (Status)) {
> --
> 2.15.0.windows.1
prev parent reply other threads:[~2018-08-21 12:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-21 6:45 [Patch] MdeModulePkg/PiSmmCore: Check valid memory range Eric Dong
2018-08-21 9:35 ` Zeng, Star
2018-08-21 12:27 ` Dong, Eric [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ED077930C258884BBCB450DB737E66224AC930F1@shsmsx102.ccr.corp.intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox