Skip to contentSkip to conversation

virtio/vhost: do not take address of packed members

PATCH In review Paolo Bonzini 2 participants 2 messages Jan 12, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio/vhost: do not take address of packed members

The address of a packed member is not packed, which may cause accesses to unaligned pointers. Avoid this by reading the packed value before passing it to another function.

---
 hw/char/virtio-serial-bus.c | 6 +++---
 hw/virtio/vhost-user.c      | 7 +++++--
 2 files changed, 8 insertions(+), 5 deletions(-)
hw/char/virtio-serial-bus.c +3 -3
index 9470bd7..2d236b3 100644
@@ -664,9 +664,9 @@ static void virtio_serial_save_device(VirtIODevice *vdev, QEMUFile *f)
 
     /* The config space (ignored on the far end in current versions) */
     get_config(vdev, (uint8_t *)&config);
-    qemu_put_be16s(f, &config.cols);
-    qemu_put_be16s(f, &config.rows);
-    qemu_put_be32s(f, &config.max_nr_ports);
+    qemu_put_be16(f, config.cols);
+    qemu_put_be16(f, config.rows);
+    qemu_put_be32(f, config.max_nr_ports);
 
     /* The ports map */
     max_nr_ports = s->serial.max_virtserial_ports;
hw/virtio/vhost-user.c +5 -2
index 093675e..3c17207 100644
@@ -638,8 +638,11 @@ static void slave_read(void *opaque)
 
     switch (msg.request) {
     case VHOST_USER_SLAVE_IOTLB_MSG:
-        ret = vhost_backend_handle_iotlb_msg(dev, &msg.payload.iotlb);
-        break;
+        {
+            struct vhost_iotlb_msg iotlb = msg.payload.iotlb;
+            ret = vhost_backend_handle_iotlb_msg(dev, &iotlb);
+            break;
+        }
     default:
         error_report("Received unexpected msg type.");
         ret = -EINVAL;
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Paolo Bonzini

The address of a packed member is not packed, which may cause accesses to unaligned pointers. Avoid this by reading the packed value before passing it to another function.

---
 hw/char/virtio-serial-bus.c | 6 +++---
 hw/virtio/vhost-user.c      | 7 +++++--
 2 files changed, 8 insertions(+), 5 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org