diff mbox

[1/5] virtio-pci: ignore unaligned read/write in virtio_address_space_read()/write()

Message ID 1436766411-29144-1-git-send-email-jasowang@redhat.com
State New
Headers show

Commit Message

Jason Wang July 13, 2015, 5:46 a.m. UTC
We abort on unaligned read/write in
virtio_address_space_read()/write() but since len in under control of
guest so qemu will simply crash when booting a modern guest (guest is
try to read when len is zero). Fix this by ignoring unaligned write or
read.

Fixes 1e40356ce5f6ccfa0bb57104a533c62952c560ce
("virtio fix cfg endian-ness for BE targets")
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/virtio/virtio-pci.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index ccca2b6..bed9735 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -466,8 +466,8 @@  void virtio_address_space_write(AddressSpace *as, hwaddr addr,
      */
     addr &= ~(len - 1);
 
-    /* Make sure caller aligned buf properly */
-    assert(!(((uintptr_t)buf) & (len - 1)));
+    if (!(((uintptr_t)buf) & (len - 1)))
+        return;
 
     switch (len) {
     case 1:
@@ -498,8 +498,8 @@  virtio_address_space_read(AddressSpace *as, hwaddr addr, uint8_t *buf, int len)
      */
     addr &= ~(len - 1);
 
-    /* Make sure caller aligned buf properly */
-    assert(!(((uintptr_t)buf) & (len - 1)));
+    if (!(((uintptr_t)buf) & (len - 1)))
+        return;
 
     switch (len) {
     case 1: