From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=59135 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PvGIZ-0002Du-Og for qemu-devel@nongnu.org; Thu, 03 Mar 2011 16:43:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PvGIY-0006nT-MP for qemu-devel@nongnu.org; Thu, 03 Mar 2011 16:43:03 -0500 Received: from mtagate7.uk.ibm.com ([194.196.100.167]:34946) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PvGIY-0006mX-E4 for qemu-devel@nongnu.org; Thu, 03 Mar 2011 16:43:02 -0500 Received: from d06nrmr1307.portsmouth.uk.ibm.com (d06nrmr1307.portsmouth.uk.ibm.com [9.149.38.129]) by mtagate7.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p23Lgwsl022631 for ; Thu, 3 Mar 2011 21:42:58 GMT Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p23Lh2Nb1958028 for ; Thu, 3 Mar 2011 21:43:10 GMT Received: from d06av08.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p23LgnoP019048 for ; Thu, 3 Mar 2011 21:42:49 GMT From: Stefan Hajnoczi Date: Thu, 3 Mar 2011 21:42:28 +0000 Message-Id: <1299188548-24670-1-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <20110303205101.GE19189@hall.aurel32.net> References: <20110303205101.GE19189@hall.aurel32.net> Subject: [Qemu-devel] [PATCH] virtio-net: Fix lduw_p() pointer argument of wrong size List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Aurelien Jarno Cc: Anthony Liguori , Liu Yu-B13201 , qemu-devel@nongnu.org, Stefan Hajnoczi A pointer to a size_t variable was passed as the void * pointer to lduw_p() in virtio_net_receive(). Instead of acting on the 16-bit value this caused failure on big-endian hosts. Avoid this issue in the future by using stw_p() instead. In general we should use ld*_p() for loading from target memory and st*_p() for storing to target memory anyway, not the other way around. Also tighten up a correct use of lduw_p() when stw_p() should be used instead in virtio_net_get_config(). Signed-off-by: Stefan Hajnoczi --- hw/virtio-net.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/virtio-net.c b/hw/virtio-net.c index 20cf680..5962298 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -79,7 +79,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) VirtIONet *n = to_virtio_net(vdev); struct virtio_net_config netcfg; - netcfg.status = lduw_p(&n->status); + stw_p(&netcfg.status, n->status); memcpy(netcfg.mac, n->mac, ETH_ALEN); memcpy(config, &netcfg, sizeof(netcfg)); } @@ -679,7 +679,7 @@ static ssize_t virtio_net_receive(VLANClientState *nc, const uint8_t *buf, size_ } if (mhdr) { - mhdr->num_buffers = lduw_p(&i); + stw_p(&mhdr->num_buffers, i); } virtqueue_flush(n->rx_vq, i); -- 1.7.2.3