Skip to contentSkip to conversation

Qemu Traditional bugfixes

PATCH In review Andrew Cooper 2 participants 66 messages Apr 22, 2015 – Oct 16, 2015

lore
Share & tools
lore
#0 lore raw

cover Qemu Traditional bugfixes

Here is a set of bugfixes against Qemu Traditional, which are from the XenServer patch queue.

Patches 1 to 4 are build fixes in a CentOS environment Patches 5 to 8 are backports of public CVEs, including two remote code execution vulnerabilities.
Patches 9 to 11 are fixes for crashes which guest activity can cause Patch 12 is a functional fix to command line parsing Patches 13 to 15 are fixes from the use of valgrind
Patches 16 to 32 are fixes from Coverity analysis

I have identified Coverity Scan IDs where applicable.

Andrew Cooper (9):
cirrus_vga: default all I/O port reads to 0xff
lm832x: don't overrun file buffer on save/restore
block-vvfat: fix fat_chksum() buffer overrun warning
CVE-2014-8106: cirrus: fix blit region check
CVE-2014-7815: vnc: sanitize bits_per_pixel from the client
CVE-2014-3615: vbe: rework sanity checks
smbios: Don't allocate smbus eeprom buffer
pic: Don't allocate irq buffers
signal: Don't use uninitalised sival_ptr

Aurelien Jarno (1):
cirrus_vga: fix division by 0 for color expansion rop

Chunjie Zhu (2):
ide: cancel dma operations on command abort or error
dma: fix incorrect bh scheduling

Jim Paris (1):
usb-linux.c: fix buffer overflow

Kaifeng Zhu (11):
cmdline: Parse -pciemulation before trying to use it
readline: fix memory corruption when adding history
block-cow: don't close cow_fd twice on error
console: Avoid overrunning the dmask arrays hw/device-hotplug: fix test of drive_add() return
qemu-char: fix memory leak in qemu_char_open_pty() hw/ide: fix memory leak from qemu_allocate_irqs()
net: don't leak an fd after an error
net: Fix memory/handle leaks in net_socket_listen_init()
block-vvfat: fix memory/handle leaks in commit_one_file()
block-vvfat: fix memory leak in check_directory_consistency()

Yunlei Ding (8):
virtio-blk: initialise unused blkcfg.size_max field hw/msmouse.c: Fix deref_after_free and double free
virtio-blk: correctly link new request in virtio_blk_load()
net: initialize parameters before use in net_socket_fd_init_dgram()
ide: don't leak irq array in pci_cmd646_ide_init()
block-nbd: close sock in nbd_open() error path
block-raw-posix: Fix memory leak in posix_aio_init()
block-vvfat: fix resource leaks in read_directory()

 block-cow.c         |    1 -
 block-nbd.c         |    3 +
 block-raw-posix.c   |    1 +
 block-vvfat.c       |   37 ++++++++++---
 console.c           |    9 +--
 dma-helpers.c       |   16 +++++-
 hw/cirrus_vga.c     |  138 +++++++++++++++++++++++++++------------------
 hw/device-hotplug.c |    2 +-
 hw/ide.c            |   15 ++---
 hw/irq.c            |   18 +++++-
 hw/irq.h            |    4 ++
 hw/lm832x.c         |   11 +++-
 hw/msmouse.c        |    1 -
 hw/pc.c             |   16 +-----
 hw/vga.c            |  154 +++++++++++++++++++++++++++++++--------------------
 hw/virtio-blk.c     |    3 +-
 net.c               |   13 ++++-
 qemu-char.c         |    2 +
 readline.c          |    2 +-
 usb-linux.c         |   12 +++-
 vl.c                |   21 ++++---
 vnc.c               |   10 ++++
 22 files changed, 320 insertions(+), 169 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/32 virtio-blk: initialise unused blkcfg.size_max field

From: Yunlei Ding <[email protected]>

Newer GCC warns about memcpy()ing uninitialised data.

Coverity-ID: 1056088

---
 hw/virtio-blk.c |    1 +
 1 file changed, 1 insertion(+)
hw/virtio-blk.c +1 -0
index 520ad1b..fcf893a 100644
@@ -252,6 +252,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
     stw_raw(&blkcfg.cylinders, cylinders);
     blkcfg.heads = heads;
     blkcfg.sectors = secs;
+    blkcfg.size_max = 0;
     memcpy(config, &blkcfg, sizeof(blkcfg));
 }
 
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/32 cirrus_vga: default all I/O port reads to 0xff

Some error paths in vga_ioport_read() would return undefined values. Always default the result to 0xff.

---
 hw/cirrus_vga.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/cirrus_vga.c +1 -1
