public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, zhiguang.liu@intel.com
Cc: Jian J Wang <jian.j.wang@intel.com>,
	Hao A Wu <hao.a.wu@intel.com>,
	mhaeuser@outlook.de
Subject: Re: [edk2-devel] [PATCH] MdePkg: PE loader should zero out dest buffer on allocation
Date: Mon, 13 Jan 2020 18:58:12 +0100	[thread overview]
Message-ID: <30c379b3-8b20-993a-cde0-e761e4e4bfec@redhat.com> (raw)
In-Reply-To: <20200113081854.9732-1-zhiguang.liu@intel.com>

On 01/13/20 09:18, Zhiguang Liu wrote:
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1999
> 
> When PE loader loads image to memory, the first section of image may
> not locate right next to the image header, which causes some memory
> space remaining uninitialized. This is a security issue.
> This patch compares the ending address of image header and the beginning
> address of the first section. If there is a gap, zero out this gap.
> 
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
> ---
>  MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> index 07bb62f860..2cdfb4a082 100644
> --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> @@ -1306,6 +1306,14 @@ PeCoffLoaderLoadImage (
>    // Load each section of the image
>    //
>    Section = FirstSection;
> +  //
> +  // Zero out the memory space between image header and the first section
> +  //
> +  End  = (CHAR8 *)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders);
> +  Base = PeCoffLoaderImageAddress (ImageContext, Section->VirtualAddress, TeStrippedOffset);
> +  if (End < Base) {
> +    ZeroMem (End, Base - End);
> +  }
>    for (Index = 0; Index < NumberOfSections; Index++) {
>      //
>      // Read the section
> 

CC'ing Marvin

Thanks
Laszlo


      parent reply	other threads:[~2020-01-13 17:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-13  8:18 [PATCH] MdePkg: PE loader should zero out dest buffer on allocation Zhiguang Liu
2020-01-13  9:09 ` [edk2-devel] " Marvin Häuser
2020-01-13 17:58 ` Laszlo Ersek [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=30c379b3-8b20-993a-cde0-e761e4e4bfec@redhat.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