From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhPXd-00076c-9Q for qemu-devel@nongnu.org; Mon, 05 May 2014 16:31:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WhPXW-0000vX-Fl for qemu-devel@nongnu.org; Mon, 05 May 2014 16:31:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10588) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhPXW-0000vJ-84 for qemu-devel@nongnu.org; Mon, 05 May 2014 16:31:06 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s45KV5Fo021414 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 5 May 2014 16:31:05 -0400 From: Juan Quintela Date: Mon, 5 May 2014 22:30:11 +0200 Message-Id: <1399321834-31310-14-git-send-email-quintela@redhat.com> In-Reply-To: <1399321834-31310-1-git-send-email-quintela@redhat.com> References: <1399321834-31310-1-git-send-email-quintela@redhat.com> Subject: [Qemu-devel] [PATCH 13/36] virtio: validate num_sg when mapping List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Amit Shah , "Michael S. Tsirkin" From: "Michael S. Tsirkin" CVE-2013-4535 CVE-2013-4536 Both virtio-block and virtio-serial read, VirtQueueElements are read in as buffers, and passed to virtqueue_map_sg(), where num_sg is taken from the wire and can force writes to indicies beyond VIRTQUEUE_MAX_SIZE. To fix, validate num_sg. Reported-by: Michael Roth Signed-off-by: Michael S. Tsirkin Cc: Amit Shah Signed-off-by: Juan Quintela --- hw/virtio/virtio.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 0072542..a70169a 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -430,6 +430,12 @@ void virtqueue_map_sg(struct iovec *sg, hwaddr *addr, unsigned int i; hwaddr len; + if (num_sg >= VIRTQUEUE_MAX_SIZE) { + error_report("virtio: map attempt out of bounds: %zd > %d", + num_sg, VIRTQUEUE_MAX_SIZE); + exit(1); + } + for (i = 0; i < num_sg; i++) { len = sg[i].iov_len; sg[i].iov_base = cpu_physical_memory_map(addr[i], &len, is_write); -- 1.9.0