yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
9ae3a8
From ae31d75c7c2872dfc2172921422bf6b1c8bb6b03 Mon Sep 17 00:00:00 2001
9ae3a8
From: Bandan Das <bsd@redhat.com>
9ae3a8
Date: Wed, 6 Nov 2013 02:11:01 +0100
9ae3a8
Subject: [PATCH 54/81] kvmvapic: Catch invalid ROM size
9ae3a8
9ae3a8
RH-Author: Bandan Das <bsd@redhat.com>
9ae3a8
Message-id: <1383703863-4840-1-git-send-email-bsd@redhat.com>
9ae3a8
Patchwork-id: 55471
9ae3a8
O-Subject: [PATCH RHEL-7.0 qemu-kvm 1/3] kvmvapic: Catch invalid ROM size
9ae3a8
Bugzilla: 920021
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
9ae3a8
RH-Acked-by: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
9ae3a8
9ae3a8
From: Jan Kiszka <jan.kiszka@siemens.com>
9ae3a8
9ae3a8
If not caught early, a zero-length ROM will cause a NULL-pointer access
9ae3a8
later on in patch_hypercalls when allocating a zero-length ROM copy and
9ae3a8
trying to read from it.
9ae3a8
9ae3a8
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9ae3a8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
(cherry picked from commit 18e5eec4db96a00907eb588a2b803401637c7f67)
9ae3a8
9ae3a8
Conflicts:
9ae3a8
	hw/i386/kvmvapic.c
9ae3a8
---
9ae3a8
 hw/i386/kvmvapic.c | 11 +++++++++--
9ae3a8
 1 file changed, 9 insertions(+), 2 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 hw/i386/kvmvapic.c |   11 +++++++++--
9ae3a8
 1 files changed, 9 insertions(+), 2 deletions(-)
9ae3a8
9ae3a8
diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
9ae3a8
index a7db94d..a2c7e8f 100644
9ae3a8
--- a/hw/i386/kvmvapic.c
9ae3a8
+++ b/hw/i386/kvmvapic.c
9ae3a8
@@ -572,7 +572,7 @@ static int patch_hypercalls(VAPICROMState *s)
9ae3a8
  * enable write access to the option ROM so that variables can be updated by
9ae3a8
  * the guest.
9ae3a8
  */
9ae3a8
-static void vapic_map_rom_writable(VAPICROMState *s)
9ae3a8
+static int vapic_map_rom_writable(VAPICROMState *s)
9ae3a8
 {
9ae3a8
     hwaddr rom_paddr = s->rom_state_paddr & ROM_BLOCK_MASK;
9ae3a8
     MemoryRegionSection section;
9ae3a8
@@ -593,6 +593,9 @@ static void vapic_map_rom_writable(VAPICROMState *s)
9ae3a8
     /* read ROM size from RAM region */
9ae3a8
     ram = memory_region_get_ram_ptr(section.mr);
9ae3a8
     rom_size = ram[rom_paddr + 2] * ROM_BLOCK_SIZE;
9ae3a8
+    if (rom_size == 0) {
9ae3a8
+        return -1;
9ae3a8
+    }
9ae3a8
     s->rom_size = rom_size;
9ae3a8
 
9ae3a8
     /* We need to round to avoid creating subpages
9ae3a8
@@ -605,11 +608,15 @@ static void vapic_map_rom_writable(VAPICROMState *s)
9ae3a8
                              rom_size);
9ae3a8
     memory_region_add_subregion_overlap(as, rom_paddr, &s->rom, 1000);
9ae3a8
     s->rom_mapped_writable = true;
9ae3a8
+
9ae3a8
+    return 0;
9ae3a8
 }
9ae3a8
 
9ae3a8
 static int vapic_prepare(VAPICROMState *s)
9ae3a8
 {
9ae3a8
-    vapic_map_rom_writable(s);
9ae3a8
+    if (vapic_map_rom_writable(s) < 0) {
9ae3a8
+        return -1;
9ae3a8
+    }
9ae3a8
 
9ae3a8
     if (patch_hypercalls(s) < 0) {
9ae3a8
         return -1;
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8