Blame SOURCES/ovmf-MdeModulePkg-HiiImage-Fix-stack-overflow-when-corrup.patch

bdb79c
From 44941e738b975e52a6494cfd9f71db5ad3f411b8 Mon Sep 17 00:00:00 2001
bdb79c
From: Laszlo Ersek <lersek@redhat.com>
bdb79c
Date: Fri, 22 Mar 2019 17:39:36 +0100
bdb79c
Subject: [PATCH 2/8] MdeModulePkg/HiiImage: Fix stack overflow when corrupted
bdb79c
 BMP is parsed (CVE-2018-12181)
bdb79c
MIME-Version: 1.0
bdb79c
Content-Type: text/plain; charset=UTF-8
bdb79c
Content-Transfer-Encoding: 8bit
bdb79c
bdb79c
Message-id: <20190322163936.10835-3-lersek@redhat.com>
bdb79c
Patchwork-id: 85123
bdb79c
O-Subject:  [RHEL-7.7 ovmf PATCH 2/2] MdeModulePkg/HiiImage: Fix stack overflow
bdb79c
	when corrupted BMP is parsed (CVE-2018-12181)
bdb79c
Bugzilla: 1691479
bdb79c
Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
bdb79c
Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
bdb79c
bdb79c
From: Ray Ni <ray.ni@intel.com>
bdb79c
bdb79c
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1135
bdb79c
bdb79c
For 4bit BMP, there are only 2^4 = 16 colors in the palette.
bdb79c
But when a corrupted BMP contains more than 16 colors in the palette,
bdb79c
today's implementation wrongly copies all colors to the local
bdb79c
PaletteValue[16] array which causes stack overflow.
bdb79c
bdb79c
The similar issue also exists in the logic to handle 8bit BMP.
bdb79c
bdb79c
The patch fixes the issue by only copies the first 16 or 256 colors
bdb79c
in the palette depending on the BMP type.
bdb79c
bdb79c
Contributed-under: TianoCore Contribution Agreement 1.1
bdb79c
Signed-off-by: Ray Ni <ray.ni@intel.com>
bdb79c
Cc: Liming Gao <liming.gao@intel.com>
bdb79c
Cc: Jiewen Yao <jiewen.yao@intel.com>
bdb79c
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
bdb79c
(cherry picked from commit 89910a39dcfd788057caa5d88b7e76e112d187b5)
bdb79c
---
bdb79c
 MdeModulePkg/Universal/HiiDatabaseDxe/Image.c | 4 ++--
bdb79c
 1 file changed, 2 insertions(+), 2 deletions(-)
bdb79c
bdb79c
diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
bdb79c
index dc9566b..9829bdd 100644
bdb79c
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
bdb79c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
bdb79c
@@ -370,7 +370,7 @@ Output4bitPixel (
bdb79c
   PaletteNum = (UINT16)(Palette->PaletteSize / sizeof (EFI_HII_RGB_PIXEL));
bdb79c
 
bdb79c
   ZeroMem (PaletteValue, sizeof (PaletteValue));
bdb79c
-  CopyRgbToGopPixel (PaletteValue, Palette->PaletteValue, PaletteNum);
bdb79c
+  CopyRgbToGopPixel (PaletteValue, Palette->PaletteValue, MIN (PaletteNum, ARRAY_SIZE (PaletteValue)));
bdb79c
   FreePool (Palette);
bdb79c
 
bdb79c
   //
bdb79c
@@ -447,7 +447,7 @@ Output8bitPixel (
bdb79c
   CopyMem (Palette, PaletteInfo, PaletteSize);
bdb79c
   PaletteNum = (UINT16)(Palette->PaletteSize / sizeof (EFI_HII_RGB_PIXEL));
bdb79c
   ZeroMem (PaletteValue, sizeof (PaletteValue));
bdb79c
-  CopyRgbToGopPixel (PaletteValue, Palette->PaletteValue, PaletteNum);
bdb79c
+  CopyRgbToGopPixel (PaletteValue, Palette->PaletteValue, MIN (PaletteNum, ARRAY_SIZE (PaletteValue)));
bdb79c
   FreePool (Palette);
bdb79c
 
bdb79c
   //
bdb79c
-- 
bdb79c
1.8.3.1
bdb79c