From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:37897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTAm2-0004y3-1U for qemu-devel@nongnu.org; Fri, 19 Apr 2013 08:50:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UTAm0-00043z-Pe for qemu-devel@nongnu.org; Fri, 19 Apr 2013 08:50:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37196) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTAm0-00043n-I9 for qemu-devel@nongnu.org; Fri, 19 Apr 2013 08:50:40 -0400 From: Luiz Capitulino Date: Fri, 19 Apr 2013 08:50:33 -0400 Message-Id: <1366375833-995-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1366375833-995-1-git-send-email-lcapitulino@redhat.com> References: <1366375833-995-1-git-send-email-lcapitulino@redhat.com> Subject: [Qemu-devel] [PULL 2/2] virtio-balloon: fix integer overflow in BALLOON_CHANGE QMP event List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com 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 Reviewed-by: Eric Blake --- hw/virtio/virtio-balloon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index c2c446e..76e32ce 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -275,7 +275,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)); } } -- 1.8.1.4