summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuiz Capitulino <lcapitulino@redhat.com>2013-04-18 11:53:32 -0400
committerMichael Roth <mdroth@linux.vnet.ibm.com>2013-05-17 12:02:18 -0500
commit45bbe1fa897937e38d7db18ce214c28b01bab0ec (patch)
tree935ebadc3bb9b543b92034209f5fd28a0761934c
parent06efdc4f4d5ba24016c33ff0690218027c0c785f (diff)
downloadqemu-45bbe1fa897937e38d7db18ce214c28b01bab0ec.tar.gz
virtio-balloon: fix integer overflow in BALLOON_CHANGE QMP event
Because dev->actual is uint32_t, the expression 'dev->actual << VIRTIO_BALLOON_PFN_SHIFT' is truncated to 32 bits. This overflows when dev->actual >= 1048576. To reproduce: 1. Start a VM with a QMP socket and 5G of RAM 2. Connect to the QMP socket, negotiate capabilities and issue: { "execute":"balloon", "arguments": { "value": 1073741824 } } 3. Watch for BALLOON_CHANGE QMP events, the last one will incorretly be: { "timestamp": { "seconds": 1366228965, "microseconds": 245466 }, "event": "BALLOON_CHANGE", "data": { "actual": 5368709120 } } To fix it this commit casts it to ram_addr_t, which is ram_size's type. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> (cherry picked from commit dcc6ceffc066745777960a1f0d32f3a555924f65) Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
-rw-r--r--hw/virtio-balloon.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index c0a790264c..f841e81601 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -291,7 +291,7 @@ static void virtio_balloon_set_config(VirtIODevice *vdev,
dev->actual = le32_to_cpu(config.actual);
if (dev->actual != oldactual) {
qemu_balloon_changed(ram_size -
- (dev->actual << VIRTIO_BALLOON_PFN_SHIFT));
+ ((ram_addr_t) dev->actual << VIRTIO_BALLOON_PFN_SHIFT));
}
}