From patchwork Mon Jul 13 05:46:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 494229 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 4ACC4140280 for ; Mon, 13 Jul 2015 15:47:39 +1000 (AEST) Received: from localhost ([::1]:52987 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEWaX-0007Og-HC for incoming@patchwork.ozlabs.org; Mon, 13 Jul 2015 01:47:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEWa5-0006WR-1u for qemu-devel@nongnu.org; Mon, 13 Jul 2015 01:47:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZEWa1-0006KU-Rw for qemu-devel@nongnu.org; Mon, 13 Jul 2015 01:47:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49323) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEWa1-0006KM-MJ; Mon, 13 Jul 2015 01:47:05 -0400 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 (Postfix) with ESMTPS id 448F8359973; Mon, 13 Jul 2015 05:47:05 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (vpn1-4-152.pek2.redhat.com [10.72.4.152]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6D5kqAX025330; Mon, 13 Jul 2015 01:47:03 -0400 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com Date: Mon, 13 Jul 2015 13:46:51 +0800 Message-Id: <1436766411-29144-5-git-send-email-jasowang@redhat.com> In-Reply-To: <1436766411-29144-1-git-send-email-jasowang@redhat.com> References: <1436766411-29144-1-git-send-email-jasowang@redhat.com> 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: Jason Wang , clg@fr.ibm.com, qemu-stable@nongnu.org Subject: [Qemu-devel] [PATCH 5/5] virtio-net: unbreak any layout 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 Commit 032a74a1c0fcdd5fd1c69e56126b4c857ee36611 ("virtio-net: byteswap virtio-net header") breaks any layout by requiring out_sg[0].iov_len >= n->guest_hdr_len. Fixing this by copying header to temporary buffer and copying it back after byteswap. Fixes 032a74a1c0fcdd5fd1c69e56126b4c857ee36611 ("virtio-net: byteswap virtio-net header") Cc: qemu-stable@nongnu.org Cc: clg@fr.ibm.com Signed-off-by: Jason Wang --- hw/net/virtio-net.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index e3c2db3..b42af8f 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1139,10 +1139,11 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) } while (virtqueue_pop(q->tx_vq, &elem)) { - ssize_t ret, len; + ssize_t ret, len, s; unsigned int out_num = elem.out_num; struct iovec *out_sg = &elem.out_sg[0]; struct iovec sg[VIRTQUEUE_MAX_SIZE]; + struct virtio_net_hdr hdr; if (out_num < 1) { error_report("virtio-net header not in first element"); @@ -1150,11 +1151,14 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) } if (n->has_vnet_hdr) { - if (out_sg[0].iov_len < n->guest_hdr_len) { + s = iov_to_buf(out_sg, out_num, 0, &hdr, sizeof(hdr)); + if (s != sizeof(hdr)) { error_report("virtio-net header incorrect"); exit(1); } - virtio_net_hdr_swap(vdev, (void *) out_sg[0].iov_base); + virtio_net_hdr_swap(vdev, (void *) &hdr); + s = iov_from_buf(out_sg, out_num, 0, &hdr, sizeof(hdr)); + assert(s == sizeof(hdr)); } /*