From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:38437) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USsHT-0004hH-7t for qemu-devel@nongnu.org; Thu, 18 Apr 2013 13:05:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1USsHR-00063o-VC for qemu-devel@nongnu.org; Thu, 18 Apr 2013 13:05:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60445) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USsHR-00063j-LJ for qemu-devel@nongnu.org; Thu, 18 Apr 2013 13:05:53 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3IH5rHB001793 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 18 Apr 2013 13:05:53 -0400 Date: Thu, 18 Apr 2013 13:05:52 -0400 From: Luiz Capitulino Message-ID: <20130418130552.2d319e91@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] 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 Cc: mkletzan@redhat.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. What the BALLOON_CHANGE QMP event, 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 --- 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