kvmvapic: Prevent reading beyond the end of guest RAM
authorJan Kiszka <jan.kiszka@siemens.com>
Mon, 30 Sep 2013 10:35:13 +0000 (12:35 +0200)
committerGleb Natapov <gleb@redhat.com>
Fri, 4 Oct 2013 10:13:16 +0000 (13:13 +0300)
rom_state_paddr is guest provided (caller address of outw(VAPIC_PORT) +
writen 16-bit value) and can be influenced to point beyond the end of
the host memory backing the guest's RAM. Make sure we do not use this
pointer to actually read beyond the limits.

Reading arbitrary guest bytes is harmless, the guest kernel has to
manage access to this I/O port anyway.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Gleb Natapov <gleb@redhat.com>
hw/i386/kvmvapic.c

index 1c2dbf59cf67112a70ed9137e7c1b0c7aeddebef..2d876009fc1022662435041894cbe3451a51a197 100644 (file)
@@ -596,6 +596,9 @@ static int vapic_map_rom_writable(VAPICROMState *s)
     section = memory_region_find(as, 0, 1);
 
     /* read ROM size from RAM region */
+    if (rom_paddr + 2 >= memory_region_size(section.mr)) {
+        return -1;
+    }
     ram = memory_region_get_ram_ptr(section.mr);
     rom_size = ram[rom_paddr + 2] * ROM_BLOCK_SIZE;
     if (rom_size == 0) {