Blame SOURCES/edk2-MdeModulePkg-PartitionDxe-Ensure-blocksize-holds-MBR.patch

7c69f2
From b045711f96003a53493cd334fe867981fb3cae2b Mon Sep 17 00:00:00 2001
7c69f2
From: Laszlo Ersek <lersek@redhat.com>
7c69f2
Date: Fri, 1 Mar 2019 13:45:07 +0100
7c69f2
Subject: [PATCH 1/2] MdeModulePkg/PartitionDxe: Ensure blocksize holds MBR
7c69f2
 (CVE-2018-12180)
7c69f2
7c69f2
Message-id: <20190301124508.18497-2-lersek@redhat.com>
7c69f2
Patchwork-id: 84759
7c69f2
O-Subject:  [RHEL-8.0 edk2 PATCH 1/2] MdeModulePkg/PartitionDxe: Ensure blocksize
7c69f2
	holds MBR (CVE-2018-12180)
7c69f2
Bugzilla: 1690501
7c69f2
Acked-by: Thomas Huth <thuth@redhat.com>
7c69f2
Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
7c69f2
7c69f2
From: Hao Wu <hao.a.wu@intel.com>
7c69f2
7c69f2
--v-- RHEL-8.0 note --v--
7c69f2
7c69f2
Trivial conflicts resolved in "Gpt.c" and "Mbr.c": up-stream, the Intel
7c69f2
copyright notice got meanwhile extended to 2018, in commit d1102dba7210
7c69f2
("MdeModulePkg: Clean up source files", 2018-06-28).
7c69f2
7c69f2
--^-- RHEL-8.0 note --^--
7c69f2
7c69f2
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1134
7c69f2
7c69f2
The commit adds checks for detecting GPT and MBR partitions.
7c69f2
7c69f2
These checks will ensure that the device block size is big enough to hold
7c69f2
an MBR (512 bytes).
7c69f2
7c69f2
Cc: Jian J Wang <jian.j.wang@intel.com>
7c69f2
Cc: Star Zeng <star.zeng@intel.com>
7c69f2
Cc: Laszlo Ersek <lersek@redhat.com>
7c69f2
Contributed-under: TianoCore Contribution Agreement 1.1
7c69f2
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
7c69f2
Reviewed-by: Ray Ni <ray.ni@intel.com>
7c69f2
(cherry picked from commit fccdb88022c1f6d85c773fce506b10c879063f1d)
7c69f2
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
7c69f2
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
7c69f2
---
7c69f2
 MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c | 9 ++++++++-
7c69f2
 MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c | 9 ++++++++-
7c69f2
 2 files changed, 16 insertions(+), 2 deletions(-)
7c69f2
7c69f2
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c
7c69f2
index fe26a64..141dca0 100644
7c69f2
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c
7c69f2
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c
7c69f2
@@ -14,7 +14,7 @@
7c69f2
   partition content and validate the GPT table and GPT entry.
7c69f2
 
7c69f2
 Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc.
7c69f2
-Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
7c69f2
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
7c69f2
 This program and the accompanying materials
7c69f2
 are licensed and made available under the terms and conditions of the BSD License
7c69f2
 which accompanies this distribution.  The full text of the license may be found at
7c69f2
@@ -237,6 +237,13 @@ PartitionInstallGptChildHandles (
7c69f2
   GptValidStatus = EFI_NOT_FOUND;
7c69f2
 
7c69f2
   //
7c69f2
+  // Ensure the block size can hold the MBR
7c69f2
+  //
7c69f2
+  if (BlockSize < sizeof (MASTER_BOOT_RECORD)) {
7c69f2
+    return EFI_NOT_FOUND;
7c69f2
+  }
7c69f2
+
7c69f2
+  //
7c69f2
   // Allocate a buffer for the Protective MBR
7c69f2
   //
7c69f2
   ProtectiveMbr = AllocatePool (BlockSize);
7c69f2
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c
7c69f2
index 479745b..d7a15b4 100644
7c69f2
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c
7c69f2
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c
7c69f2
@@ -13,7 +13,7 @@
7c69f2
 
7c69f2
 Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc.
7c69f2
 Copyright (c) 2014, Hewlett-Packard Development Company, L.P.
7c69f2
-Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
7c69f2
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
7c69f2
 This program and the accompanying materials
7c69f2
 are licensed and made available under the terms and conditions of the BSD License
7c69f2
 which accompanies this distribution.  The full text of the license may be found at
7c69f2
@@ -150,6 +150,13 @@ PartitionInstallMbrChildHandles (
7c69f2
   MediaId   = BlockIo->Media->MediaId;
7c69f2
   LastBlock = BlockIo->Media->LastBlock;
7c69f2
 
7c69f2
+  //
7c69f2
+  // Ensure the block size can hold the MBR
7c69f2
+  //
7c69f2
+  if (BlockSize < sizeof (MASTER_BOOT_RECORD)) {
7c69f2
+    return EFI_NOT_FOUND;
7c69f2
+  }
7c69f2
+
7c69f2
   Mbr = AllocatePool (BlockSize);
7c69f2
   if (Mbr == NULL) {
7c69f2
     return Found;
7c69f2
-- 
7c69f2
1.8.3.1
7c69f2