From patchwork Thu Sep 15 11:34:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 9333247 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4AC0B6077A for ; Thu, 15 Sep 2016 11:35:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F2EB295EC for ; Thu, 15 Sep 2016 11:35:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21EF4295F0; Thu, 15 Sep 2016 11:35:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DEBF7295EC for ; Thu, 15 Sep 2016 11:35:22 +0000 (UTC) Received: from localhost ([::1]:33673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkUws-00009h-0w for patchwork-qemu-devel@patchwork.kernel.org; Thu, 15 Sep 2016 07:35:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33383) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkUwR-00007d-AH for qemu-devel@nongnu.org; Thu, 15 Sep 2016 07:34:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkUwL-0002us-Cj for qemu-devel@nongnu.org; Thu, 15 Sep 2016 07:34:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51160) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkUwL-0002uE-6Q for qemu-devel@nongnu.org; Thu, 15 Sep 2016 07:34:49 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13C8A10570; Thu, 15 Sep 2016 11:34:48 +0000 (UTC) Received: from javelin.localdomain (vpn1-6-73.sin2.redhat.com [10.67.6.73]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8FBYhn3022199 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 15 Sep 2016 07:34:46 -0400 From: P J P To: Qemu Developers Date: Thu, 15 Sep 2016 17:04:42 +0530 Message-Id: <1473939282-3596-1-git-send-email-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 15 Sep 2016 11:34:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] virtio: add check for descriptor's mapped address X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Qinghao Tang , Prasad J Pandit , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Prasad J Pandit virtio back end uses set of buffers to facilitate I/O operations. If its size is too large, 'cpu_physical_memory_map' could return a null address. This would result in a null dereference while un-mapping descriptors. Add check to avoid it. Reported-by: Qinghao Tang Signed-off-by: Prasad J Pandit --- hw/virtio/virtio.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 15ee3a7..0a4c5b6 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -472,12 +472,14 @@ static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iove } iov[num_sg].iov_base = cpu_physical_memory_map(pa, &len, is_write); - iov[num_sg].iov_len = len; - addr[num_sg] = pa; + if (iov[num_sg].iov_base) { + iov[num_sg].iov_len = len; + addr[num_sg] = pa; + pa += len; + num_sg++; + } sz -= len; - pa += len; - num_sg++; } *p_num_sg = num_sg; }