Skip to contentSkip to conversation

vhost: fix log base address

PATCH Superseded Michael S. Tsirkin 2 participants 3 messages Apr 17, 2015

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 vhost: fix log base address

VHOST_SET_LOG_BASE got an incorrect address, causing migration errors and potentially even memory corruption.

---

Built only.
Will test and report next week.
Wen Congyang, can you pls confirm as well?

 hw/virtio/vhost.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/virtio/vhost.c +4 -1
index 8dd2f59..e4cf9d7 100644
@@ -1016,10 +1016,13 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev)
     }
 
     if (hdev->log_enabled) {
+        uint64_t log_base;
+
         hdev->log_size = vhost_get_log_size(hdev);
         hdev->log = hdev->log_size ?
             g_malloc0(hdev->log_size * sizeof *hdev->log) : NULL;
-        r = hdev->vhost_ops->vhost_call(hdev, VHOST_SET_LOG_BASE, hdev->log);
+        log_base = (uint64_t)(unsigned long)hdev->log;
+        r = hdev->vhost_ops->vhost_call(hdev, VHOST_SET_LOG_BASE, &log_base);
         if (r < 0) {
             r = -errno;
             goto fail_log;
Signature · 1 line
MST
#1 lore raw
Quoted 19 lines · Michael S. Tsirkin

VHOST_SET_LOG_BASE got an incorrect address, causing migration errors and potentially even memory corruption.

---

Built only.
Will test and report next week.
Wen Congyang, can you pls confirm as well?

 hw/virtio/vhost.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/virtio/vhost.c +0 -0
index 8dd2f59..e4cf9d7 100644

hw/virtio/vhost.c int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) · line 1024

Quoted 10 lines
hw/virtio/vhost.c +3 -1
@@ -1016,10 +1016,13 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev)
     }
 
     if (hdev->log_enabled) {
+        uint64_t log_base;
+
         hdev->log_size = vhost_get_log_size(hdev);
         hdev->log = hdev->log_size ?
             g_malloc0(hdev->log_size * sizeof *hdev->log) : NULL;
-        r = hdev->vhost_ops->vhost_call(hdev, VHOST_SET_LOG_BASE, hdev->log);
+        log_base = (uint64_t)(unsigned long)hdev->log;

Paolo asked you to make this cast just be a single (uintptr_t).

thanks
-- PMM

#2 lore raw
Quoted 33 lines · Peter Maydell
Quoted 19 lines · Michael S. Tsirkin

VHOST_SET_LOG_BASE got an incorrect address, causing migration errors and potentially even memory corruption.

---

Built only.
Will test and report next week.
Wen Congyang, can you pls confirm as well?

 hw/virtio/vhost.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/virtio/vhost.c +0 -0
index 8dd2f59..e4cf9d7 100644

hw/virtio/vhost.c int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) · line 1024

Quoted 10 lines
hw/virtio/vhost.c +3 -1
@@ -1016,10 +1016,13 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev)
     }
 
     if (hdev->log_enabled) {
+        uint64_t log_base;
+
         hdev->log_size = vhost_get_log_size(hdev);
         hdev->log = hdev->log_size ?
             g_malloc0(hdev->log_size * sizeof *hdev->log) : NULL;
-        r = hdev->vhost_ops->vhost_call(hdev, VHOST_SET_LOG_BASE, hdev->log);
+        log_base = (uint64_t)(unsigned long)hdev->log;

Paolo asked you to make this cast just be a single (uintptr_t).

Quoted 2 lines

thanks
-- PMM

done.