index a26b051..11ce212 100644
@@ -2674,7 +2674,7 @@ static void cirrus_update_memory_access(CirrusVGAState *s)
 static uint32_t vga_ioport_read(void *opaque, uint32_t addr)
 {
     CirrusVGAState *s = opaque;
-    int val, index;
+    int val = 0xff, index;
 
     /* check port range access depending on color/monochrome mode */
     if ((addr >= 0x3b0 && addr <= 0x3bf && (s->msr & MSR_COLOR_EMULATION))
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 3/32 lm832x: don't overrun file buffer on save/restore

In reply to Andrew Cooper

Saving and restoring an lm832x record would overrun the pwm.file array since pwm.file is uint16_t elements and sizeof(pwm.file) twice as many elements.

To ensure compatibility, padding bytes are added to the record.

Coverity-IDs: 1055728 1055729

---
 hw/lm832x.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
hw/lm832x.c +9 -2
index dd94310..a212866 100644
@@ -439,8 +439,11 @@ static void lm_kbd_save(QEMUFile *f, void *opaque)
     qemu_put_byte(f, s->kbd.len);
     qemu_put_buffer(f, s->kbd.fifo, sizeof(s->kbd.fifo));
 
-    for (i = 0; i < sizeof(s->pwm.file); i ++)
+    for (i = 0; i < ARRAY_SIZE(s->pwm.file); i ++)
         qemu_put_be16s(f, &s->pwm.file[i]);
+    /* Padding for compatibility with older records. */
+    for ( ; i < sizeof(s->pwm.file); i++)
+        qemu_put_be16s(f, 0);
     qemu_put_8s(f, &s->pwm.faddr);
     qemu_put_buffer(f, s->pwm.addr, sizeof(s->pwm.addr));
     qemu_put_timer(f, s->pwm.tm[0]);
@@ -451,6 +454,7 @@ static void lm_kbd_save(QEMUFile *f, void *opaque)
 static int lm_kbd_load(QEMUFile *f, void *opaque, int version_id)
 {
     struct lm_kbd_s *s = (struct lm_kbd_s *) opaque;
+    uint16_t pad;
     int i;
 
     i2c_slave_load(f, &s->i2c);
@@ -475,8 +479,11 @@ static int lm_kbd_load(QEMUFile *f, void *opaque, int version_id)
     s->kbd.len = qemu_get_byte(f);
     qemu_get_buffer(f, s->kbd.fifo, sizeof(s->kbd.fifo));
 
-    for (i = 0; i < sizeof(s->pwm.file); i ++)
+    for (i = 0; i < ARRAY_SIZE(s->pwm.file); i ++)
         qemu_get_be16s(f, &s->pwm.file[i]);
+    /* Skip padding. */
+    for ( ; i < sizeof(s->pwm.file); i++)
+        qemu_get_be16(f);
     qemu_get_8s(f, &s->pwm.faddr);
     qemu_get_buffer(f, s->pwm.addr, sizeof(s->pwm.addr));
     qemu_get_timer(f, s->pwm.tm[0]);
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH 4/32 block-vvfat: fix fat_chksum() buffer overrun warning

In reply to Andrew Cooper

Newer GCC versions raise an undefined behaviour warning in fat_chksum() because it overruns the name buffer. However, this is intentional behaviour because the extension array immediately follows.

Refactor this function to avoid the warning and make it clear it's checksumming both parts.

Coverity-ID: 1055738

---
 block-vvfat.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
block-vvfat.c +11 -4
index 9eb676b..345d7be 100644
@@ -504,14 +504,21 @@ static void set_begin_of_direntry(direntry_t* direntry, uint32_t begin)
 
 /* fat functions */
 
+static inline void fat_chksum_part(const char *name, size_t len, uint8_t *chksum)
+{
+    size_t i;
+
+    for(i = 0; i < len; i++)
+	*chksum = (((*chksum&0xfe) >> 1) | ((*chksum & 0x01) ? 0x80 : 0))
+	    + (unsigned char)name[i];
+}
+
 static inline uint8_t fat_chksum(const direntry_t* entry)
 {
     uint8_t chksum=0;
-    int i;
 
-    for(i=0;i<11;i++)
-	chksum=(((chksum&0xfe)>>1)|((chksum&0x01)?0x80:0))
-	    +(unsigned char)entry->name[i];
+    fat_chksum_part(entry->name, ARRAY_SIZE(entry->name), &chksum);
+    fat_chksum_part(entry->extension, ARRAY_SIZE(entry->extension), &chksum);
 
     return chksum;
 }
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH 5/32 usb-linux.c: fix buffer overflow

In reply to Andrew Cooper

From: Jim Paris <[email protected]>

In usb-linux.c:usb_host_handle_control, we pass a 1024-byte buffer and length to the kernel. However, the length was provided by the caller of dev->handle_packet, and is not checked, so the kernel might provide too much data and overflow our buffer.

For example, hw/usb-uhci.c could set the length to 2047. hw/usb-ohci.c looks like it might go up to 4096 or 8192.

This causes a qemu crash, as reported here:
http://www.mail-archive.com/[email protected]/msg18447.html

This patch increases the usb-linux.c buffer size to 2048 to fix the specific device reported, and adds a check to avoid the overflow in any case.

---
 usb-linux.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
usb-linux.c +10 -2
index 5dfed8c..51bac8a 100644
@@ -117,7 +117,7 @@ struct ctrl_struct {
     uint16_t offset;
     uint8_t  state;
     struct   usb_ctrlrequest req;
-    uint8_t  buffer[1024];
+    uint8_t  buffer[2048];
 };
 
 typedef struct USBHostDevice {
@@ -554,6 +554,7 @@ static int usb_host_handle_control(USBHostDevice *s, USBPacket *p)
     struct usbdevfs_urb *urb;
     AsyncURB *aurb;
     int ret, value, index;
+    int buffer_len;
 
     /* 
      * Process certain standard device requests.
@@ -582,6 +583,13 @@ static int usb_host_handle_control(USBHostDevice *s, USBPacket *p)
 
     /* The rest are asynchronous */
 
+    buffer_len = 8 + s->ctrl.len;
+    if (buffer_len > sizeof(s->ctrl.buffer)) {
+	    fprintf(stderr, "husb: ctrl buffer too small (%d > %zu)\n",
+		    buffer_len, sizeof(s->ctrl.buffer));
+	    return USB_RET_STALL;
+    }
+
     aurb = async_alloc();
     aurb->hdev   = s;
     aurb->packet = p;
@@ -598,7 +606,7 @@ static int usb_host_handle_control(USBHostDevice *s, USBPacket *p)
     urb->endpoint = p->devep;
 
     urb->buffer        = &s->ctrl.req;
-    urb->buffer_length = 8 + s->ctrl.len;
+    urb->buffer_length = buffer_len;
 
     urb->usercontext = s;
 
Signature · 1 line
1.7.10.4
#6 lore raw

PATCH 6/32 CVE-2014-8106: cirrus: fix blit region check

In reply to Andrew Cooper

Backport of qemu-upstream:
* bf25983345ca44aec3dd92c57142be45452bd38a
* d3532a0db02296e687711b8cdc7791924efccea0

---
 hw/cirrus_vga.c |   66 +++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 49 insertions(+), 17 deletions(-)
hw/cirrus_vga.c +49 -17
index 11ce212..d3bf4cf 100644
@@ -34,6 +34,8 @@
 #include "qemu-xen.h"
 #include "qemu-log.h"
 
+#include <assert.h>
+
 /*
  * TODO:
  *    - destination write mask support not complete (bits 5..7)
@@ -223,20 +225,6 @@
 
 #define ABS(a) ((signed)(a) > 0 ? a : -a)
 
-#define BLTUNSAFE(s) \
-    ( \
-        ( /* check dst is within bounds */ \
-            (s)->cirrus_blt_height * ABS((s)->cirrus_blt_dstpitch) \
-                + ((s)->cirrus_blt_dstaddr & (s)->cirrus_addr_mask) > \
-                    (s)->vram_size \
-        ) || \
-        ( /* check src is within bounds */ \
-            (s)->cirrus_blt_height * ABS((s)->cirrus_blt_srcpitch) \
-                + ((s)->cirrus_blt_srcaddr & (s)->cirrus_addr_mask) > \
-                    (s)->vram_size \
-        ) \
-    )
-
 struct CirrusVGAState;
 typedef void (*cirrus_bitblt_rop_t) (struct CirrusVGAState *s,
                                      uint8_t * dst, const uint8_t * src,
@@ -315,6 +303,50 @@ static void cirrus_vga_mem_writew(void *opaque, target_phys_addr_t addr, uint32_
  *
  ***************************************/
 
+static bool blit_region_is_unsafe(struct CirrusVGAState *s,
+                                  int32_t pitch, int32_t addr)
+{
+    if (pitch < 0) {
+        int64_t min = addr
+            + ((int64_t)s->cirrus_blt_height-1) * pitch;
+        int32_t max = addr
+            + s->cirrus_blt_width;
+        if (min < 0 || max >= s->vram_size) {
+            return true;
+        }
+    } else {
+        int64_t max = addr
+            + ((int64_t)s->cirrus_blt_height-1) * pitch
+            + s->cirrus_blt_width;
+        if (max >= s->vram_size) {
+            return true;
+        }
+    }
+    return false;
+}
+
+static bool blit_is_unsafe(struct CirrusVGAState *s)
+{
+    /* should be the case, see cirrus_bitblt_start */
+    assert(s->cirrus_blt_width > 0);
+    assert(s->cirrus_blt_height > 0);
+
+    if (s->cirrus_blt_width > CIRRUS_BLTBUFSIZE) {
+        return true;
+    }
+
+    if (blit_region_is_unsafe(s, s->cirrus_blt_dstpitch,
+                              s->cirrus_blt_dstaddr & s->cirrus_addr_mask)) {
+        return true;
+    }
+    if (blit_region_is_unsafe(s, s->cirrus_blt_srcpitch,
+                              s->cirrus_blt_srcaddr & s->cirrus_addr_mask)) {
+        return true;
+    }
+
+    return false;
+}
+
 static void cirrus_bitblt_rop_nop(CirrusVGAState *s,
                                   uint8_t *dst,const uint8_t *src,
                                   int dstpitch,int srcpitch,
@@ -676,7 +708,7 @@ static int cirrus_bitblt_common_patterncopy(CirrusVGAState * s,
 
     dst = s->vram_ptr + (s->cirrus_blt_dstaddr & s->cirrus_addr_mask);
 
-    if (BLTUNSAFE(s))
+    if (blit_is_unsafe(s))
         return 0;
 
     (*s->cirrus_rop) (s, dst, src,
@@ -694,7 +726,7 @@ static int cirrus_bitblt_solidfill(CirrusVGAState *s, int blt_rop)
 {
     cirrus_fill_t rop_func;
 
-    if (BLTUNSAFE(s))
+    if (blit_is_unsafe(s))
         return 0;
     rop_func = cirrus_fill[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1];
     rop_func(s, s->vram_ptr + (s->cirrus_blt_dstaddr & s->cirrus_addr_mask),
@@ -790,7 +822,7 @@ static void cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)
 
 static int cirrus_bitblt_videotovideo_copy(CirrusVGAState * s)
 {
-    if (BLTUNSAFE(s))
+    if (blit_is_unsafe(s))
         return 0;
 
     cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->start_addr,
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH 7/32 CVE-2014-7815: vnc: sanitize bits_per_pixel from the client

In reply to Andrew Cooper

Backport of qemu-upstream:
* e6908bfe8e07f2b452e78e677da1b45b1c0f6829

---
 vnc.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
vnc.c +10 -0
index 7629dfa..7006a34 100644
@@ -1616,6 +1616,16 @@ static void set_pixel_format(VncState *vs,
         return;
     }
 
+    switch (bits_per_pixel) {
+    case 8:
+    case 16:
+    case 32:
+        break;
+    default:
+        vnc_client_error(vs);
+        return;
+    }
+
     vs->clientds = vs->serverds;
     vs->clientds.pf.rmax = red_max;
     count_bits(vs->clientds.pf.rbits, red_max);
Signature · 1 line
1.7.10.4
#8 lore raw

PATCH 8/32 CVE-2014-3615: vbe: rework sanity checks

In reply to Andrew Cooper

Backport of qemu-upstream:
* c1b886c45dc70f247300f549dce9833f3fa2def5

---
 hw/vga.c |  154 ++++++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 95 insertions(+), 59 deletions(-)
hw/vga.c +95 -59
index d0c12aa..e8b1ce0 100644
@@ -521,6 +521,93 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val)
 }
 
 #ifdef CONFIG_BOCHS_VBE
+/*
+ * Sanity check vbe register writes.
+ *
+ * As we don't have a way to signal errors to the guest in the bochs
+ * dispi interface we'll go adjust the registers to the closest valid
+ * value.
+ */
+static void vbe_fixup_regs(VGAState *s)
+{
+    uint16_t *r = s->vbe_regs;
+    uint32_t bits, linelength, maxy, offset;
+
+    if (!(r[VBE_DISPI_INDEX_ENABLE] & VBE_DISPI_ENABLED)) {
+        /* vbe is turned off -- nothing to do */
+        return;
+    }
+
+    /* check depth */
+    switch (r[VBE_DISPI_INDEX_BPP]) {
+    case 4:
+    case 8:
+    case 16:
+    case 24:
+    case 32:
+        bits = r[VBE_DISPI_INDEX_BPP];
+        break;
+    case 15:
+        bits = 16;
+        break;
+    default:
+        bits = r[VBE_DISPI_INDEX_BPP] = 8;
+        break;
+    }
+
+    /* check width */
+    r[VBE_DISPI_INDEX_XRES] &= ~7u;
+    if (r[VBE_DISPI_INDEX_XRES] == 0) {
+        r[VBE_DISPI_INDEX_XRES] = 8;
+    }
+    if (r[VBE_DISPI_INDEX_XRES] > VBE_DISPI_MAX_XRES) {
+        r[VBE_DISPI_INDEX_XRES] = VBE_DISPI_MAX_XRES;
+    }
+    r[VBE_DISPI_INDEX_VIRT_WIDTH] &= ~7u;
+    if (r[VBE_DISPI_INDEX_VIRT_WIDTH] > VBE_DISPI_MAX_XRES) {
+        r[VBE_DISPI_INDEX_VIRT_WIDTH] = VBE_DISPI_MAX_XRES;
+    }
+    if (r[VBE_DISPI_INDEX_VIRT_WIDTH] < r[VBE_DISPI_INDEX_XRES]) {
+        r[VBE_DISPI_INDEX_VIRT_WIDTH] = r[VBE_DISPI_INDEX_XRES];
+    }
+
+    /* check height */
+    linelength = r[VBE_DISPI_INDEX_VIRT_WIDTH] * bits / 8;
+    maxy = s->vram_size / linelength;
+    if (r[VBE_DISPI_INDEX_YRES] == 0) {
+        r[VBE_DISPI_INDEX_YRES] = 1;
+    }
+    if (r[VBE_DISPI_INDEX_YRES] > VBE_DISPI_MAX_YRES) {
+        r[VBE_DISPI_INDEX_YRES] = VBE_DISPI_MAX_YRES;
+    }
+    if (r[VBE_DISPI_INDEX_YRES] > maxy) {
+        r[VBE_DISPI_INDEX_YRES] = maxy;
+    }
+
+    /* check offset */
+    if (r[VBE_DISPI_INDEX_X_OFFSET] > VBE_DISPI_MAX_XRES) {
+        r[VBE_DISPI_INDEX_X_OFFSET] = VBE_DISPI_MAX_XRES;
+    }
+    if (r[VBE_DISPI_INDEX_Y_OFFSET] > VBE_DISPI_MAX_YRES) {
+        r[VBE_DISPI_INDEX_Y_OFFSET] = VBE_DISPI_MAX_YRES;
+    }
+    offset = r[VBE_DISPI_INDEX_X_OFFSET] * bits / 8;
+    offset += r[VBE_DISPI_INDEX_Y_OFFSET] * linelength;
+    if (offset + r[VBE_DISPI_INDEX_YRES] * linelength > s->vram_size) {
+        r[VBE_DISPI_INDEX_Y_OFFSET] = 0;
+        offset = r[VBE_DISPI_INDEX_X_OFFSET] * bits / 8;
+        if (offset + r[VBE_DISPI_INDEX_YRES] * linelength > s->vram_size) {
+            r[VBE_DISPI_INDEX_X_OFFSET] = 0;
+            offset = 0;
+        }
+    }
+
+    /* update vga state */
+    r[VBE_DISPI_INDEX_VIRT_HEIGHT] = maxy;
+    s->vbe_line_offset = linelength;
+    s->vbe_start_addr  = offset / 4;
+}
+
 static uint32_t vbe_ioport_read_index(void *opaque, uint32_t addr)
 {
     VGAState *s = opaque;
@@ -588,22 +675,13 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val)
             }
             break;
         case VBE_DISPI_INDEX_XRES:
-            if ((val <= VBE_DISPI_MAX_XRES) && ((val & 7) == 0)) {
-                s->vbe_regs[s->vbe_index] = val;
-            }
-            break;
         case VBE_DISPI_INDEX_YRES:
-            if (val <= VBE_DISPI_MAX_YRES) {
-                s->vbe_regs[s->vbe_index] = val;
-            }
-            break;
         case VBE_DISPI_INDEX_BPP:
-            if (val == 0)
-                val = 8;
-            if (val == 4 || val == 8 || val == 15 ||
-                val == 16 || val == 24 || val == 32) {
-                s->vbe_regs[s->vbe_index] = val;
-            }
+        case VBE_DISPI_INDEX_VIRT_WIDTH:
+        case VBE_DISPI_INDEX_X_OFFSET:
+        case VBE_DISPI_INDEX_Y_OFFSET:
+            s->vbe_regs[s->vbe_index] = val;
+            vbe_fixup_regs(s);
             break;
         case VBE_DISPI_INDEX_BANK:
             if (s->vbe_regs[VBE_DISPI_INDEX_BPP] == 4) {
@@ -623,19 +701,11 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val)
                      set_vram_mapping(s, s->lfb_addr, s->lfb_end);
                 }
 
-                s->vbe_regs[VBE_DISPI_INDEX_VIRT_WIDTH] =
-                    s->vbe_regs[VBE_DISPI_INDEX_XRES];
-                s->vbe_regs[VBE_DISPI_INDEX_VIRT_HEIGHT] =
-                    s->vbe_regs[VBE_DISPI_INDEX_YRES];
+                s->vbe_regs[VBE_DISPI_INDEX_VIRT_WIDTH] = 0;
                 s->vbe_regs[VBE_DISPI_INDEX_X_OFFSET] = 0;
                 s->vbe_regs[VBE_DISPI_INDEX_Y_OFFSET] = 0;
-
-                if (s->vbe_regs[VBE_DISPI_INDEX_BPP] == 4)
-                    s->vbe_line_offset = s->vbe_regs[VBE_DISPI_INDEX_XRES] >> 1;
-                else
-                    s->vbe_line_offset = s->vbe_regs[VBE_DISPI_INDEX_XRES] *
-                        ((s->vbe_regs[VBE_DISPI_INDEX_BPP] + 7) >> 3);
-                s->vbe_start_addr = 0;
+                s->vbe_regs[VBE_DISPI_INDEX_ENABLE] |= VBE_DISPI_ENABLED;
+                vbe_fixup_regs(s);
 
                 /* clear the screen (should be done in BIOS) */
                 if (!(val & VBE_DISPI_NOCLEARMEM)) {
@@ -677,40 +747,6 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val)
             s->dac_8bit = (val & VBE_DISPI_8BIT_DAC) > 0;
             s->vbe_regs[s->vbe_index] = val;
             break;
-        case VBE_DISPI_INDEX_VIRT_WIDTH:
-            {
-                int w, h, line_offset;
-
-                if (val < s->vbe_regs[VBE_DISPI_INDEX_XRES])
-                    return;
-                w = val;
-                if (s->vbe_regs[VBE_DISPI_INDEX_BPP] == 4)
-                    line_offset = w >> 1;
-                else
-                    line_offset = w * ((s->vbe_regs[VBE_DISPI_INDEX_BPP] + 7) >> 3);
-                h = s->vram_size / line_offset;
-                /* XXX: support weird bochs semantics ? */
-                if (h < s->vbe_regs[VBE_DISPI_INDEX_YRES])
-                    return;
-                s->vbe_regs[VBE_DISPI_INDEX_VIRT_WIDTH] = w;
-                s->vbe_regs[VBE_DISPI_INDEX_VIRT_HEIGHT] = h;
-                s->vbe_line_offset = line_offset;
-            }
-            break;
-        case VBE_DISPI_INDEX_X_OFFSET:
-        case VBE_DISPI_INDEX_Y_OFFSET:
-            {
-                int x;
-                s->vbe_regs[s->vbe_index] = val;
-                s->vbe_start_addr = s->vbe_line_offset * s->vbe_regs[VBE_DISPI_INDEX_Y_OFFSET];
-                x = s->vbe_regs[VBE_DISPI_INDEX_X_OFFSET];
-                if (s->vbe_regs[VBE_DISPI_INDEX_BPP] == 4)
-                    s->vbe_start_addr += x >> 1;
-                else
-                    s->vbe_start_addr += x * ((s->vbe_regs[VBE_DISPI_INDEX_BPP] + 7) >> 3);
-                s->vbe_start_addr >>= 2;
-            }
-            break;
         default:
             break;
         }
Signature · 1 line
1.7.10.4
#9 lore raw

PATCH 9/32 cirrus_vga: fix division by 0 for color expansion rop

In reply to Andrew Cooper

From: Aurelien Jarno <[email protected]>

Commit d85d0d3883f5a567fa2969a0396e42e0a662b3fa introduces a regression with Windows ME that leads to a division by 0 and a crash.

It uses the color expansion rop with the source pitch set to 0. This is something allowed, as the manual explicitely says "When the source of color-expand data is display memory, the source pitch is ignored.".

This patch fixes this regression by computing sx, sy and others variables only if they are going to be used later, that is for a plain copy ROP. It basically consists in moving code.

---
 hw/cirrus_vga.c |   70 +++++++++++++++++++++++++++----------------------------
 1 file changed, 35 insertions(+), 35 deletions(-)
hw/cirrus_vga.c +35 -35
index d3bf4cf..e6c3893 100644
@@ -754,46 +754,46 @@ static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState * s)
 
 static void cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)
 {
-    int sx, sy;
-    int dx, dy;
-    int width, height;
-    int depth;
+    int sx = 0, sy = 0;
+    int dx = 0, dy = 0;
+    int depth = 0;
     int notify = 0;
 
-    depth = s->get_bpp((VGAState *)s) / 8;
-    s->get_resolution((VGAState *)s, &width, &height);
-
-    /* extra x, y */
-    sx = (src % ABS(s->cirrus_blt_srcpitch)) / depth;
-    sy = (src / ABS(s->cirrus_blt_srcpitch));
-    dx = (dst % ABS(s->cirrus_blt_dstpitch)) / depth;
-    dy = (dst / ABS(s->cirrus_blt_dstpitch));
-
-    /* normalize width */
-    w /= depth;
-
-    /* if we're doing a backward copy, we have to adjust
-       our x/y to be the upper left corner (instead of the lower
-       right corner) */
-    if (s->cirrus_blt_dstpitch < 0) {
-	sx -= (s->cirrus_blt_width / depth) - 1;
-	dx -= (s->cirrus_blt_width / depth) - 1;
-	sy -= s->cirrus_blt_height - 1;
-	dy -= s->cirrus_blt_height - 1;
-    }
+    /* make sure to only copy if it's a plain copy ROP */
+    if (*s->cirrus_rop == cirrus_bitblt_rop_fwd_src ||
+        *s->cirrus_rop == cirrus_bitblt_rop_bkwd_src) {
+        int width, height;
+
+        depth = s->get_bpp((VGAState *)s) / 8;
+        s->get_resolution((VGAState *)s, &width, &height);
+
+        /* extra x, y */
+        sx = (src % ABS(s->cirrus_blt_srcpitch)) / depth;
+        sy = (src / ABS(s->cirrus_blt_srcpitch));
+        dx = (dst % ABS(s->cirrus_blt_dstpitch)) / depth;
+        dy = (dst / ABS(s->cirrus_blt_dstpitch));
+
+        /* normalize width */
+        w /= depth;
+
+        /* if we're doing a backward copy, we have to adjust
+           our x/y to be the upper left corner (instead of the lower
+           right corner) */
+        if (s->cirrus_blt_dstpitch < 0) {
+            sx -= (s->cirrus_blt_width / depth) - 1;
+            dx -= (s->cirrus_blt_width / depth) - 1;
+            sy -= s->cirrus_blt_height - 1;
+            dy -= s->cirrus_blt_height - 1;
+        }
 
-    /* are we in the visible portion of memory? */
-    if (sx >= 0 && sy >= 0 && dx >= 0 && dy >= 0 &&
-	(sx + w) <= width && (sy + h) <= height &&
-	(dx + w) <= width && (dy + h) <= height) {
-	notify = 1;
+        /* are we in the visible portion of memory? */
+        if (sx >= 0 && sy >= 0 && dx >= 0 && dy >= 0 &&
+            (sx + w) <= width && (sy + h) <= height &&
+            (dx + w) <= width && (dy + h) <= height) {
+            notify = 1;
+        }
     }
 
-    /* make to sure only copy if it's a plain copy ROP */
-    if (*s->cirrus_rop != cirrus_bitblt_rop_fwd_src &&
-	*s->cirrus_rop != cirrus_bitblt_rop_bkwd_src)
-	notify = 0;
-
     /* we have to flush all pending changes so that the copy
        is generated at the appropriate moment in time */
     if (notify)
Signature · 1 line
1.7.10.4
#10 lore raw

PATCH 10/32 ide: cancel dma operations on command abort or error

In reply to Andrew Cooper

From: Chunjie Zhu <[email protected]>

Otherwise, a guest can cause Qemu to reuse an active aio structure.

---
 hw/ide.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/ide.c +5 -2
index 791666b..83e3c70 100644
@@ -919,8 +919,10 @@ static void ide_set_signature(IDEState *s)
     }
 }
 
+static void ide_dma_cancel(BMDMAState *bm);
 static inline void ide_abort_command(IDEState *s)
 {
+    if (s->bmdma) ide_dma_cancel(s->bmdma);
     s->status = READY_STAT | ERR_STAT;
     s->error = ABRT_ERR;
 }
@@ -1098,6 +1100,7 @@ static void dma_buf_commit(IDEState *s, int is_write)
 
 static void ide_dma_error(IDEState *s)
 {
+    if (s->bmdma) ide_dma_cancel(s->bmdma);
     ide_transfer_stop(s);
     s->error = ABRT_ERR;
     s->status = READY_STAT | ERR_STAT;
@@ -1230,7 +1233,7 @@ static void ide_read_dma_cb(void *opaque, int ret)
 	return;
     }
 
-    if (!s->bs) return; /* ouch! (see ide_flush_cb) */
+    if (!s || !s->bs) return; /* ouch! (see ide_dma_error & ide_flush_cb) */
 
     n = s->io_buffer_size >> 9;
     sector_num = ide_get_sector(s);
@@ -1371,7 +1374,7 @@ static void ide_write_dma_cb(void *opaque, int ret)
             return;
     }
 
-    if (!s->bs) return; /* ouch! (see ide_flush_cb) */
+    if (!s || !s->bs) return; /* ouch! (see ide_dma_error & ide_flush_cb) */
 
     n = s->io_buffer_size >> 9;
     sector_num = ide_get_sector(s);
Signature · 1 line
1.7.10.4
#11 lore raw

PATCH 11/32 dma: fix incorrect bh scheduling

In reply to Andrew Cooper

From: Chunjie Zhu <[email protected]>

The following 2 cases should be avoided:

1. DMAAIOCB has been released but continue_after_map_failure schedules a bh for it.
2. Multiple bh calls are schduled on the same DMAAIOCB.

---
 dma-helpers.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
dma-helpers.c +15 -1
index 2a1621b..c9fbbd9 100644
@@ -50,8 +50,14 @@ typedef struct {
     target_phys_addr_t sg_cur_byte;
     QEMUIOVector iov;
     QEMUBH *bh;
+    int in_use;
 } DMAAIOCB;
 
+static void dma_aio_cb_reset(DMAAIOCB *p)
+{
+    p->in_use = 0;
+}
+
 static void dma_bdrv_cb(void *opaque, int ret);
 
 static void reschedule_dma(void *opaque)
@@ -60,6 +66,10 @@ static void reschedule_dma(void *opaque)
 
     qemu_bh_delete(dbs->bh);
     dbs->bh = NULL;
+
+    if (!dbs->in_use)
+        return;
+
     dma_bdrv_cb(opaque, 0);
 }
 
