yeahuh / rpms / qemu-kvm

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