peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0033-kvmvapic-Catch-invalid-ROM-size.patch

298366
From 50b31e80525d03ef406a8c9f55ff2ae1655a3b66 Mon Sep 17 00:00:00 2001
298366
From: Jan Kiszka <jan.kiszka@siemens.com>
298366
Date: Tue, 3 Sep 2013 18:08:50 +0200
298366
Subject: [PATCH] kvmvapic: Catch invalid ROM size
298366
298366
If not caught early, a zero-length ROM will cause a NULL-pointer access
298366
later on in patch_hypercalls when allocating a zero-length ROM copy and
298366
trying to read from it.
298366
298366
CC: qemu-stable@nongnu.org
298366
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
298366
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
298366
(cherry picked from commit 18e5eec4db96a00907eb588a2b803401637c7f67)
298366
298366
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
298366
---
298366
 hw/i386/kvmvapic.c | 11 +++++++++--
298366
 1 file changed, 9 insertions(+), 2 deletions(-)
298366
298366
diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
298366
index 15beb80..7ac0fe1 100644
298366
--- a/hw/i386/kvmvapic.c
298366
+++ b/hw/i386/kvmvapic.c
298366
@@ -578,7 +578,7 @@ static int patch_hypercalls(VAPICROMState *s)
298366
  * enable write access to the option ROM so that variables can be updated by
298366
  * the guest.
298366
  */
298366
-static void vapic_map_rom_writable(VAPICROMState *s)
298366
+static int vapic_map_rom_writable(VAPICROMState *s)
298366
 {
298366
     hwaddr rom_paddr = s->rom_state_paddr & ROM_BLOCK_MASK;
298366
     MemoryRegionSection section;
298366
@@ -599,6 +599,9 @@ static void vapic_map_rom_writable(VAPICROMState *s)
298366
     /* read ROM size from RAM region */
298366
     ram = memory_region_get_ram_ptr(section.mr);
298366
     rom_size = ram[rom_paddr + 2] * ROM_BLOCK_SIZE;
298366
+    if (rom_size == 0) {
298366
+        return -1;
298366
+    }
298366
     s->rom_size = rom_size;
298366
 
298366
     /* We need to round to avoid creating subpages
298366
@@ -612,11 +615,15 @@ static void vapic_map_rom_writable(VAPICROMState *s)
298366
     memory_region_add_subregion_overlap(as, rom_paddr, &s->rom, 1000);
298366
     s->rom_mapped_writable = true;
298366
     memory_region_unref(section.mr);
298366
+
298366
+    return 0;
298366
 }
298366
 
298366
 static int vapic_prepare(VAPICROMState *s)
298366
 {
298366
-    vapic_map_rom_writable(s);
298366
+    if (vapic_map_rom_writable(s) < 0) {
298366
+        return -1;
298366
+    }
298366
 
298366
     if (patch_hypercalls(s) < 0) {
298366
         return -1;