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

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