@@ -67,7 +77,8 @@ static void continue_after_map_failure(void *opaque)
 {
     DMAAIOCB *dbs = (DMAAIOCB *)opaque;
 
-    dbs->bh = qemu_bh_new(reschedule_dma, dbs);
+    if (!dbs->bh)
+        dbs->bh = qemu_bh_new(reschedule_dma, dbs);
     qemu_bh_schedule(dbs->bh);
 }
 
@@ -97,6 +108,7 @@ void dma_bdrv_cb(void *opaque, int ret)
         dbs->common.cb(dbs->common.opaque, ret);
         qemu_iovec_destroy(&dbs->iov);
         qemu_aio_release(dbs);
+        dma_aio_cb_reset(dbs);
         return;
     }
 
@@ -129,6 +141,7 @@ void dma_bdrv_cb(void *opaque, int ret)
     if (!dbs->acb) {
         dma_bdrv_unmap(dbs);
         qemu_iovec_destroy(&dbs->iov);
+        dma_aio_cb_reset(dbs);
         return;
     }
 }
@@ -148,6 +161,7 @@ static BlockDriverAIOCB *dma_bdrv_io(
     dbs->sg_cur_byte = 0;
     dbs->is_write = is_write;
     dbs->bh = NULL;
+    dbs->in_use = 1;
     qemu_iovec_init(&dbs->iov, sg->nsg);
     dma_bdrv_cb(dbs, 0);
     if (!dbs->acb) {
Signature · 1 line
1.7.10.4
#12 lore raw

PATCH 12/32 cmdline: Parse -pciemulation before trying to use it

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

---
 vl.c |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
vl.c +9 -9
index d21c3aa..67d9d86 100644
@@ -5952,6 +5952,15 @@ int main(int argc, char **argv, char **envp)
         }
     }
 
+#ifdef CONFIG_PASSTHROUGH
+    for (i = 0; i < nb_pci_emulation; i++) {
+        if (pci_emulation_add(pci_emulation_config_text[i]) < 0) {
+            fprintf(stderr, "Warning: could not add PCI device %s\n",
+                    pci_emulation_config_text[i]);
+        }
+    }
+#endif
+
     machine->init(ram_size, vga_ram_size, boot_devices,
                   kernel_filename, kernel_cmdline, initrd_filename, cpu_model,
 		  direct_pci);
@@ -6068,15 +6077,6 @@ int main(int argc, char **argv, char **envp)
         }
     }
 
