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>,
	"Ni, Ruiyu" <ruiyu.ni@intel.com>
Subject: Re: [PATCH] MdeModulePkg/Core: fix feature conflict between NX and NULL detection
Date: Tue, 30 Jan 2018 02:09:07 +0000	[thread overview]
Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503AA9EDA0@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <20180129110950.24212-1-jian.j.wang@intel.com>

Hi Jian
May I know how we handle MemoryMapEntry->NumberOfPages is 1?
The lengh will be 0 in that case. Should we add additional check?

> +        SetUefiImageMemoryAttributes (
> +          MemoryMapEntry->PhysicalStart + EFI_PAGE_SIZE,
> +          LShiftU64 (MemoryMapEntry->NumberOfPages - 1,
> EFI_PAGE_SHIFT),
> +          Attributes);

> -----Original Message-----
> From: Wang, Jian J
> Sent: Monday, January 29, 2018 7:10 PM
> 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>; Ni, Ruiyu <ruiyu.ni@intel.com>
> Subject: [PATCH] MdeModulePkg/Core: fix feature conflict between NX and
> NULL detection
> 
> If enabled, NX memory protection feature will mark all free memory as
> NX (non-executable), including page 0. This will overwrite the attributes
> of page 0 if NULL pointer detection feature is also enabled and then
> compromise the functionality of it. The solution is skipping the NX
> attributes setting to page 0 if NULL pointer detection feature is enabled.
> 
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
> ---
>  MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 20
> ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
> b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
> index 862593f562..150167bf66 100644
> --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
> +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
> @@ -845,10 +845,22 @@ InitializeDxeNxMemoryProtectionPolicy (
> 
>      Attributes = GetPermissionAttributeForMemoryType
> (MemoryMapEntry->Type);
>      if (Attributes != 0) {
> -      SetUefiImageMemoryAttributes (
> -        MemoryMapEntry->PhysicalStart,
> -        LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT),
> -        Attributes);
> +      if (MemoryMapEntry->PhysicalStart == 0 &&
> +          PcdGet8 (PcdNullPointerDetectionPropertyMask) != 0) {
> +        //
> +        // Skip page 0 if NULL pointer detection is enabled to avoid attributes
> +        // overwritten.
> +        //
> +        SetUefiImageMemoryAttributes (
> +          MemoryMapEntry->PhysicalStart + EFI_PAGE_SIZE,
> +          LShiftU64 (MemoryMapEntry->NumberOfPages - 1,
> EFI_PAGE_SHIFT),
> +          Attributes);
> +      } else {
> +        SetUefiImageMemoryAttributes (
> +          MemoryMapEntry->PhysicalStart,
> +          LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT),
> +          Attributes);
> +      }
>      }
>      MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry,
> DescriptorSize);
>    }
> --
> 2.14.1.windows.1



  reply	other threads:[~2018-01-30  2:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-29 11:09 [PATCH] MdeModulePkg/Core: fix feature conflict between NX and NULL detection Jian J Wang
2018-01-30  2:09 ` Yao, Jiewen [this message]
2018-02-01  1:14   ` Wang, Jian J
2018-01-30  4:38 ` Ni, Ruiyu
2018-02-01  1:17   ` Wang, Jian J
2018-02-01  5:33     ` Ni, Ruiyu
2018-02-01  5:54       ` Ni, Ruiyu
2018-02-01  5:59         ` Wang, Jian J

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=74D8A39837DF1E4DA445A8C0B3885C503AA9EDA0@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