From patchwork Sat Jul 7 13:37:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 169596 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5DD672C0089 for ; Sat, 7 Jul 2012 23:38:21 +1000 (EST) Received: from localhost ([::1]:42264 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SnVDG-000122-6v for incoming@patchwork.ozlabs.org; Sat, 07 Jul 2012 09:38:18 -0400 Received: from eggs.gnu.org ([208.118.235.92]:59233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SnVD9-00011j-Cd for qemu-devel@nongnu.org; Sat, 07 Jul 2012 09:38:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SnVD7-0004po-C7 for qemu-devel@nongnu.org; Sat, 07 Jul 2012 09:38:10 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:47202) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SnVD7-0004pa-4f for qemu-devel@nongnu.org; Sat, 07 Jul 2012 09:38:09 -0400 Received: from [192.168.88.2] (mjt.vpn.tls.msk.ru [192.168.177.99]) by isrv.corpit.ru (Postfix) with ESMTP id 93D0EA04AF; Sat, 7 Jul 2012 17:37:59 +0400 (MSK) Message-ID: <4FF83BB6.6080304@msgid.tls.msk.ru> Date: Sat, 07 Jul 2012 17:37:58 +0400 From: Michael Tokarev Organization: Telecom Service, JSC User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:10.0.4) Gecko/20120510 Icedove/10.0.4 MIME-Version: 1.0 To: qemu-devel , "Michael S. Tsirkin" X-Enigmail-Version: 1.4.1 OpenPGP: id=804465C5 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 86.62.121.231 Subject: [Qemu-devel] CVE-2011-2212: has it been actually fixed? 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 I come across a patch in ububtu qemu-kvm package, this: From: Nelson Elhage Date: Thu, 19 May 2011 13:23:17 -0400 Subject: [PATCH] virtqueue: Sanity-check the length of indirect descriptors. We were previously allowing arbitrarily-long descriptors, which could lead to a buffer overflow in the qemu-kvm process. But this one - apparently - fixes a different codepath, no? Thanks, /mjt Index: qemu-kvm-1.1~rc+dfsg/hw/virtio.c =================================================================== --- qemu-kvm-1.1~rc+dfsg.orig/hw/virtio.c 2012-06-01 01:19:22.000000000 +0000 +++ qemu-kvm-1.1~rc+dfsg/hw/virtio.c 2012-06-12 19:31:02.336250076 +0000 @@ -370,6 +370,11 @@ max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc); num_bufs = i = 0; desc_pa = vring_desc_addr(desc_pa, i); + + if (max > VIRTQUEUE_MAX_SIZE) { + error_report("Too-large indirect descriptor"); + exit(1); + } } do { @@ -443,6 +448,11 @@ max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc); desc_pa = vring_desc_addr(desc_pa, i); i = 0; + + if (max > VIRTQUEUE_MAX_SIZE) { + error_report("Too-large indirect descriptor"); + exit(1); + } } /* Collect all the descriptors */ And I wonder if it is still needed. The mentioned CVE-2011-2212 has been fixed before 0.15, by the following: commit c8eac1cfa1e9104a658b4614ada758861b8d823a Author: Michael S. Tsirkin Date: Mon Jun 20 13:42:27 2011 +0300 virtio: fix indirect descriptor buffer overflow We were previously allowing arbitrarily-long indirect descriptors, which could lead to a buffer overflow in qemu-kvm process. CVE-2011-2212 Signed-off-by: Michael S. Tsirkin diff --git a/hw/virtio.c b/hw/virtio.c index cc47a06..a8f4940 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -449,9 +449,17 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) struct iovec *sg; if (vring_desc_flags(desc_pa, i) & VRING_DESC_F_WRITE) { + if (elem->in_num >= ARRAY_SIZE(elem->in_sg)) { + error_report("Too many write descriptors in indirect table"); + exit(1); + } elem->in_addr[elem->in_num] = vring_desc_addr(desc_pa, i); sg = &elem->in_sg[elem->in_num++]; } else { + if (elem->out_num >= ARRAY_SIZE(elem->out_sg)) { + error_report("Too many read descriptors in indirect table"); + exit(1); + } elem->out_addr[elem->out_num] = vring_desc_addr(desc_pa, i); sg = &elem->out_sg[elem->out_num++]; }