Blame SOURCES/kvm-multiboot-Reject-kernels-exceeding-the-address-space.patch

169b9a
From 7ca60898ccb2e1dc5e47dca5d53eb42922a0a0bc Mon Sep 17 00:00:00 2001
6e672b
From: Kevin Wolf <kwolf@redhat.com>
6e672b
Date: Thu, 26 Jul 2018 16:24:47 +0200
6e672b
Subject: [PATCH 5/8] multiboot: Reject kernels exceeding the address space
6e672b
6e672b
RH-Author: Kevin Wolf <kwolf@redhat.com>
6e672b
Message-id: <20180726162448.22072-6-kwolf@redhat.com>
6e672b
Patchwork-id: 81514
6e672b
O-Subject: [RHEL-7.6/7.5.z qemu-kvm PATCH 5/6] multiboot: Reject kernels exceeding the address space
169b9a
Bugzilla: 1549822
6e672b
RH-Acked-by: John Snow <jsnow@redhat.com>
6e672b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
6e672b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
6e672b
6e672b
The code path where mh_load_end_addr is non-zero in the Multiboot
6e672b
header checks that mh_load_end_addr >= mh_load_addr and so
6e672b
mb_load_size is checked.  However, mb_load_size is not checked when
6e672b
calculated from the file size, when mh_load_end_addr is 0.
6e672b
6e672b
If the kernel binary size is larger than can fit in the address space
6e672b
after load_addr, we ended up with a kernel_size that is smaller than
6e672b
load_size, which means that we read the file into a too small buffer.
6e672b
6e672b
Add a check to reject kernel files with such Multiboot headers.
6e672b
6e672b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6e672b
Reviewed-by: Jack Schwartz <jack.schwartz@oracle.com>
6e672b
(cherry picked from commit b17a9054a0652a1481be48a6729e972abf02412f)
6e672b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6e672b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
6e672b
---
6e672b
 hw/i386/multiboot.c | 4 ++++
6e672b
 1 file changed, 4 insertions(+)
6e672b
6e672b
diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c
6e672b
index 56889e8..6f489a5 100644
6e672b
--- a/hw/i386/multiboot.c
6e672b
+++ b/hw/i386/multiboot.c
6e672b
@@ -226,6 +226,10 @@ int load_multiboot(FWCfgState *fw_cfg,
6e672b
             }
6e672b
             mb_load_size = kernel_file_size - mb_kernel_text_offset;
6e672b
         }
6e672b
+        if (mb_load_size > UINT32_MAX - mh_load_addr) {
6e672b
+            error_report("kernel does not fit in address space");
6e672b
+            exit(1);
6e672b
+        }
6e672b
         if (mh_bss_end_addr) {
6e672b
             if (mh_bss_end_addr < (mh_load_addr + mb_load_size)) {
6e672b
                 error_report("invalid bss_end_addr address");
6e672b
-- 
6e672b
1.8.3.1
6e672b