qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: Aurelien Jarno <aurelien@aurel32.net>
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	Liu Yu-B13201 <B13201@freescale.com>,
	qemu-devel@nongnu.org,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH] virtio-net: Fix lduw_p() pointer argument of wrong size
Date: Thu,  3 Mar 2011 21:42:28 +0000	[thread overview]
Message-ID: <1299188548-24670-1-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <20110303205101.GE19189@hall.aurel32.net>

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 <stefanha@linux.vnet.ibm.com>
---
 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

  reply	other threads:[~2011-03-03 21:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-15 19:27 [Qemu-devel] [PATCH 1/2] virtio-net: fix cross-endianness support Aurelien Jarno
2011-01-15 19:27 ` [Qemu-devel] [PATCH 2/2] virtio-blk: fix cross-endianness targets Aurelien Jarno
2011-01-25  8:07   ` Aurelien Jarno
2011-01-25  9:58   ` Stefan Hajnoczi
2011-01-25  8:07 ` [Qemu-devel] [PATCH 1/2] virtio-net: fix cross-endianness support Aurelien Jarno
2011-02-28  8:43 ` Liu Yu-B13201
2011-03-03 19:16   ` Aurelien Jarno
2011-03-03 19:50     ` Stefan Hajnoczi
2011-03-03 20:51       ` Aurelien Jarno
2011-03-03 21:42         ` Stefan Hajnoczi [this message]
2011-03-03 22:45           ` [Qemu-devel] Re: [PATCH] virtio-net: Fix lduw_p() pointer argument of wrong size Aurelien Jarno
2011-03-04  6:41             ` [Qemu-devel] " Liu Yu-B13201

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1299188548-24670-1-git-send-email-stefanha@linux.vnet.ibm.com \
    --to=stefanha@linux.vnet.ibm.com \
    --cc=B13201@freescale.com \
    --cc=aliguori@us.ibm.com \
    --cc=aurelien@aurel32.net \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).