-#ifdef CONFIG_PASSTHROUGH
-    for (i = 0; i < nb_pci_emulation; i++) {
-        if (pci_emulation_add(pci_emulation_config_text[i]) < 0) {
-            fprintf(stderr, "Warning: could not add PCI device %s\n",
-                    pci_emulation_config_text[i]);
-        }
-    }
-#endif
-
     for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
         const char *devname = virtio_consoles[i];
         if (virtcon_hds[i] && devname) {
Signature · 1 line
1.7.10.4
#13 lore raw

PATCH 13/32 smbios: Don't allocate smbus eeprom buffer

In reply to Andrew Cooper

smbus_eeprom_device_init() has been disabled since 2007. The #define turns the actual function call into a comma expression with no effect.

Removing the leaked allocation also makes Valgrind happier.

Coverity-ID: 1090387

---
 hw/pc.c |   12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
hw/pc.c +1 -11
index 3e33694..7359338 100644
@@ -79,7 +79,6 @@ static void xen_relocator_hook(target_phys_addr_t *prot_addr_upd,
                                uint16_t protocol,
 			       const uint8_t header[], int kernel_size,
 			       target_phys_addr_t real_addr, int real_size);
-#define smbus_eeprom_device_init (void)
 
 static void ioport80_write(void *opaque, uint32_t addr, uint32_t data)
 {
@@ -1135,17 +1134,8 @@ vga_bios_error:
     }
 
     if (pci_enabled && acpi_enabled) {
-        uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
-        i2c_bus *smbus;
-
         /* TODO: Populate SPD eeprom data.  */
-        smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100, i8259[9]);
-
-	if (smbus) {
-	    for (i = 0; i < 8; i++) {
-		smbus_eeprom_device_init(smbus, 0x50 + i, eeprom_buf + (i * 256));
-	    }
-        }
+        piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100, i8259[9]);
     }
 
     if (i440fx_state) {
Signature · 1 line
1.7.10.4
#14 lore raw

PATCH 14/32 pic: Don't allocate irq buffers

In reply to Andrew Cooper

i8259_init() doesn't inspect its argument at all, causing the allocation to be leaked and never used.

---
 hw/pc.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/pc.c +1 -3
index 7359338..09b4af4 100644
@@ -801,7 +801,6 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
     PCIBus *pci_bus;
     int piix3_devfn = -1;
     CPUState *env;
-    qemu_irq *cpu_irq;
     qemu_irq *i8259;
     int index;
     BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
@@ -970,8 +969,7 @@ vga_bios_error:
 
     bochs_bios_init();
 
-    cpu_irq = qemu_allocate_irqs(pic_irq_request, NULL, 1);
-    i8259 = i8259_init(cpu_irq[0]);
+    i8259 = i8259_init(NULL);
     ferr_irq = i8259[13];
 
     if (pci_enabled) {
Signature · 1 line
1.7.10.4
#15 lore raw

PATCH 15/32 signal: Don't use uninitalised sival_ptr

In reply to Andrew Cooper

In 64bit builds, setting sival_int to 0 doesn't clear the upper half of the sival_ptr pointer. Valgrind does not like this.

---
 vl.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
vl.c +1 -2
index 67d9d86..c864e7d 100644
@@ -1568,7 +1568,7 @@ static void rtc_stop_timer(struct qemu_alarm_timer *t)
 
 static int dynticks_start_timer(struct qemu_alarm_timer *t)
 {
-    struct sigevent ev;
+    struct sigevent ev = { { 0 } };
     timer_t host_timer;
     struct sigaction act;
 
@@ -1578,7 +1578,6 @@ static int dynticks_start_timer(struct qemu_alarm_timer *t)
 
     sigaction(SIGALRM, &act, NULL);
 
-    ev.sigev_value.sival_int = 0;
     ev.sigev_notify = SIGEV_SIGNAL;
     ev.sigev_signo = SIGALRM;
 
Signature · 1 line
1.7.10.4
#16 lore raw

PATCH 16/32 hw/msmouse.c: Fix deref_after_free and double free

In reply to Andrew Cooper

From: Yunlei Ding <[email protected]>

msmouse_chr_close is only pointed by chr->chr_close in qemu_chr_close function. After calling chr->chr_close, chr will be freed. So we don't need to free it again here.

(defect not identified by Coverity Scan)

---
 hw/msmouse.c |    1 -
 1 file changed, 1 deletion(-)
hw/msmouse.c +0 -1
index 69356a5..2d2703b 100644
@@ -61,7 +61,6 @@ static int msmouse_chr_write (struct CharDriverState *s, const uint8_t *buf, int
 
 static void msmouse_chr_close (struct CharDriverState *chr)
 {
-    qemu_free (chr);
 }
 
 CharDriverState *qemu_chr_open_msmouse(void)
Signature · 1 line
1.7.10.4
#17 lore raw

PATCH 17/32 readline: fix memory corruption when adding history

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

idx can be down to 0, so TERM_MAX_CMDS-idx+1 could be TERM_MAX_CMDS+1, which exceeds the size of term_history.

Coverity-ID: 1055739

---
 readline.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
readline.c +1 -1
index 8572841..4b68726 100644
@@ -267,7 +267,7 @@ static void term_hist_add(const char *cmdline)
 	    new_entry = hist_entry;
 	    /* Put this entry at the end of history */
 	    memmove(&term_history[idx], &term_history[idx + 1],
-		    (TERM_MAX_CMDS - idx + 1) * sizeof(char *));
+		    (TERM_MAX_CMDS - (idx + 1)) * sizeof(char *));
 	    term_history[TERM_MAX_CMDS - 1] = NULL;
 	    for (; idx < TERM_MAX_CMDS; idx++) {
 		if (term_history[idx] == NULL)
Signature · 1 line
1.7.10.4
#18 lore raw

PATCH 18/32 block-cow: don't close cow_fd twice on error

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

Coverity-ID: 1056200

---
 block-cow.c |    1 -
 1 file changed, 1 deletion(-)
block-cow.c +0 -1
index 777d8a5..9ad0a32 100644
@@ -224,7 +224,6 @@ static int cow_create(const char *filename, int64_t image_sectors,
 
         fd = open(image_filename, O_RDONLY | O_BINARY);
         if (fd < 0) {
-            close(cow_fd);
             goto mtime_fail;
         }
         if (fstat(fd, &st) != 0) {
Signature · 1 line
1.7.10.4
#19 lore raw

PATCH 19/32 console: Avoid overrunning the dmask arrays

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

The valide range of font_data should be [0, 0xFF].

(defects not identified by Coverity Scan)

---
 console.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
console.c +5 -4
index 9984d6f..d4f1ad0 100644
@@ -421,7 +421,8 @@ static void vga_putcharxy(DisplayState *ds, int x, int y, int ch,
 {
     uint8_t *d;
     const uint8_t *font_ptr;
-    unsigned int font_data, linesize, xorcol, bpp;
+    uint8_t font_data;
+    unsigned int linesize, xorcol, bpp;
     int i;
     unsigned int fgcol, bgcol;
 
@@ -450,7 +451,7 @@ static void vga_putcharxy(DisplayState *ds, int x, int y, int ch,
             font_data = *font_ptr++;
             if (t_attrib->uline
                 && ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) {
-                font_data = 0xFFFF;
+                font_data = 0xFF;
             }
             ((uint32_t *)d)[0] = (dmask16[(font_data >> 4)] & xorcol) ^ bgcol;
             ((uint32_t *)d)[1] = (dmask16[(font_data >> 0) & 0xf] & xorcol) ^ bgcol;
@@ -463,7 +464,7 @@ static void vga_putcharxy(DisplayState *ds, int x, int y, int ch,
             font_data = *font_ptr++;
             if (t_attrib->uline
                 && ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) {
-                font_data = 0xFFFF;
+                font_data = 0xFF;
             }
             ((uint32_t *)d)[0] = (dmask4[(font_data >> 6)] & xorcol) ^ bgcol;
             ((uint32_t *)d)[1] = (dmask4[(font_data >> 4) & 3] & xorcol) ^ bgcol;
@@ -476,7 +477,7 @@ static void vga_putcharxy(DisplayState *ds, int x, int y, int ch,
         for(i = 0; i < FONT_HEIGHT; i++) {
             font_data = *font_ptr++;
             if (t_attrib->uline && ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) {
-                font_data = 0xFFFF;
+                font_data = 0xFF;
             }
             ((uint32_t *)d)[0] = (-((font_data >> 7)) & xorcol) ^ bgcol;
             ((uint32_t *)d)[1] = (-((font_data >> 6) & 1) & xorcol) ^ bgcol;
Signature · 1 line
1.7.10.4
#20 lore raw

PATCH 20/32 hw/device-hotplug: fix test of drive_add() return

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

drive_opt_idx could be -1 in case error occurs inside drive_add, so the error check should be "if (drive_opt_idx < 0)" instead of original
"if (!drive_opt_idx)".

Coverity-ID: 1055574

---
 hw/device-hotplug.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/device-hotplug.c +1 -1
index 3bdc048..97d3529 100644
@@ -34,7 +34,7 @@ int add_init_drive(const char *opts)
     int ret = -1;
 
     drive_opt_idx = drive_add(NULL, "%s", opts);
-    if (!drive_opt_idx)
+    if (drive_opt_idx < 0)
         return ret;
 
     drive_idx = drive_init(&drives_opt[drive_opt_idx], 0, current_machine);
Signature · 1 line
1.7.10.4
#21 lore raw

PATCH 21/32 qemu-char: fix memory leak in qemu_char_open_pty()

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

The momery pointed by s and chr could be leaked if openpty return a value less then 0.

Coverity-IDs: 1055926 1055927

---
 qemu-char.c |    2 ++
 1 file changed, 2 insertions(+)
qemu-char.c +2 -0
index 324ed16..f62a6af 100644
@@ -932,6 +932,8 @@ static CharDriverState *qemu_chr_open_pty(void)
     s = qemu_mallocz(sizeof(PtyCharDriver));
 
     if (openpty(&s->fd, &slave_fd, pty_name, NULL, NULL) < 0) {
+        qemu_free(s);
+        qemu_free(chr);
         return NULL;
     }
 
Signature · 1 line
1.7.10.4
#22 lore raw

PATCH 22/32 hw/ide: fix memory leak from qemu_allocate_irqs()

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

qemu_allocate_irqs would return an array of irqs, not store the allocated array pointer, and subsequently leak it.

(defects not identified by Coverity Scan)

---
 hw/ide.c |    2 +-
 hw/irq.c |   18 +++++++++++++++++-
 hw/irq.h |    4 ++++
 3 files changed, 22 insertions(+), 2 deletions(-)
hw/ide.c +1 -1
index 83e3c70..f372b7b 100644
@@ -4769,7 +4769,7 @@ struct pcmcia_card_s *dscm1xxxx_init(BlockDriverState *bdrv)
     md->card.cis = dscm1xxxx_cis;
     md->card.cis_len = sizeof(dscm1xxxx_cis);
 
-    ide_init2(md->ide, bdrv, 0, qemu_allocate_irqs(md_set_irq, md, 1)[0]);
+    ide_init2(md->ide, bdrv, 0, qemu_allocate_irq(md_set_irq, md));
     md->ide->is_cf = 1;
     md->ide->mdata_size = METADATA_SIZE;
     md->ide->mdata_storage = (uint8_t *) qemu_mallocz(METADATA_SIZE);
hw/irq.c +17 -1
index 7703f62..c7c4864 100644
@@ -38,6 +38,22 @@ void qemu_set_irq(qemu_irq irq, int level)
     irq->handler(irq->opaque, irq->n, level);
 }
 
+qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque)
+{
+    struct IRQState *irq;
+
+    irq = (struct IRQState *)qemu_mallocz(sizeof(struct IRQState));
+    irq->handler = handler;
+    irq->opaque = opaque;
+    irq->n = 0;
+    return irq;
+}
+
+void qemu_free_irq(qemu_irq irq)
+{
+    qemu_free(irq);
+}
+
 qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n)
 {
     qemu_irq *s;
@@ -73,5 +89,5 @@ qemu_irq qemu_irq_invert(qemu_irq irq)
 {
     /* The default state for IRQs is low, so raise the output now.  */
     qemu_irq_raise(irq);
-    return qemu_allocate_irqs(qemu_notirq, irq, 1)[0];
+    return qemu_allocate_irq(qemu_notirq, irq);
 }
hw/irq.h +4 -0
index 5daae44..da34ae3 100644
@@ -25,6 +25,10 @@ static inline void qemu_irq_pulse(qemu_irq irq)
     qemu_set_irq(irq, 0);
 }
 
+/* Returns one IRQ.  */
+qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque);
+void qemu_free_irq(qemu_irq irq);
+
 /* Returns an array of N IRQs.  */
 qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n);
 void qemu_free_irqs(qemu_irq *s);
Signature · 1 line
1.7.10.4
#23 lore raw

PATCH 23/32 net: don't leak an fd after an error

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

fd will be leaked if launch_script failed.

Coverity-ID: 1055925

---
 net.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net.c +3 -1
index 720027c..f3887a7 100644
@@ -1049,8 +1049,10 @@ static int net_tap_init(VLANState *vlan, const char *model,
     if (!setup_script || !strcmp(setup_script, "no"))
         setup_script = "";
     if (setup_script[0] != '\0') {
-	if (launch_script(setup_script, ifname, script_arg, fd))
+	if (launch_script(setup_script, ifname, script_arg, fd)) {
+	    close(fd);
 	    return -1;
+	}
     }
     s = net_tap_fd_init(vlan, model, name, fd);
     if (!s)
Signature · 1 line
1.7.10.4
#24 lore raw

PATCH 24/32 net: Fix memory/handle leaks in net_socket_listen_init()

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

fd and s could be leaked in case bind/listen failed.

Coverity-IDs: 1055923 1055924

---
 net.c |    5 +++++
 1 file changed, 5 insertions(+)
net.c +5 -0
index f3887a7..33460d8 100644
@@ -1460,6 +1460,7 @@ static int net_socket_listen_init(VLANState *vlan,
     fd = socket(PF_INET, SOCK_STREAM, 0);
     if (fd < 0) {
         perror("socket");
+        qemu_free(s);
         return -1;
     }
     socket_set_nonblock(fd);
@@ -1471,11 +1472,15 @@ static int net_socket_listen_init(VLANState *vlan,
     ret = bind(fd, (struct sockaddr *)&saddr, sizeof(saddr));
     if (ret < 0) {
         perror("bind");
+        closesocket(fd);
+        qemu_free(s);
         return -1;
     }
     ret = listen(fd, 0);
     if (ret < 0) {
         perror("listen");
+        closesocket(fd);
+        qemu_free(s);
         return -1;
     }
     s->vlan = vlan;
Signature · 1 line
1.7.10.4
#25 lore raw

PATCH 25/32 block-vvfat: fix memory/handle leaks in commit_one_file()

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

Some handles and memory in commit_one_file are going to be leaked if certain function calls failed.

Coverity-IDs: 1055918 1055919

---
 block-vvfat.c |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
block-vvfat.c +14 -3
index 345d7be..ec3363c 100644
@@ -2229,11 +2229,15 @@ static int commit_one_file(BDRVVVFATState* s,
     if (fd < 0) {
 	fprintf(stderr, "Could not open %s... (%s, %d)\n", mapping->path,
 		strerror(errno), errno);
+	qemu_free(cluster);
 	return fd;
     }
     if (offset > 0)
-	if (lseek(fd, offset, SEEK_SET) != offset)
+	if (lseek(fd, offset, SEEK_SET) != offset) {
+	    close(fd);
+	    qemu_free(cluster);
 	    return -3;
+	}
 
     while (offset < size) {
 	uint32_t c1;
@@ -2249,11 +2253,17 @@ static int commit_one_file(BDRVVVFATState* s,
 	ret = vvfat_read(s->bs, cluster2sector(s, c),
 	    (uint8_t*)cluster, (rest_size + 0x1ff) / 0x200);
 
-	if (ret < 0)
+	if (ret < 0) {
+	    close(fd);
+	    qemu_free(cluster);
 	    return ret;
+	}
 
-	if (qemu_write_ok(fd, cluster, rest_size) < 0)
+	if (qemu_write_ok(fd, cluster, rest_size) < 0) {
+	    close(fd);
+	    qemu_free(cluster);
 	    return -2;
+	}
 
 	offset += rest_size;
 	c = c1;
@@ -2261,6 +2271,7 @@ static int commit_one_file(BDRVVVFATState* s,
 
     ftruncate(fd, size);
     close(fd);
+    qemu_free(cluster);
 
     return commit_mappings(s, first_cluster, dir_index);
 }
Signature · 1 line
1.7.10.4
#26 lore raw

PATCH 26/32 block-vvfat: fix memory leak in check_directory_consistency()

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

Memory pointed by cluster leaks in error handling code.

Coverity-ID: 1055917

---
 block-vvfat.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block-vvfat.c +1 -1
index ec3363c..6cd57a2 100644
@@ -1769,7 +1769,7 @@ static int check_directory_consistency(BDRVVVFATState *s,
 
 	if (s->used_clusters[cluster_num] & USED_ANY) {
 	    fprintf(stderr, "cluster %d used more than once\n", (int)cluster_num);
-	    return 0;
+	    goto fail;
 	}
 	s->used_clusters[cluster_num] = USED_DIRECTORY;
 
Signature · 1 line
1.7.10.4
#27 lore raw

PATCH 27/32 virtio-blk: correctly link new request in virtio_blk_load()

In reply to Andrew Cooper

From: Yunlei Ding <[email protected]>

s->rq should be set with req instead of req-next.

Coverity-ID: 1055910

---
 hw/virtio-blk.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio-blk.c +1 -1
index fcf893a..f3a81e3 100644
@@ -288,7 +288,7 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
         VirtIOBlockReq *req = virtio_blk_alloc_request(s);
         qemu_get_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem));
         req->next = s->rq;
-        s->rq = req->next;
+        s->rq = req;
     }
 
     return 0;
Signature · 1 line
1.7.10.4
#28 lore raw

PATCH 28/32 net: initialize parameters before use in net_socket_fd_init_dgram()

In reply to Andrew Cooper

From: Yunlei Ding <[email protected]>

Coverity-IDs: 1005339 1005340

---
 net.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net.c +3 -1
index 33460d8..8aba3c2 100644
@@ -1316,9 +1316,11 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
 {
     struct sockaddr_in saddr;
     int newfd;
-    socklen_t saddr_len;
+    socklen_t saddr_len = sizeof(saddr);
     NetSocketState *s;
 
+    memset(&saddr, 0, sizeof(saddr));
+
     /* fd passed: multicast: "learn" dgram_dst address from bound address and save it
      * Because this may be "shared" socket from a "master" process, datagrams would be recv()
      * by ONLY ONE process: we must "clone" this dgram socket --jjo
Signature · 1 line
1.7.10.4
#29 lore raw

PATCH 29/32 ide: don't leak irq array in pci_cmd646_ide_init()

In reply to Andrew Cooper

From: Yunlei Ding <[email protected]>

Call qemu_allocate_irq() twice instead of qemu_allocate_irqs to allocate memory.

(defects not identified by Coverity Scan)

---
 hw/ide.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
hw/ide.c +2 -4
index f372b7b..e7b9f24 100644
@@ -3652,7 +3652,6 @@ void pci_cmd646_ide_init(PCIBus *bus, BlockDriverState **hd_table,
     PCIIDEState *d;
     uint8_t *pci_conf;
     int i;
-    qemu_irq *irq;
 
     d = (PCIIDEState *)pci_register_device(bus, "CMD646 IDE",
                                            sizeof(PCIIDEState),
@@ -3694,9 +3693,8 @@ void pci_cmd646_ide_init(PCIBus *bus, BlockDriverState **hd_table,
     for(i = 0; i < 4; i++)
         d->ide_if[i].pci_dev = (PCIDevice *)d;
 
-    irq = qemu_allocate_irqs(cmd646_set_irq, d, 2);
-    ide_init2(&d->ide_if[0], hd_table[0], hd_table[1], irq[0]);
-    ide_init2(&d->ide_if[2], hd_table[2], hd_table[3], irq[1]);
+    ide_init2(&d->ide_if[0], hd_table[0], hd_table[1], qemu_allocate_irq(cmd646_set_irq, d));
+    ide_init2(&d->ide_if[2], hd_table[2], hd_table[3], qemu_allocate_irq(cmd646_set_irq, d));
 
     register_savevm("ide", 0, 3, pci_ide_save, pci_ide_load, d);
     qemu_register_reset(cmd646_reset, d);
Signature · 1 line
1.7.10.4
#30 lore raw

PATCH 30/32 block-nbd: close sock in nbd_open() error path

In reply to Andrew Cooper

From: Yunlei Ding <[email protected]>

Close sock handle before return.

Coverity-ID: 1055914

---
 block-nbd.c |    3 +++
 1 file changed, 3 insertions(+)
block-nbd.c +3 -0
index dc63183..e2c90eb 100644
@@ -88,7 +88,10 @@ static int nbd_open(BlockDriverState *bs, const char* filename, int flags)
 
     ret = nbd_receive_negotiate(sock, &size, &blocksize);
     if (ret == -1)
+    {
+        close(sock);
         return -errno;
+    }
 
     s->sock = sock;
     s->size = size;
Signature · 1 line
1.7.10.4
#31 lore raw

PATCH 31/32 block-raw-posix: Fix memory leak in posix_aio_init()

In reply to Andrew Cooper

From: Yunlei Ding <[email protected]>

Free allocated memory s before return.

Coverity-ID: 1055915

---
 block-raw-posix.c |    1 +
 1 file changed, 1 insertion(+)
block-raw-posix.c +1 -0
index 795cd5b..8a1baa8 100644
@@ -602,6 +602,7 @@ static int posix_aio_init(void)
     s->first_aio = NULL;
     if (pipe(fds) == -1) {
         fprintf(stderr, "failed to create pipe\n");
+        qemu_free(s);
         return -errno;
     }
 
Signature · 1 line
1.7.10.4
#32 lore raw

PATCH 32/32 block-vvfat: fix resource leaks in read_directory()

In reply to Andrew Cooper

From: Yunlei Ding <[email protected]>

Coverity-IDs: 1055920 1055921

---
 block-vvfat.c |    3 +++
 1 file changed, 3 insertions(+)
block-vvfat.c +3 -0
index 6cd57a2..ff5c8bf 100644
@@ -760,6 +760,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)
         if (st.st_size > 0x7fffffff) {
 	    fprintf(stderr, "File %s is larger than 2GB\n", buffer);
 	    free(buffer);
+            closedir(dir);
 	    return -2;
         }
 	direntry->size=cpu_to_le32(S_ISDIR(st.st_mode)?0:st.st_size);
@@ -787,6 +788,8 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)
 	    s->current_mapping->read_only =
 		(st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) == 0;
 	}
+        else
+            qemu_free(buffer);
     }
     closedir(dir);
 
Signature · 1 line
1.7.10.4
#33 lore raw

PATCH 1/32 virtio-blk: initialise unused blkcfg.size_max field

In reply to Andrew Cooper

From: Yunlei Ding <[email protected]>

Newer GCC warns about memcpy()ing uninitialised data.

Coverity-ID: 1056088

---
 hw/virtio-blk.c |    1 +
 1 file changed, 1 insertion(+)
hw/virtio-blk.c +1 -0
index 520ad1b..fcf893a 100644
@@ -252,6 +252,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
     stw_raw(&blkcfg.cylinders, cylinders);
     blkcfg.heads = heads;
     blkcfg.sectors = secs;
+    blkcfg.size_max = 0;
     memcpy(config, &blkcfg, sizeof(blkcfg));
 }
 
Signature · 1 line
1.7.10.4
#34 lore raw

PATCH 2/32 cirrus_vga: default all I/O port reads to 0xff

Some error paths in vga_ioport_read() would return undefined values. Always default the result to 0xff.

---
 hw/cirrus_vga.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/cirrus_vga.c +1 -1
index a26b051..11ce212 100644
@@ -2674,7 +2674,7 @@ static void cirrus_update_memory_access(CirrusVGAState *s)
 static uint32_t vga_ioport_read(void *opaque, uint32_t addr)
 {
     CirrusVGAState *s = opaque;
-    int val, index;
+    int val = 0xff, index;
 
     /* check port range access depending on color/monochrome mode */
     if ((addr >= 0x3b0 && addr <= 0x3bf && (s->msr & MSR_COLOR_EMULATION))
Signature · 1 line
1.7.10.4
#35 lore raw

PATCH 3/32 lm832x: don't overrun file buffer on save/restore

In reply to Andrew Cooper

Saving and restoring an lm832x record would overrun the pwm.file array since pwm.file is uint16_t elements and sizeof(pwm.file) twice as many elements.

To ensure compatibility, padding bytes are added to the record.

Coverity-IDs: 1055728 1055729

---
 hw/lm832x.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
hw/lm832x.c +9 -2
index dd94310..a212866 100644
@@ -439,8 +439,11 @@ static void lm_kbd_save(QEMUFile *f, void *opaque)
     qemu_put_byte(f, s->kbd.len);
     qemu_put_buffer(f, s->kbd.fifo, sizeof(s->kbd.fifo));
 
-    for (i = 0; i < sizeof(s->pwm.file); i ++)
+    for (i = 0; i < ARRAY_SIZE(s->pwm.file); i ++)
         qemu_put_be16s(f, &s->pwm.file[i]);
+    /* Padding for compatibility with older records. */
+    for ( ; i < sizeof(s->pwm.file); i++)
+        qemu_put_be16s(f, 0);
     qemu_put_8s(f, &s->pwm.faddr);
     qemu_put_buffer(f, s->pwm.addr, sizeof(s->pwm.addr));
     qemu_put_timer(f, s->pwm.tm[0]);
@@ -451,6 +454,7 @@ static void lm_kbd_save(QEMUFile *f, void *opaque)
 static int lm_kbd_load(QEMUFile *f, void *opaque, int version_id)
 {
     struct lm_kbd_s *s = (struct lm_kbd_s *) opaque;
+    uint16_t pad;
     int i;
 
     i2c_slave_load(f, &s->i2c);
@@ -475,8 +479,11 @@ static int lm_kbd_load(QEMUFile *f, void *opaque, int version_id)
     s->kbd.len = qemu_get_byte(f);
     qemu_get_buffer(f, s->kbd.fifo, sizeof(s->kbd.fifo));
 
-    for (i = 0; i < sizeof(s->pwm.file); i ++)
+    for (i = 0; i < ARRAY_SIZE(s->pwm.file); i ++)
         qemu_get_be16s(f, &s->pwm.file[i]);
+    /* Skip padding. */
+    for ( ; i < sizeof(s->pwm.file); i++)
+        qemu_get_be16(f);
     qemu_get_8s(f, &s->pwm.faddr);
     qemu_get_buffer(f, s->pwm.addr, sizeof(s->pwm.addr));
     qemu_get_timer(f, s->pwm.tm[0]);
Signature · 1 line
1.7.10.4
#36 lore raw

PATCH 4/32 block-vvfat: fix fat_chksum() buffer overrun warning

In reply to Andrew Cooper

Newer GCC versions raise an undefined behaviour warning in fat_chksum() because it overruns the name buffer. However, this is intentional behaviour because the extension array immediately follows.

Refactor this function to avoid the warning and make it clear it's checksumming both parts.

Coverity-ID: 1055738

---
 block-vvfat.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
block-vvfat.c +11 -4
index 9eb676b..345d7be 100644
@@ -504,14 +504,21 @@ static void set_begin_of_direntry(direntry_t* direntry, uint32_t begin)
 
 /* fat functions */
 
+static inline void fat_chksum_part(const char *name, size_t len, uint8_t *chksum)
+{
+    size_t i;
+
+    for(i = 0; i < len; i++)
+	*chksum = (((*chksum&0xfe) >> 1) | ((*chksum & 0x01) ? 0x80 : 0))
+	    + (unsigned char)name[i];
+}
+
 static inline uint8_t fat_chksum(const direntry_t* entry)
 {
     uint8_t chksum=0;
-    int i;
 
-    for(i=0;i<11;i++)
-	chksum=(((chksum&0xfe)>>1)|((chksum&0x01)?0x80:0))
-	    +(unsigned char)entry->name[i];
+    fat_chksum_part(entry->name, ARRAY_SIZE(entry->name), &chksum);
+    fat_chksum_part(entry->extension, ARRAY_SIZE(entry->extension), &chksum);
 
     return chksum;
 }
Signature · 1 line
1.7.10.4
#37 lore raw

PATCH 5/32 usb-linux.c: fix buffer overflow

In reply to Andrew Cooper

From: Jim Paris <[email protected]>

In usb-linux.c:usb_host_handle_control, we pass a 1024-byte buffer and length to the kernel. However, the length was provided by the caller of dev->handle_packet, and is not checked, so the kernel might provide too much data and overflow our buffer.

For example, hw/usb-uhci.c could set the length to 2047. hw/usb-ohci.c looks like it might go up to 4096 or 8192.

This causes a qemu crash, as reported here:
http://www.mail-archive.com/[email protected]/msg18447.html

This patch increases the usb-linux.c buffer size to 2048 to fix the specific device reported, and adds a check to avoid the overflow in any case.

---
 usb-linux.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
usb-linux.c +10 -2
index 5dfed8c..51bac8a 100644
@@ -117,7 +117,7 @@ struct ctrl_struct {
     uint16_t offset;
     uint8_t  state;
     struct   usb_ctrlrequest req;
-    uint8_t  buffer[1024];
+    uint8_t  buffer[2048];
 };
 
 typedef struct USBHostDevice {
@@ -554,6 +554,7 @@ static int usb_host_handle_control(USBHostDevice *s, USBPacket *p)
     struct usbdevfs_urb *urb;
     AsyncURB *aurb;
     int ret, value, index;
+    int buffer_len;
 
     /* 
      * Process certain standard device requests.
@@ -582,6 +583,13 @@ static int usb_host_handle_control(USBHostDevice *s, USBPacket *p)
 
     /* The rest are asynchronous */
 
+    buffer_len = 8 + s->ctrl.len;
+    if (buffer_len > sizeof(s->ctrl.buffer)) {
+	    fprintf(stderr, "husb: ctrl buffer too small (%d > %zu)\n",
+		    buffer_len, sizeof(s->ctrl.buffer));
+	    return USB_RET_STALL;
+    }
+
     aurb = async_alloc();
     aurb->hdev   = s;
     aurb->packet = p;
@@ -598,7 +606,7 @@ static int usb_host_handle_control(USBHostDevice *s, USBPacket *p)
     urb->endpoint = p->devep;
 
     urb->buffer        = &s->ctrl.req;
-    urb->buffer_length = 8 + s->ctrl.len;
+    urb->buffer_length = buffer_len;
 
     urb->usercontext = s;
 
Signature · 1 line
1.7.10.4
#38 lore raw

PATCH 6/32 CVE-2014-8106: cirrus: fix blit region check

In reply to Andrew Cooper

Backport of qemu-upstream:
* bf25983345ca44aec3dd92c57142be45452bd38a
* d3532a0db02296e687711b8cdc7791924efccea0

---
 hw/cirrus_vga.c |   66 +++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 49 insertions(+), 17 deletions(-)
hw/cirrus_vga.c +49 -17
index 11ce212..d3bf4cf 100644
@@ -34,6 +34,8 @@
 #include "qemu-xen.h"
 #include "qemu-log.h"
 
+#include <assert.h>
+
 /*
  * TODO:
  *    - destination write mask support not complete (bits 5..7)
@@ -223,20 +225,6 @@
 
 #define ABS(a) ((signed)(a) > 0 ? a : -a)
 
-#define BLTUNSAFE(s) \
-    ( \
-        ( /* check dst is within bounds */ \
-            (s)->cirrus_blt_height * ABS((s)->cirrus_blt_dstpitch) \
-                + ((s)->cirrus_blt_dstaddr & (s)->cirrus_addr_mask) > \
-                    (s)->vram_size \
-        ) || \
-        ( /* check src is within bounds */ \
-            (s)->cirrus_blt_height * ABS((s)->cirrus_blt_srcpitch) \
-                + ((s)->cirrus_blt_srcaddr & (s)->cirrus_addr_mask) > \
-                    (s)->vram_size \
-        ) \
-    )
-
 struct CirrusVGAState;
 typedef void (*cirrus_bitblt_rop_t) (struct CirrusVGAState *s,
                                      uint8_t * dst, const uint8_t * src,
@@ -315,6 +303,50 @@ static void cirrus_vga_mem_writew(void *opaque, target_phys_addr_t addr, uint32_
  *
  ***************************************/
 
+static bool blit_region_is_unsafe(struct CirrusVGAState *s,
+                                  int32_t pitch, int32_t addr)
+{
+    if (pitch < 0) {
+        int64_t min = addr
+            + ((int64_t)s->cirrus_blt_height-1) * pitch;
+        int32_t max = addr
+            + s->cirrus_blt_width;
+        if (min < 0 || max >= s->vram_size) {
+            return true;
+        }
+    } else {
+        int64_t max = addr
+            + ((int64_t)s->cirrus_blt_height-1) * pitch
+            + s->cirrus_blt_width;
+        if (max >= s->vram_size) {
+            return true;
+        }
+    }
+    return false;
+}
+
+static bool blit_is_unsafe(struct CirrusVGAState *s)
+{
+    /* should be the case, see cirrus_bitblt_start */
+    assert(s->cirrus_blt_width > 0);
+    assert(s->cirrus_blt_height > 0);
+
+    if (s->cirrus_blt_width > CIRRUS_BLTBUFSIZE) {
+        return true;
+    }
+
+    if (blit_region_is_unsafe(s, s->cirrus_blt_dstpitch,
+                              s->cirrus_blt_dstaddr & s->cirrus_addr_mask)) {
+        return true;
+    }
+    if (blit_region_is_unsafe(s, s->cirrus_blt_srcpitch,
+                              s->cirrus_blt_srcaddr & s->cirrus_addr_mask)) {
+        return true;
+    }
+
+    return false;
+}
+
 static void cirrus_bitblt_rop_nop(CirrusVGAState *s,
                                   uint8_t *dst,const uint8_t *src,
                                   int dstpitch,int srcpitch,
@@ -676,7 +708,7 @@ static int cirrus_bitblt_common_patterncopy(CirrusVGAState * s,
 
     dst = s->vram_ptr + (s->cirrus_blt_dstaddr & s->cirrus_addr_mask);
 
-    if (BLTUNSAFE(s))
+    if (blit_is_unsafe(s))
         return 0;
 
     (*s->cirrus_rop) (s, dst, src,
@@ -694,7 +726,7 @@ static int cirrus_bitblt_solidfill(CirrusVGAState *s, int blt_rop)
 {
     cirrus_fill_t rop_func;
 
-    if (BLTUNSAFE(s))
+    if (blit_is_unsafe(s))
         return 0;
     rop_func = cirrus_fill[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1];
     rop_func(s, s->vram_ptr + (s->cirrus_blt_dstaddr & s->cirrus_addr_mask),
@@ -790,7 +822,7 @@ static void cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)
 
 static int cirrus_bitblt_videotovideo_copy(CirrusVGAState * s)
 {
-    if (BLTUNSAFE(s))
+    if (blit_is_unsafe(s))
         return 0;
 
     cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->start_addr,
Signature · 1 line
1.7.10.4
#39 lore raw

PATCH 7/32 CVE-2014-7815: vnc: sanitize bits_per_pixel from the client

In reply to Andrew Cooper

Backport of qemu-upstream:
* e6908bfe8e07f2b452e78e677da1b45b1c0f6829

---
 vnc.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
vnc.c +10 -0
index 7629dfa..7006a34 100644
@@ -1616,6 +1616,16 @@ static void set_pixel_format(VncState *vs,
         return;
     }
 
+    switch (bits_per_pixel) {
+    case 8:
+    case 16:
+    case 32:
+        break;
+    default:
+        vnc_client_error(vs);
+        return;
+    }
+
     vs->clientds = vs->serverds;
     vs->clientds.pf.rmax = red_max;
     count_bits(vs->clientds.pf.rbits, red_max);
Signature · 1 line
1.7.10.4
#40 lore raw

PATCH 8/32 CVE-2014-3615: vbe: rework sanity checks

In reply to Andrew Cooper

Backport of qemu-upstream:
* c1b886c45dc70f247300f549dce9833f3fa2def5

---
 hw/vga.c |  154 ++++++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 95 insertions(+), 59 deletions(-)
hw/vga.c +95 -59
index d0c12aa..e8b1ce0 100644
@@ -521,6 +521,93 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val)
 }
 
 #ifdef CONFIG_BOCHS_VBE
+/*
+ * Sanity check vbe register writes.
+ *
+ * As we don't have a way to signal errors to the guest in the bochs
+ * dispi interface we'll go adjust the registers to the closest valid
+ * value.
+ */
+static void vbe_fixup_regs(VGAState *s)
+{
+    uint16_t *r = s->vbe_regs;
+    uint32_t bits, linelength, maxy, offset;
+
+    if (!(r[VBE_DISPI_INDEX_ENABLE] & VBE_DISPI_ENABLED)) {
+        /* vbe is turned off -- nothing to do */
+        return;
+    }
+
+    /* check depth */
+    switch (r[VBE_DISPI_INDEX_BPP]) {
+    case 4:
+    case 8:
+    case 16:
+    case 24:
+    case 32:
+        bits = r[VBE_DISPI_INDEX_BPP];
+        break;
+    case 15:
+        bits = 16;
+        break;
+    default:
+        bits = r[VBE_DISPI_INDEX_BPP] = 8;
+        break;
+    }
+
+    /* check width */
+    r[VBE_DISPI_INDEX_XRES] &= ~7u;
+    if (r[VBE_DISPI_INDEX_XRES] == 0) {
+        r[VBE_DISPI_INDEX_XRES] = 8;
+    }
+    if (r[VBE_DISPI_INDEX_XRES] > VBE_DISPI_MAX_XRES) {
+        r[VBE_DISPI_INDEX_XRES] = VBE_DISPI_MAX_XRES;
+    }
+    r[VBE_DISPI_INDEX_VIRT_WIDTH] &= ~7u;
+    if (r[VBE_DISPI_INDEX_VIRT_WIDTH] > VBE_DISPI_MAX_XRES) {
+        r[VBE_DISPI_INDEX_VIRT_WIDTH] = VBE_DISPI_MAX_XRES;
+    }
+    if (r[VBE_DISPI_INDEX_VIRT_WIDTH] < r[VBE_DISPI_INDEX_XRES]) {
+        r[VBE_DISPI_INDEX_VIRT_WIDTH] = r[VBE_DISPI_INDEX_XRES];
+    }
+
+    /* check height */
+    linelength = r[VBE_DISPI_INDEX_VIRT_WIDTH] * bits / 8;
+    maxy = s->vram_size / linelength;
+    if (r[VBE_DISPI_INDEX_YRES] == 0) {
+        r[VBE_DISPI_INDEX_YRES] = 1;
+    }
+    if (r[VBE_DISPI_INDEX_YRES] > VBE_DISPI_MAX_YRES) {
+        r[VBE_DISPI_INDEX_YRES] = VBE_DISPI_MAX_YRES;
+    }
+    if (r[VBE_DISPI_INDEX_YRES] > maxy) {
+        r[VBE_DISPI_INDEX_YRES] = maxy;
+    }
+
+    /* check offset */
+    if (r[VBE_DISPI_INDEX_X_OFFSET] > VBE_DISPI_MAX_XRES) {
+        r[VBE_DISPI_INDEX_X_OFFSET] = VBE_DISPI_MAX_XRES;
+    }
+    if (r[VBE_DISPI_INDEX_Y_OFFSET] > VBE_DISPI_MAX_YRES) {
+        r[VBE_DISPI_INDEX_Y_OFFSET] = VBE_DISPI_MAX_YRES;
+    }
+    offset = r[VBE_DISPI_INDEX_X_OFFSET] * bits / 8;
+    offset += r[VBE_DISPI_INDEX_Y_OFFSET] * linelength;
+    if (offset + r[VBE_DISPI_INDEX_YRES] * linelength > s->vram_size) {
+        r[VBE_DISPI_INDEX_Y_OFFSET] = 0;
+        offset = r[VBE_DISPI_INDEX_X_OFFSET] * bits / 8;
+        if (offset + r[VBE_DISPI_INDEX_YRES] * linelength > s->vram_size) {
+            r[VBE_DISPI_INDEX_X_OFFSET] = 0;
+            offset = 0;
+        }
+    }
+
+    /* update vga state */
+    r[VBE_DISPI_INDEX_VIRT_HEIGHT] = maxy;
+    s->vbe_line_offset = linelength;
+    s->vbe_start_addr  = offset / 4;
+}
+
 static uint32_t vbe_ioport_read_index(void *opaque, uint32_t addr)
 {
     VGAState *s = opaque;
@@ -588,22 +675,13 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val)
             }
             break;
         case VBE_DISPI_INDEX_XRES:
-            if ((val <= VBE_DISPI_MAX_XRES) && ((val & 7) == 0)) {
-                s->vbe_regs[s->vbe_index] = val;
-            }
-            break;
         case VBE_DISPI_INDEX_YRES:
-            if (val <= VBE_DISPI_MAX_YRES) {
-                s->vbe_regs[s->vbe_index] = val;
-            }
-            break;
         case VBE_DISPI_INDEX_BPP:
-            if (val == 0)
-                val = 8;
-            if (val == 4 || val == 8 || val == 15 ||
-                val == 16 || val == 24 || val == 32) {
-                s->vbe_regs[s->vbe_index] = val;
-            }
+        case VBE_DISPI_INDEX_VIRT_WIDTH:
+        case VBE_DISPI_INDEX_X_OFFSET:
+        case VBE_DISPI_INDEX_Y_OFFSET:
+            s->vbe_regs[s->vbe_index] = val;
+            vbe_fixup_regs(s);
             break;
         case VBE_DISPI_INDEX_BANK:
             if (s->vbe_regs[VBE_DISPI_INDEX_BPP] == 4) {
@@ -623,19 +701,11 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val)
                      set_vram_mapping(s, s->lfb_addr, s->lfb_end);
                 }
 
-                s->vbe_regs[VBE_DISPI_INDEX_VIRT_WIDTH] =
-                    s->vbe_regs[VBE_DISPI_INDEX_XRES];
-                s->vbe_regs[VBE_DISPI_INDEX_VIRT_HEIGHT] =
-                    s->vbe_regs[VBE_DISPI_INDEX_YRES];
+                s->vbe_regs[VBE_DISPI_INDEX_VIRT_WIDTH] = 0;
                 s->vbe_regs[VBE_DISPI_INDEX_X_OFFSET] = 0;
                 s->vbe_regs[VBE_DISPI_INDEX_Y_OFFSET] = 0;
-
-                if (s->vbe_regs[VBE_DISPI_INDEX_BPP] == 4)
-                    s->vbe_line_offset = s->vbe_regs[VBE_DISPI_INDEX_XRES] >> 1;
-                else
-                    s->vbe_line_offset = s->vbe_regs[VBE_DISPI_INDEX_XRES] *
-                        ((s->vbe_regs[VBE_DISPI_INDEX_BPP] + 7) >> 3);
-                s->vbe_start_addr = 0;
+                s->vbe_regs[VBE_DISPI_INDEX_ENABLE] |= VBE_DISPI_ENABLED;
+                vbe_fixup_regs(s);
 
                 /* clear the screen (should be done in BIOS) */
                 if (!(val & VBE_DISPI_NOCLEARMEM)) {
@@ -677,40 +747,6 @@ static void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val)
             s->dac_8bit = (val & VBE_DISPI_8BIT_DAC) > 0;
             s->vbe_regs[s->vbe_index] = val;
             break;
-        case VBE_DISPI_INDEX_VIRT_WIDTH:
-            {
-                int w, h, line_offset;
-
-                if (val < s->vbe_regs[VBE_DISPI_INDEX_XRES])
-                    return;
-                w = val;
-                if (s->vbe_regs[VBE_DISPI_INDEX_BPP] == 4)
-                    line_offset = w >> 1;
-                else
-                    line_offset = w * ((s->vbe_regs[VBE_DISPI_INDEX_BPP] + 7) >> 3);
-                h = s->vram_size / line_offset;
-                /* XXX: support weird bochs semantics ? */
-                if (h < s->vbe_regs[VBE_DISPI_INDEX_YRES])
-                    return;
-                s->vbe_regs[VBE_DISPI_INDEX_VIRT_WIDTH] = w;
-                s->vbe_regs[VBE_DISPI_INDEX_VIRT_HEIGHT] = h;
-                s->vbe_line_offset = line_offset;
-            }
-            break;
-        case VBE_DISPI_INDEX_X_OFFSET:
-        case VBE_DISPI_INDEX_Y_OFFSET:
-            {
-                int x;
-                s->vbe_regs[s->vbe_index] = val;
-                s->vbe_start_addr = s->vbe_line_offset * s->vbe_regs[VBE_DISPI_INDEX_Y_OFFSET];
-                x = s->vbe_regs[VBE_DISPI_INDEX_X_OFFSET];
-                if (s->vbe_regs[VBE_DISPI_INDEX_BPP] == 4)
-                    s->vbe_start_addr += x >> 1;
-                else
-                    s->vbe_start_addr += x * ((s->vbe_regs[VBE_DISPI_INDEX_BPP] + 7) >> 3);
-                s->vbe_start_addr >>= 2;
-            }
-            break;
         default:
             break;
         }
Signature · 1 line
1.7.10.4
#41 lore raw

PATCH 9/32 cirrus_vga: fix division by 0 for color expansion rop

In reply to Andrew Cooper

From: Aurelien Jarno <[email protected]>

Commit d85d0d3883f5a567fa2969a0396e42e0a662b3fa introduces a regression with Windows ME that leads to a division by 0 and a crash.

It uses the color expansion rop with the source pitch set to 0. This is something allowed, as the manual explicitely says "When the source of color-expand data is display memory, the source pitch is ignored.".

This patch fixes this regression by computing sx, sy and others variables only if they are going to be used later, that is for a plain copy ROP. It basically consists in moving code.

---
 hw/cirrus_vga.c |   70 +++++++++++++++++++++++++++----------------------------
 1 file changed, 35 insertions(+), 35 deletions(-)
hw/cirrus_vga.c +35 -35
index d3bf4cf..e6c3893 100644
@@ -754,46 +754,46 @@ static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState * s)
 
 static void cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)
 {
-    int sx, sy;
-    int dx, dy;
-    int width, height;
-    int depth;
+    int sx = 0, sy = 0;
+    int dx = 0, dy = 0;
+    int depth = 0;
     int notify = 0;
 
-    depth = s->get_bpp((VGAState *)s) / 8;
-    s->get_resolution((VGAState *)s, &width, &height);
-
-    /* extra x, y */
-    sx = (src % ABS(s->cirrus_blt_srcpitch)) / depth;
-    sy = (src / ABS(s->cirrus_blt_srcpitch));
-    dx = (dst % ABS(s->cirrus_blt_dstpitch)) / depth;
-    dy = (dst / ABS(s->cirrus_blt_dstpitch));
-
-    /* normalize width */
-    w /= depth;
-
-    /* if we're doing a backward copy, we have to adjust
-       our x/y to be the upper left corner (instead of the lower
-       right corner) */
-    if (s->cirrus_blt_dstpitch < 0) {
-	sx -= (s->cirrus_blt_width / depth) - 1;
-	dx -= (s->cirrus_blt_width / depth) - 1;
-	sy -= s->cirrus_blt_height - 1;
-	dy -= s->cirrus_blt_height - 1;
-    }
+    /* make sure to only copy if it's a plain copy ROP */
+    if (*s->cirrus_rop == cirrus_bitblt_rop_fwd_src ||
+        *s->cirrus_rop == cirrus_bitblt_rop_bkwd_src) {
+        int width, height;
+
+        depth = s->get_bpp((VGAState *)s) / 8;
+        s->get_resolution((VGAState *)s, &width, &height);
+
+        /* extra x, y */
+        sx = (src % ABS(s->cirrus_blt_srcpitch)) / depth;
+        sy = (src / ABS(s->cirrus_blt_srcpitch));
+        dx = (dst % ABS(s->cirrus_blt_dstpitch)) / depth;
+        dy = (dst / ABS(s->cirrus_blt_dstpitch));
+
+        /* normalize width */
+        w /= depth;
+
+        /* if we're doing a backward copy, we have to adjust
+           our x/y to be the upper left corner (instead of the lower
+           right corner) */
+        if (s->cirrus_blt_dstpitch < 0) {
+            sx -= (s->cirrus_blt_width / depth) - 1;
+            dx -= (s->cirrus_blt_width / depth) - 1;
+            sy -= s->cirrus_blt_height - 1;
+            dy -= s->cirrus_blt_height - 1;
+        }
 
-    /* are we in the visible portion of memory? */
-    if (sx >= 0 && sy >= 0 && dx >= 0 && dy >= 0 &&
-	(sx + w) <= width && (sy + h) <= height &&
-	(dx + w) <= width && (dy + h) <= height) {
-	notify = 1;
+        /* are we in the visible portion of memory? */
+        if (sx >= 0 && sy >= 0 && dx >= 0 && dy >= 0 &&
+            (sx + w) <= width && (sy + h) <= height &&
+            (dx + w) <= width && (dy + h) <= height) {
+            notify = 1;
+        }
     }
 
-    /* make to sure only copy if it's a plain copy ROP */
-    if (*s->cirrus_rop != cirrus_bitblt_rop_fwd_src &&
-	*s->cirrus_rop != cirrus_bitblt_rop_bkwd_src)
-	notify = 0;
-
     /* we have to flush all pending changes so that the copy
        is generated at the appropriate moment in time */
     if (notify)
Signature · 1 line
1.7.10.4
#42 lore raw

PATCH 10/32 ide: cancel dma operations on command abort or error

In reply to Andrew Cooper

From: Chunjie Zhu <[email protected]>

Otherwise, a guest can cause Qemu to reuse an active aio structure.

---
 hw/ide.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/ide.c +5 -2
index 791666b..83e3c70 100644
@@ -919,8 +919,10 @@ static void ide_set_signature(IDEState *s)
     }
 }
 
+static void ide_dma_cancel(BMDMAState *bm);
 static inline void ide_abort_command(IDEState *s)
 {
+    if (s->bmdma) ide_dma_cancel(s->bmdma);
     s->status = READY_STAT | ERR_STAT;
     s->error = ABRT_ERR;
 }
@@ -1098,6 +1100,7 @@ static void dma_buf_commit(IDEState *s, int is_write)
 
 static void ide_dma_error(IDEState *s)
 {
+    if (s->bmdma) ide_dma_cancel(s->bmdma);
     ide_transfer_stop(s);
     s->error = ABRT_ERR;
     s->status = READY_STAT | ERR_STAT;
@@ -1230,7 +1233,7 @@ static void ide_read_dma_cb(void *opaque, int ret)
 	return;
     }
 
-    if (!s->bs) return; /* ouch! (see ide_flush_cb) */
+    if (!s || !s->bs) return; /* ouch! (see ide_dma_error & ide_flush_cb) */
 
     n = s->io_buffer_size >> 9;
     sector_num = ide_get_sector(s);
@@ -1371,7 +1374,7 @@ static void ide_write_dma_cb(void *opaque, int ret)
             return;
     }
 
-    if (!s->bs) return; /* ouch! (see ide_flush_cb) */
+    if (!s || !s->bs) return; /* ouch! (see ide_dma_error & ide_flush_cb) */
 
     n = s->io_buffer_size >> 9;
     sector_num = ide_get_sector(s);
Signature · 1 line
1.7.10.4
#43 lore raw

PATCH 11/32 dma: fix incorrect bh scheduling

In reply to Andrew Cooper

From: Chunjie Zhu <[email protected]>

The following 2 cases should be avoided:

1. DMAAIOCB has been released but continue_after_map_failure schedules a bh for it.
2. Multiple bh calls are schduled on the same DMAAIOCB.

---
 dma-helpers.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
dma-helpers.c +15 -1
index 2a1621b..c9fbbd9 100644
@@ -50,8 +50,14 @@ typedef struct {
     target_phys_addr_t sg_cur_byte;
     QEMUIOVector iov;
     QEMUBH *bh;
+    int in_use;
 } DMAAIOCB;
 
+static void dma_aio_cb_reset(DMAAIOCB *p)
+{
+    p->in_use = 0;
+}
+
 static void dma_bdrv_cb(void *opaque, int ret);
 
 static void reschedule_dma(void *opaque)
@@ -60,6 +66,10 @@ static void reschedule_dma(void *opaque)
 
     qemu_bh_delete(dbs->bh);
     dbs->bh = NULL;
+
+    if (!dbs->in_use)
+        return;
+
     dma_bdrv_cb(opaque, 0);
 }
 
@@ -67,7 +77,8 @@ static void continue_after_map_failure(void *opaque)
 {
     DMAAIOCB *dbs = (DMAAIOCB *)opaque;
 
-    dbs->bh = qemu_bh_new(reschedule_dma, dbs);
+    if (!dbs->bh)
+        dbs->bh = qemu_bh_new(reschedule_dma, dbs);
     qemu_bh_schedule(dbs->bh);
 }
 
@@ -97,6 +108,7 @@ void dma_bdrv_cb(void *opaque, int ret)
         dbs->common.cb(dbs->common.opaque, ret);
         qemu_iovec_destroy(&dbs->iov);
         qemu_aio_release(dbs);
+        dma_aio_cb_reset(dbs);
         return;
     }
 
@@ -129,6 +141,7 @@ void dma_bdrv_cb(void *opaque, int ret)
     if (!dbs->acb) {
         dma_bdrv_unmap(dbs);
         qemu_iovec_destroy(&dbs->iov);
+        dma_aio_cb_reset(dbs);
         return;
     }
 }
@@ -148,6 +161,7 @@ static BlockDriverAIOCB *dma_bdrv_io(
     dbs->sg_cur_byte = 0;
     dbs->is_write = is_write;
     dbs->bh = NULL;
+    dbs->in_use = 1;
     qemu_iovec_init(&dbs->iov, sg->nsg);
     dma_bdrv_cb(dbs, 0);
     if (!dbs->acb) {
Signature · 1 line
1.7.10.4
#44 lore raw

PATCH 12/32 cmdline: Parse -pciemulation before trying to use it

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

---
 vl.c |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
vl.c +9 -9
index d21c3aa..67d9d86 100644
@@ -5952,6 +5952,15 @@ int main(int argc, char **argv, char **envp)
         }
     }
 
+#ifdef CONFIG_PASSTHROUGH
+    for (i = 0; i < nb_pci_emulation; i++) {
+        if (pci_emulation_add(pci_emulation_config_text[i]) < 0) {
+            fprintf(stderr, "Warning: could not add PCI device %s\n",
+                    pci_emulation_config_text[i]);
+        }
+    }
+#endif
+
     machine->init(ram_size, vga_ram_size, boot_devices,
                   kernel_filename, kernel_cmdline, initrd_filename, cpu_model,
 		  direct_pci);
@@ -6068,15 +6077,6 @@ int main(int argc, char **argv, char **envp)
         }
     }
 
-#ifdef CONFIG_PASSTHROUGH
-    for (i = 0; i < nb_pci_emulation; i++) {
-        if (pci_emulation_add(pci_emulation_config_text[i]) < 0) {
-            fprintf(stderr, "Warning: could not add PCI device %s\n",
-                    pci_emulation_config_text[i]);
-        }
-    }
-#endif
-
     for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
         const char *devname = virtio_consoles[i];
         if (virtcon_hds[i] && devname) {
Signature · 1 line
1.7.10.4
#45 lore raw

PATCH 13/32 smbios: Don't allocate smbus eeprom buffer

In reply to Andrew Cooper

smbus_eeprom_device_init() has been disabled since 2007. The #define turns the actual function call into a comma expression with no effect.

Removing the leaked allocation also makes Valgrind happier.

Coverity-ID: 1090387

---
 hw/pc.c |   12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
hw/pc.c +1 -11
index 3e33694..7359338 100644
@@ -79,7 +79,6 @@ static void xen_relocator_hook(target_phys_addr_t *prot_addr_upd,
                                uint16_t protocol,
 			       const uint8_t header[], int kernel_size,
 			       target_phys_addr_t real_addr, int real_size);
-#define smbus_eeprom_device_init (void)
 
 static void ioport80_write(void *opaque, uint32_t addr, uint32_t data)
 {
@@ -1135,17 +1134,8 @@ vga_bios_error:
     }
 
     if (pci_enabled && acpi_enabled) {
-        uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
-        i2c_bus *smbus;
-
         /* TODO: Populate SPD eeprom data.  */
-        smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100, i8259[9]);
-
-	if (smbus) {
-	    for (i = 0; i < 8; i++) {
-		smbus_eeprom_device_init(smbus, 0x50 + i, eeprom_buf + (i * 256));
-	    }
-        }
+        piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100, i8259[9]);
     }
 
     if (i440fx_state) {
Signature · 1 line
1.7.10.4
#46 lore raw

PATCH 14/32 pic: Don't allocate irq buffers

In reply to Andrew Cooper

i8259_init() doesn't inspect its argument at all, causing the allocation to be leaked and never used.

---
 hw/pc.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/pc.c +1 -3
index 7359338..09b4af4 100644
@@ -801,7 +801,6 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
     PCIBus *pci_bus;
     int piix3_devfn = -1;
     CPUState *env;
-    qemu_irq *cpu_irq;
     qemu_irq *i8259;
     int index;
     BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
@@ -970,8 +969,7 @@ vga_bios_error:
 
     bochs_bios_init();
 
-    cpu_irq = qemu_allocate_irqs(pic_irq_request, NULL, 1);
-    i8259 = i8259_init(cpu_irq[0]);
+    i8259 = i8259_init(NULL);
     ferr_irq = i8259[13];
 
     if (pci_enabled) {
Signature · 1 line
1.7.10.4
#47 lore raw

PATCH 15/32 signal: Don't use uninitalised sival_ptr

In reply to Andrew Cooper

In 64bit builds, setting sival_int to 0 doesn't clear the upper half of the sival_ptr pointer. Valgrind does not like this.

---
 vl.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
vl.c +1 -2
index 67d9d86..c864e7d 100644
@@ -1568,7 +1568,7 @@ static void rtc_stop_timer(struct qemu_alarm_timer *t)
 
 static int dynticks_start_timer(struct qemu_alarm_timer *t)
 {
-    struct sigevent ev;
+    struct sigevent ev = { { 0 } };
     timer_t host_timer;
     struct sigaction act;
 
@@ -1578,7 +1578,6 @@ static int dynticks_start_timer(struct qemu_alarm_timer *t)
 
     sigaction(SIGALRM, &act, NULL);
 
-    ev.sigev_value.sival_int = 0;
     ev.sigev_notify = SIGEV_SIGNAL;
     ev.sigev_signo = SIGALRM;
 
Signature · 1 line
1.7.10.4
#48 lore raw

PATCH 16/32 hw/msmouse.c: Fix deref_after_free and double free

In reply to Andrew Cooper

From: Yunlei Ding <[email protected]>

msmouse_chr_close is only pointed by chr->chr_close in qemu_chr_close function. After calling chr->chr_close, chr will be freed. So we don't need to free it again here.

(defect not identified by Coverity Scan)

---
 hw/msmouse.c |    1 -
 1 file changed, 1 deletion(-)
hw/msmouse.c +0 -1
index 69356a5..2d2703b 100644
@@ -61,7 +61,6 @@ static int msmouse_chr_write (struct CharDriverState *s, const uint8_t *buf, int
 
 static void msmouse_chr_close (struct CharDriverState *chr)
 {
-    qemu_free (chr);
 }
 
 CharDriverState *qemu_chr_open_msmouse(void)
Signature · 1 line
1.7.10.4
#49 lore raw

PATCH 17/32 readline: fix memory corruption when adding history

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

idx can be down to 0, so TERM_MAX_CMDS-idx+1 could be TERM_MAX_CMDS+1, which exceeds the size of term_history.

Coverity-ID: 1055739

---
 readline.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
readline.c +1 -1
index 8572841..4b68726 100644
@@ -267,7 +267,7 @@ static void term_hist_add(const char *cmdline)
 	    new_entry = hist_entry;
 	    /* Put this entry at the end of history */
 	    memmove(&term_history[idx], &term_history[idx + 1],
-		    (TERM_MAX_CMDS - idx + 1) * sizeof(char *));
+		    (TERM_MAX_CMDS - (idx + 1)) * sizeof(char *));
 	    term_history[TERM_MAX_CMDS - 1] = NULL;
 	    for (; idx < TERM_MAX_CMDS; idx++) {
 		if (term_history[idx] == NULL)
Signature · 1 line
1.7.10.4
#50 lore raw

PATCH 18/32 block-cow: don't close cow_fd twice on error

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

Coverity-ID: 1056200

---
 block-cow.c |    1 -
 1 file changed, 1 deletion(-)
block-cow.c +0 -1
index 777d8a5..9ad0a32 100644
@@ -224,7 +224,6 @@ static int cow_create(const char *filename, int64_t image_sectors,
 
         fd = open(image_filename, O_RDONLY | O_BINARY);
         if (fd < 0) {
-            close(cow_fd);
             goto mtime_fail;
         }
         if (fstat(fd, &st) != 0) {
Signature · 1 line
1.7.10.4
#51 lore raw

PATCH 19/32 console: Avoid overrunning the dmask arrays

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

The valide range of font_data should be [0, 0xFF].

(defects not identified by Coverity Scan)

---
 console.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
console.c +5 -4
index 9984d6f..d4f1ad0 100644
@@ -421,7 +421,8 @@ static void vga_putcharxy(DisplayState *ds, int x, int y, int ch,
 {
     uint8_t *d;
     const uint8_t *font_ptr;
-    unsigned int font_data, linesize, xorcol, bpp;
+    uint8_t font_data;
+    unsigned int linesize, xorcol, bpp;
     int i;
     unsigned int fgcol, bgcol;
 
@@ -450,7 +451,7 @@ static void vga_putcharxy(DisplayState *ds, int x, int y, int ch,
             font_data = *font_ptr++;
             if (t_attrib->uline
                 && ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) {
-                font_data = 0xFFFF;
+                font_data = 0xFF;
             }
             ((uint32_t *)d)[0] = (dmask16[(font_data >> 4)] & xorcol) ^ bgcol;
             ((uint32_t *)d)[1] = (dmask16[(font_data >> 0) & 0xf] & xorcol) ^ bgcol;
@@ -463,7 +464,7 @@ static void vga_putcharxy(DisplayState *ds, int x, int y, int ch,
             font_data = *font_ptr++;
             if (t_attrib->uline
                 && ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) {
-                font_data = 0xFFFF;
+                font_data = 0xFF;
             }
             ((uint32_t *)d)[0] = (dmask4[(font_data >> 6)] & xorcol) ^ bgcol;
             ((uint32_t *)d)[1] = (dmask4[(font_data >> 4) & 3] & xorcol) ^ bgcol;
@@ -476,7 +477,7 @@ static void vga_putcharxy(DisplayState *ds, int x, int y, int ch,
         for(i = 0; i < FONT_HEIGHT; i++) {
             font_data = *font_ptr++;
             if (t_attrib->uline && ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) {
-                font_data = 0xFFFF;
+                font_data = 0xFF;
             }
             ((uint32_t *)d)[0] = (-((font_data >> 7)) & xorcol) ^ bgcol;
             ((uint32_t *)d)[1] = (-((font_data >> 6) & 1) & xorcol) ^ bgcol;
Signature · 1 line
1.7.10.4
#52 lore raw

PATCH 20/32 hw/device-hotplug: fix test of drive_add() return

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

drive_opt_idx could be -1 in case error occurs inside drive_add, so the error check should be "if (drive_opt_idx < 0)" instead of original
"if (!drive_opt_idx)".

Coverity-ID: 1055574

---
 hw/device-hotplug.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/device-hotplug.c +1 -1
index 3bdc048..97d3529 100644
@@ -34,7 +34,7 @@ int add_init_drive(const char *opts)
     int ret = -1;
 
     drive_opt_idx = drive_add(NULL, "%s", opts);
-    if (!drive_opt_idx)
+    if (drive_opt_idx < 0)
         return ret;
 
     drive_idx = drive_init(&drives_opt[drive_opt_idx], 0, current_machine);
Signature · 1 line
1.7.10.4
#53 lore raw

PATCH 21/32 qemu-char: fix memory leak in qemu_char_open_pty()

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

The momery pointed by s and chr could be leaked if openpty return a value less then 0.

Coverity-IDs: 1055926 1055927

---
 qemu-char.c |    2 ++
 1 file changed, 2 insertions(+)
qemu-char.c +2 -0
index 324ed16..f62a6af 100644
@@ -932,6 +932,8 @@ static CharDriverState *qemu_chr_open_pty(void)
     s = qemu_mallocz(sizeof(PtyCharDriver));
 
     if (openpty(&s->fd, &slave_fd, pty_name, NULL, NULL) < 0) {
+        qemu_free(s);
+        qemu_free(chr);
         return NULL;
     }
 
Signature · 1 line
1.7.10.4
#54 lore raw

PATCH 22/32 hw/ide: fix memory leak from qemu_allocate_irqs()

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

qemu_allocate_irqs would return an array of irqs, not store the allocated array pointer, and subsequently leak it.

(defects not identified by Coverity Scan)

---
 hw/ide.c |    2 +-
 hw/irq.c |   18 +++++++++++++++++-
 hw/irq.h |    4 ++++
 3 files changed, 22 insertions(+), 2 deletions(-)
hw/ide.c +1 -1
index 83e3c70..f372b7b 100644
@@ -4769,7 +4769,7 @@ struct pcmcia_card_s *dscm1xxxx_init(BlockDriverState *bdrv)
     md->card.cis = dscm1xxxx_cis;
     md->card.cis_len = sizeof(dscm1xxxx_cis);
 
-    ide_init2(md->ide, bdrv, 0, qemu_allocate_irqs(md_set_irq, md, 1)[0]);
+    ide_init2(md->ide, bdrv, 0, qemu_allocate_irq(md_set_irq, md));
     md->ide->is_cf = 1;
     md->ide->mdata_size = METADATA_SIZE;
     md->ide->mdata_storage = (uint8_t *) qemu_mallocz(METADATA_SIZE);
hw/irq.c +17 -1
index 7703f62..c7c4864 100644
@@ -38,6 +38,22 @@ void qemu_set_irq(qemu_irq irq, int level)
     irq->handler(irq->opaque, irq->n, level);
 }
 
+qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque)
+{
+    struct IRQState *irq;
+
+    irq = (struct IRQState *)qemu_mallocz(sizeof(struct IRQState));
+    irq->handler = handler;
+    irq->opaque = opaque;
+    irq->n = 0;
+    return irq;
+}
+
+void qemu_free_irq(qemu_irq irq)
+{
+    qemu_free(irq);
+}
+
 qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n)
 {
     qemu_irq *s;
@@ -73,5 +89,5 @@ qemu_irq qemu_irq_invert(qemu_irq irq)
 {
     /* The default state for IRQs is low, so raise the output now.  */
     qemu_irq_raise(irq);
-    return qemu_allocate_irqs(qemu_notirq, irq, 1)[0];
+    return qemu_allocate_irq(qemu_notirq, irq);
 }
hw/irq.h +4 -0
index 5daae44..da34ae3 100644
@@ -25,6 +25,10 @@ static inline void qemu_irq_pulse(qemu_irq irq)
     qemu_set_irq(irq, 0);
 }
 
+/* Returns one IRQ.  */
+qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque);
+void qemu_free_irq(qemu_irq irq);
+
 /* Returns an array of N IRQs.  */
 qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n);
 void qemu_free_irqs(qemu_irq *s);
Signature · 1 line
1.7.10.4
#55 lore raw

PATCH 23/32 net: don't leak an fd after an error

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

fd will be leaked if launch_script failed.

Coverity-ID: 1055925

---
 net.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net.c +3 -1
index 720027c..f3887a7 100644
@@ -1049,8 +1049,10 @@ static int net_tap_init(VLANState *vlan, const char *model,
     if (!setup_script || !strcmp(setup_script, "no"))
         setup_script = "";
     if (setup_script[0] != '\0') {
-	if (launch_script(setup_script, ifname, script_arg, fd))
+	if (launch_script(setup_script, ifname, script_arg, fd)) {
+	    close(fd);
 	    return -1;
+	}
     }
     s = net_tap_fd_init(vlan, model, name, fd);
     if (!s)
Signature · 1 line
1.7.10.4
#56 lore raw

PATCH 24/32 net: Fix memory/handle leaks in net_socket_listen_init()

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

fd and s could be leaked in case bind/listen failed.

Coverity-IDs: 1055923 1055924

---
 net.c |    5 +++++
 1 file changed, 5 insertions(+)
net.c +5 -0
index f3887a7..33460d8 100644
@@ -1460,6 +1460,7 @@ static int net_socket_listen_init(VLANState *vlan,
     fd = socket(PF_INET, SOCK_STREAM, 0);
     if (fd < 0) {
         perror("socket");
+        qemu_free(s);
         return -1;
     }
     socket_set_nonblock(fd);
@@ -1471,11 +1472,15 @@ static int net_socket_listen_init(VLANState *vlan,
     ret = bind(fd, (struct sockaddr *)&saddr, sizeof(saddr));
     if (ret < 0) {
         perror("bind");
+        closesocket(fd);
+        qemu_free(s);
         return -1;
     }
     ret = listen(fd, 0);
     if (ret < 0) {
         perror("listen");
+        closesocket(fd);
+        qemu_free(s);
         return -1;
     }
     s->vlan = vlan;
Signature · 1 line
1.7.10.4
#57 lore raw

PATCH 25/32 block-vvfat: fix memory/handle leaks in commit_one_file()

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

Some handles and memory in commit_one_file are going to be leaked if certain function calls failed.

Coverity-IDs: 1055918 1055919

---
 block-vvfat.c |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
block-vvfat.c +14 -3
index 345d7be..ec3363c 100644
@@ -2229,11 +2229,15 @@ static int commit_one_file(BDRVVVFATState* s,
     if (fd < 0) {
 	fprintf(stderr, "Could not open %s... (%s, %d)\n", mapping->path,
 		strerror(errno), errno);
+	qemu_free(cluster);
 	return fd;
     }
     if (offset > 0)
-	if (lseek(fd, offset, SEEK_SET) != offset)
+	if (lseek(fd, offset, SEEK_SET) != offset) {
+	    close(fd);
+	    qemu_free(cluster);
 	    return -3;
+	}
 
     while (offset < size) {
 	uint32_t c1;
@@ -2249,11 +2253,17 @@ static int commit_one_file(BDRVVVFATState* s,
 	ret = vvfat_read(s->bs, cluster2sector(s, c),
 	    (uint8_t*)cluster, (rest_size + 0x1ff) / 0x200);
 
-	if (ret < 0)
+	if (ret < 0) {
+	    close(fd);
+	    qemu_free(cluster);
 	    return ret;
+	}
 
-	if (qemu_write_ok(fd, cluster, rest_size) < 0)
+	if (qemu_write_ok(fd, cluster, rest_size) < 0) {
+	    close(fd);
+	    qemu_free(cluster);
 	    return -2;
+	}
 
 	offset += rest_size;
 	c = c1;
@@ -2261,6 +2271,7 @@ static int commit_one_file(BDRVVVFATState* s,
 
     ftruncate(fd, size);
     close(fd);
+    qemu_free(cluster);
 
     return commit_mappings(s, first_cluster, dir_index);
 }
Signature · 1 line
1.7.10.4
#58 lore raw

PATCH 26/32 block-vvfat: fix memory leak in check_directory_consistency()

In reply to Andrew Cooper

From: Kaifeng Zhu <[email protected]>

Memory pointed by cluster leaks in error handling code.

Coverity-ID: 1055917

---
 block-vvfat.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block-vvfat.c +1 -1
index ec3363c..6cd57a2 100644
@@ -1769,7 +1769,7 @@ static int check_directory_consistency(BDRVVVFATState *s,
 
 	if (s->used_clusters[cluster_num] & USED_ANY) {
 	    fprintf(stderr, "cluster %d used more than once\n", (int)cluster_num);
-	    return 0;
+	    goto fail;
 	}
 	s->used_clusters[cluster_num] = USED_DIRECTORY;
 
Signature · 1 line
1.7.10.4
#59 lore raw

PATCH 27/32 virtio-blk: correctly link new request in virtio_blk_load()

In reply to Andrew Cooper

From: Yunlei Ding <[email protected]>

s->rq should be set with req instead of req-next.

Coverity-ID: 1055910

---
 hw/virtio-blk.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio-blk.c +1 -1
index fcf893a..f3a81e3 100644
@@ -288,7 +288,7 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
         VirtIOBlockReq *req = virtio_blk_alloc_request(s);
         qemu_get_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem));
         req->next = s->rq;
-        s->rq = req->next;
+        s->rq = req;
     }
 
     return 0;
Signature · 1 line
1.7.10.4
#60 lore raw

PATCH 28/32 net: initialize parameters before use in net_socket_fd_init_dgram()

In reply to Andrew Cooper

From: Yunlei Ding <[email protected]>

Coverity-IDs: 1005339 1005340

---
 net.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net.c +3 -1
index 33460d8..8aba3c2 100644
@@ -1316,9 +1316,11 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
 {
     struct sockaddr_in saddr;
     int newfd;
-    socklen_t saddr_len;
+    socklen_t saddr_len = sizeof(saddr);
     NetSocketState *s;
 
+    memset(&saddr, 0, sizeof(saddr));
+
     /* fd passed: multicast: "learn" dgram_dst address from bound address and save it
      * Because this may be "shared" socket from a "master" process, datagrams would be recv()
      * by ONLY ONE process: we must "clone" this dgram socket --jjo
Signature · 1 line
1.7.10.4
#61 lore raw

PATCH 29/32 ide: don't leak irq array in pci_cmd646_ide_init()

In reply to Andrew Cooper

From: Yunlei Ding <[email protected]>

Call qemu_allocate_irq() twice instead of qemu_allocate_irqs to allocate memory.

(defects not identified by Coverity Scan)

---
 hw/ide.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
hw/ide.c +2 -4
index f372b7b..e7b9f24 100644
@@ -3652,7 +3652,6 @@ void pci_cmd646_ide_init(PCIBus *bus, BlockDriverState **hd_table,
     PCIIDEState *d;
     uint8_t *pci_conf;
     int i;
-    qemu_irq *irq;
 
     d = (PCIIDEState *)pci_register_device(bus, "CMD646 IDE",
                                            sizeof(PCIIDEState),
@@ -3694,9 +3693,8 @@ void pci_cmd646_ide_init(PCIBus *bus, BlockDriverState **hd_table,
     for(i = 0; i < 4; i++)
         d->ide_if[i].pci_dev = (PCIDevice *)d;
 
-    irq = qemu_allocate_irqs(cmd646_set_irq, d, 2);
-    ide_init2(&d->ide_if[0], hd_table[0], hd_table[1], irq[0]);
-    ide_init2(&d->ide_if[2], hd_table[2], hd_table[3], irq[1]);
+    ide_init2(&d->ide_if[0], hd_table[0], hd_table[1], qemu_allocate_irq(cmd646_set_irq, d));
+    ide_init2(&d->ide_if[2], hd_table[2], hd_table[3], qemu_allocate_irq(cmd646_set_irq, d));
 
     register_savevm("ide", 0, 3, pci_ide_save, pci_ide_load, d);
     qemu_register_reset(cmd646_reset, d);
Signature · 1 line
1.7.10.4
#62 lore raw

PATCH 30/32 block-nbd: close sock in nbd_open() error path

In reply to Andrew Cooper

From: Yunlei Ding <[email protected]>

Close sock handle before return.

Coverity-ID: 1055914

---
 block-nbd.c |    3 +++
 1 file changed, 3 insertions(+)
block-nbd.c +3 -0
index dc63183..e2c90eb 100644
@@ -88,7 +88,10 @@ static int nbd_open(BlockDriverState *bs, const char* filename, int flags)
 
     ret = nbd_receive_negotiate(sock, &size, &blocksize);
     if (ret == -1)
+    {
+        close(sock);
         return -errno;
+    }
 
     s->sock = sock;
     s->size = size;
Signature · 1 line
1.7.10.4
#63 lore raw

PATCH 31/32 block-raw-posix: Fix memory leak in posix_aio_init()

In reply to Andrew Cooper

From: Yunlei Ding <[email protected]>

Free allocated memory s before return.

Coverity-ID: 1055915

---
 block-raw-posix.c |    1 +
 1 file changed, 1 insertion(+)
block-raw-posix.c +1 -0
index 795cd5b..8a1baa8 100644
@@ -602,6 +602,7 @@ static int posix_aio_init(void)
     s->first_aio = NULL;
     if (pipe(fds) == -1) {
         fprintf(stderr, "failed to create pipe\n");
+        qemu_free(s);
         return -errno;
     }
 
Signature · 1 line
1.7.10.4
#64 lore raw

PATCH 32/32 block-vvfat: fix resource leaks in read_directory()

In reply to Andrew Cooper

From: Yunlei Ding <[email protected]>

Coverity-IDs: 1055920 1055921

---
 block-vvfat.c |    3 +++
 1 file changed, 3 insertions(+)
block-vvfat.c +3 -0
index 6cd57a2..ff5c8bf 100644
@@ -760,6 +760,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)
         if (st.st_size > 0x7fffffff) {
 	    fprintf(stderr, "File %s is larger than 2GB\n", buffer);
 	    free(buffer);
+            closedir(dir);
 	    return -2;
         }
 	direntry->size=cpu_to_le32(S_ISDIR(st.st_mode)?0:st.st_size);
@@ -787,6 +788,8 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)
 	    s->current_mapping->read_only =
 		(st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) == 0;
 	}
+        else
+            qemu_free(buffer);
     }
     closedir(dir);
 
Signature · 1 line
1.7.10.4
Acked-by on the v1 series
#65 lore raw
In reply to Andrew Cooper

Andrew Cooper writes ("[PATCH 00/32] Qemu Traditional bugfixes"):

Quoted 2 lines

Here is a set of bugfixes against Qemu Traditional, which are from the XenServer patch queue.

Thanks for this, and for chasing me about it. For all 32 patches[1]:

(This is for the record here on the list; I don't expect you to resend or rebase with that added to each patch.)

I am going to hold off pushing this because of the plan to unify the qemu git trees next week.

Ian.

[1] as rebased by Andrew as
git://xenbits.xen.org/people/andrewcoop/qemu-traditional.git#xs-fixes-v2