From patchwork Thu Nov 27 05:59:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 415384 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6FCF71401F6 for ; Thu, 27 Nov 2014 17:00:11 +1100 (AEDT) Received: from localhost ([::1]:37757 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xts7d-0005GK-2b for incoming@patchwork.ozlabs.org; Thu, 27 Nov 2014 01:00:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xts7F-0004lq-72 for qemu-devel@nongnu.org; Thu, 27 Nov 2014 00:59:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xts7B-0003Xm-5R for qemu-devel@nongnu.org; Thu, 27 Nov 2014 00:59:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43874) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xts7A-0003XU-Si; Thu, 27 Nov 2014 00:59:41 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sAR5xVYc010528 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 27 Nov 2014 00:59:32 -0500 Received: from jason-ThinkPad-T430s.nay.redhat.com (dhcp-66-71-84.eng.nay.redhat.com [10.66.71.84] (may be forged)) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sAR5xRF6025002; Thu, 27 Nov 2014 00:59:28 -0500 From: Jason Wang To: aliguori@amazon.com, mst@redhat.com, qemu-devel@nongnu.org Date: Thu, 27 Nov 2014 13:59:25 +0800 Message-Id: <1417067965-9159-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Jason Wang , qemu-stable@nongnu.org, Stefano Stabellini Subject: [Qemu-devel] [2.2 PATCH] virtio-net: fix unmap leak 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 virtio_net_handle_ctrl() and other functions that process control vq request call iov_discard_front() which will shorten the iov. This will lead unmapping in virtqueue_push() leaks mapping. Fixes this by keeping the original iov untouched and using a temp variable in those functions. Cc: Wen Congyang Cc: Stefano Stabellini Cc: qemu-stable@nongnu.org Signed-off-by: Jason Wang --- hw/net/virtio-net.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 9b88775..fdb4edd 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -798,7 +798,7 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) virtio_net_ctrl_ack status = VIRTIO_NET_ERR; VirtQueueElement elem; size_t s; - struct iovec *iov; + struct iovec *iov, *iov2; unsigned int iov_cnt; while (virtqueue_pop(vq, &elem)) { @@ -808,8 +808,12 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) exit(1); } - iov = elem.out_sg; iov_cnt = elem.out_num; + s = sizeof(struct iovec) * elem.out_num; + iov = g_malloc(s); + memcpy(iov, elem.out_sg, s); + iov2 = iov; + s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl)); iov_discard_front(&iov, &iov_cnt, sizeof(ctrl)); if (s != sizeof(ctrl)) { @@ -833,6 +837,7 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) virtqueue_push(vq, &elem, sizeof(status)); virtio_notify(vdev, vq); + g_free(iov2); } }