From patchwork Tue Dec 3 16:29:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 296259 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5890B2C008E for ; Wed, 4 Dec 2013 04:39:55 +1100 (EST) Received: from localhost ([::1]:43412 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VnssJ-0003Nw-Oc for incoming@patchwork.ozlabs.org; Tue, 03 Dec 2013 11:31:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VnsnA-00069R-6u for qemu-devel@nongnu.org; Tue, 03 Dec 2013 11:25:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vnsn3-0006pH-OY for qemu-devel@nongnu.org; Tue, 03 Dec 2013 11:25:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:5351) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vnsn3-0006pB-GJ; Tue, 03 Dec 2013 11:25:37 -0500 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 rB3GPY17014051 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 3 Dec 2013 11:25:34 -0500 Received: from redhat.com ([10.35.213.190]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id rB3GPVRj010456; Tue, 3 Dec 2013 11:25:32 -0500 Date: Tue, 3 Dec 2013 18:29:04 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1386087086-3691-17-git-send-email-mst@redhat.com> References: <1386087086-3691-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1386087086-3691-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-stable@nongnu.org, Anthony Liguori , Michael Roth Subject: [Qemu-devel] [PATCH 16/23] virtio: validate num_sg when mapping X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- hw/virtio/virtio.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index b3c38f7..edc2ce7 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -427,6 +427,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: %d > %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);