From: Jason Wang <jasowang@redhat.com>
To: qemu-devel@nongnu.org, mst@redhat.com
Cc: Jason Wang <jasowang@redhat.com>, clg@fr.ibm.com, qemu-stable@nongnu.org
Subject: [Qemu-devel] [PATCH 5/5] virtio-net: unbreak any layout
Date: Mon, 13 Jul 2015 13:46:51 +0800 [thread overview]
Message-ID: <1436766411-29144-5-git-send-email-jasowang@redhat.com> (raw)
In-Reply-To: <1436766411-29144-1-git-send-email-jasowang@redhat.com>
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 <jasowang@redhat.com>
---
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));
}
/*
--
2.1.4
next prev parent reply other threads:[~2015-07-13 5:47 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-13 5:46 [Qemu-devel] [PATCH 1/5] virtio-pci: ignore unaligned read/write in virtio_address_space_read()/write() Jason Wang
2015-07-13 5:46 ` [Qemu-devel] [PATCH 2/5] virtio-blk: disable scsi passthrough for 1.0 device Jason Wang
2015-07-13 7:46 ` Michael S. Tsirkin
2015-07-13 9:00 ` Jason Wang
2015-07-13 9:56 ` Kevin Wolf
2015-07-13 11:51 ` Cornelia Huck
2015-07-13 12:22 ` Michael S. Tsirkin
2015-07-13 12:30 ` Cornelia Huck
2015-07-13 12:36 ` Michael S. Tsirkin
2015-07-13 13:20 ` Cornelia Huck
2015-07-13 14:34 ` Paolo Bonzini
2015-07-13 14:41 ` Cornelia Huck
2015-07-13 15:13 ` Paolo Bonzini
2015-07-13 15:35 ` Michael S. Tsirkin
2015-07-14 17:43 ` Cornelia Huck
2015-07-15 10:59 ` Michael S. Tsirkin
2015-07-15 11:46 ` Cornelia Huck
2015-07-15 12:01 ` Michael S. Tsirkin
2015-07-15 12:43 ` Cornelia Huck
2015-07-15 13:16 ` Michael S. Tsirkin
2015-07-15 13:40 ` Cornelia Huck
2015-07-15 14:11 ` Michael S. Tsirkin
2015-07-15 14:30 ` Cornelia Huck
2015-07-15 14:39 ` Michael S. Tsirkin
2015-07-15 15:38 ` Cornelia Huck
2015-07-15 18:51 ` Michael S. Tsirkin
2015-07-16 12:37 ` Cornelia Huck
2015-07-16 12:47 ` Michael S. Tsirkin
2015-07-16 17:22 ` Paolo Bonzini
2015-07-17 7:18 ` Cornelia Huck
2015-07-13 11:27 ` Michael S. Tsirkin
2015-07-13 5:46 ` [Qemu-devel] [PATCH 3/5] virtio-blk: set VIRTIO_F_ANY_LAYOUT when 1.0 is supported Jason Wang
2015-07-13 5:46 ` [Qemu-devel] [PATCH 4/5] Revert "virtio-net: enable virtio 1.0" Jason Wang
2015-07-13 6:16 ` Cornelia Huck
2015-07-13 7:22 ` Michael S. Tsirkin
2015-07-13 8:46 ` Cornelia Huck
2015-07-13 8:29 ` Jason Wang
2015-07-13 5:46 ` Jason Wang [this message]
2015-07-13 6:50 ` [Qemu-devel] [PATCH 5/5] virtio-net: unbreak any layout Paolo Bonzini
2015-07-13 8:30 ` Jason Wang
2015-07-13 7:24 ` Michael S. Tsirkin
2015-07-13 8:22 ` Michael S. Tsirkin
2015-07-13 10:54 ` Greg Kurz
2015-07-13 11:13 ` Michael S. Tsirkin
2015-07-13 8:30 ` Jason Wang
2015-07-13 7:36 ` [Qemu-devel] [PATCH 1/5] virtio-pci: ignore unaligned read/write in virtio_address_space_read()/write() Michael S. Tsirkin
2015-07-13 7:53 ` Gerd Hoffmann
2015-07-13 8:00 ` Michael S. Tsirkin
2015-07-13 8:39 ` Gerd Hoffmann
2015-07-13 8:37 ` Jason Wang
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=1436766411-29144-5-git-send-email-jasowang@redhat.com \
--to=jasowang@redhat.com \
--cc=clg@fr.ibm.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@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).