public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Yao, Jiewen" <jiewen.yao@intel.com>
To: "Wang, Jian J" <jian.j.wang@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Zeng, Star" <star.zeng@intel.com>, "Dong, Eric" <eric.dong@intel.com>
Subject: Re: [PATCH] MdeModulePkg/Core: fix mem alloc issues in heap guard
Date: Tue, 13 Mar 2018 05:38:23 +0000	[thread overview]
Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503AAFA2E0@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <20180313023450.18336-1-jian.j.wang@intel.com>

Reviewed-by: Jiewen.yao@intel.com

> -----Original Message-----
> From: Wang, Jian J
> Sent: Tuesday, March 13, 2018 10:35 AM
> To: edk2-devel@lists.01.org
> Cc: Zeng, Star <star.zeng@intel.com>; Dong, Eric <eric.dong@intel.com>; Yao,
> Jiewen <jiewen.yao@intel.com>
> Subject: [PATCH] MdeModulePkg/Core: fix mem alloc issues in heap guard
> 
> There're two ASSERT issues which will be triggered by boot loader of
> Windows 10.
> 
> The first is caused by allocating memory in heap guard during another
> memory allocation, which is not allowed in DXE core. Avoiding reentry
> of memory allocation has been considered in heap guard feature. But
> there's a hole in the code of function FindGuardedMemoryMap(). The fix
> is adding AllocMapUnit parameter in the condition of while(), which
> will prevent memory allocation from happenning during Guard page
> check operation.
> 
> The second is caused by the core trying to allocate page 0 with Guard
> page, which will cause the start address rolling back to the end of
> supported system address. According to the requirement of heap guard,
> the fix is just simply skipping the free memory at page 0 and let
> the core continue searching free memory after it.
> 
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
> 
> ---
>  MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
> b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
> index 19245049c2..ac043b5d9b 100644
> --- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
> +++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
> @@ -225,8 +225,8 @@ FindGuardedMemoryMap (
>    //
>    // Adjust current map table depth according to the address to access
>    //
> -  while (mMapLevel < GUARDED_HEAP_MAP_TABLE_DEPTH
> -         &&
> +  while (AllocMapUnit &&
> +         mMapLevel < GUARDED_HEAP_MAP_TABLE_DEPTH &&
>           RShiftU64 (
>             Address,
>             mLevelShift[GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel -
> 1]
> @@ -904,6 +904,10 @@ AdjustMemoryS (
>    }
> 
>    Target = Start + Size - SizeRequested;
> +  ASSERT (Target >= Start);
> +  if (Target == 0) {
> +    return 0;
> +  }
> 
>    if (!IsGuardPage (Start + Size)) {
>      // No Guard at tail to share. One more page is needed.
> --
> 2.16.2.windows.1



      reply	other threads:[~2018-03-13  5:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-13  2:34 [PATCH] MdeModulePkg/Core: fix mem alloc issues in heap guard Jian J Wang
2018-03-13  5:38 ` Yao, Jiewen [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=74D8A39837DF1E4DA445A8C0B3885C503AAFA2E0@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