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