* [PATCH] MdePkg: PE loader should zero out dest buffer on allocation
@ 2020-01-13 8:18 Zhiguang Liu
2020-01-13 9:09 ` [edk2-devel] " Marvin Häuser
2020-01-13 17:58 ` Laszlo Ersek
0 siblings, 2 replies; 3+ messages in thread
From: Zhiguang Liu @ 2020-01-13 8:18 UTC (permalink / raw)
To: devel; +Cc: Jian J Wang, Hao A Wu
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
--
2.16.2.windows.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [edk2-devel] [PATCH] MdePkg: PE loader should zero out dest buffer on allocation
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
2020-01-13 17:58 ` Laszlo Ersek
1 sibling, 0 replies; 3+ messages in thread
From: Marvin Häuser @ 2020-01-13 9:09 UTC (permalink / raw)
To: devel, zhiguang.liu; +Cc: Jian J Wang, Hao A Wu
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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [edk2-devel] [PATCH] MdePkg: PE loader should zero out dest buffer on allocation
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
1 sibling, 0 replies; 3+ messages in thread
From: Laszlo Ersek @ 2020-01-13 17:58 UTC (permalink / raw)
To: devel, zhiguang.liu; +Cc: Jian J Wang, Hao A Wu, mhaeuser
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-01-13 17:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox