public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Marvin Häuser" <mhaeuser@outlook.de>
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>
Subject: Re: [edk2-devel] [PATCH] MdePkg: PE loader should zero out dest buffer on allocation
Date: Mon, 13 Jan 2020 10:09:50 +0100	[thread overview]
Message-ID: <AM6PR07MB5859007493DA84FAA1D6BEF5AC350@AM6PR07MB5859.eurprd07.prod.outlook.com> (raw)
In-Reply-To: <20200113081854.9732-1-zhiguang.liu@intel.com>

Good day,

Please see my comment in the related BZ: 
https://bugzilla.tianocore.org/show_bug.cgi?id=1999#c5

Best regards,
Marvin

Am 13.01.2020 um 09:18 schrieb Zhiguang Liu:
> 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
> 

  reply	other threads:[~2020-01-13  9:09 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 ` Marvin Häuser [this message]
2020-01-13 17:58 ` [edk2-devel] " Laszlo Ersek

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=AM6PR07MB5859007493DA84FAA1D6BEF5AC350@AM6PR07MB5859.eurprd07.prod.outlook.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