Blame SOURCES/kvm-device_tree-Fix-integer-overflowing-in-load_device_t.patch

b21ec6
From b18831e53e64414ebd35419fb8dffd51e8ec46f7 Mon Sep 17 00:00:00 2001
b21ec6
From: Sergio Lopez Pascual <slp@redhat.com>
b21ec6
Date: Mon, 15 Apr 2019 09:09:30 +0200
b21ec6
Subject: [PATCH] device_tree: Fix integer overflowing in load_device_tree()
b21ec6
MIME-Version: 1.0
b21ec6
Content-Type: text/plain; charset=UTF-8
b21ec6
Content-Transfer-Encoding: 8bit
b21ec6
b21ec6
RH-Author: Sergio Lopez Pascual <slp@redhat.com>
b21ec6
Message-id: <20190415090930.27086-2-slp@redhat.com>
b21ec6
Patchwork-id: 85657
b21ec6
O-Subject: [RHEL-7.6.z qemu-kvm-ma PATCH 1/1] device_tree: Fix integer overflowing in load_device_tree()
b21ec6
Bugzilla: 1693112
b21ec6
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
b21ec6
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
b21ec6
RH-Acked-by: John Snow <jsnow@redhat.com>
b21ec6
b21ec6
From: Markus Armbruster <armbru@redhat.com>
b21ec6
b21ec6
If the value of get_image_size() exceeds INT_MAX / 2 - 10000, the
b21ec6
computation of @dt_size overflows to a negative number, which then
b21ec6
gets converted to a very large size_t for g_malloc0() and
b21ec6
load_image_size().  In the (fortunately improbable) case g_malloc0()
b21ec6
succeeds and load_image_size() survives, we'd assign the negative
b21ec6
number to *sizep.  What that would do to the callers I can't say, but
b21ec6
it's unlikely to be good.
b21ec6
b21ec6
Fix by rejecting images whose size would overflow.
b21ec6
b21ec6
Reported-by: Kurtis Miller <kurtis.miller@nccgroup.com>
b21ec6
Signed-off-by: Markus Armbruster <armbru@redhat.com>
b21ec6
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
b21ec6
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
b21ec6
Message-Id: <20190409174018.25798-1-armbru@redhat.com>
b21ec6
(cherry picked from commit 065e6298a75164b4347682b63381dbe752c2b156)
b21ec6
Signed-off-by: Sergio Lopez <slp@redhat.com>
b21ec6
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
b21ec6
---
b21ec6
 device_tree.c | 4 ++++
b21ec6
 1 file changed, 4 insertions(+)
b21ec6
b21ec6
diff --git a/device_tree.c b/device_tree.c
b21ec6
index 19458b3..2457f58 100644
b21ec6
--- a/device_tree.c
b21ec6
+++ b/device_tree.c
b21ec6
@@ -84,6 +84,10 @@ void *load_device_tree(const char *filename_path, int *sizep)
b21ec6
                      filename_path);
b21ec6
         goto fail;
b21ec6
     }
b21ec6
+    if (dt_size > INT_MAX / 2 - 10000) {
b21ec6
+        error_report("Device tree file '%s' is too large", filename_path);
b21ec6
+        goto fail;
b21ec6
+    }
b21ec6
 
b21ec6
     /* Expand to 2x size to give enough room for manipulation.  */
b21ec6
     dt_size += 10000;
b21ec6
-- 
b21ec6
1.8.3.1
b21ec6