Skip to contentSkip to conversation

vhost: fix log base address

PATCH Superseded Michael S. Tsirkin 5 participants 7 messages Apr 15, 2015 – Apr 17, 2015 virtio core

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

PATCH 1/1 vhost: fix log base address

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

---

Could you please confirm this fixes the problem for you?

 hw/virtio/vhost.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/virtio/vhost.c +4 -1
index 8dd2f59..02c5604 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)log_base;
+        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 18 lines · Michael S. Tsirkin

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

---

Could you please confirm this fixes the problem for you?

  hw/virtio/vhost.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
hw/virtio/vhost.c +0 -0
index 8dd2f59..02c5604 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)log_base;
                                               ^^^^^^^^

s/log_base/hdev->log ?

Quoted 5 lines
hw/virtio/vhost.c +1 -0
+        r = hdev->vhost_ops->vhost_call(hdev, VHOST_SET_LOG_BASE, &log_base);
          if (r < 0) {
              r = -errno;
              goto fail_log;
#2 lore raw
Quoted 31 lines · zhanghailiang
Quoted 18 lines · Michael S. Tsirkin

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

---

Could you please confirm this fixes the problem for you?

  hw/virtio/vhost.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
hw/virtio/vhost.c +0 -0
index 8dd2f59..02c5604 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)log_base;
                                               ^^^^^^^^
Quoted 1 line

s/log_base/hdev->log ?

I test the patch with this modification. It works for me.

Thanks
Wen Congyang

Quoted 10 lines

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

Quoted 6 lines
hw/virtio/vhost.c +1 -0
+        r = hdev->vhost_ops->vhost_call(hdev, VHOST_SET_LOG_BASE, &log_base);
          if (r < 0) {
              r = -errno;
              goto fail_log;

.

#3 lore raw
In reply to zhanghailiang
Quoted 33 lines · zhanghailiang
Quoted 20 lines · Michael S. Tsirkin

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

---

Could you please confirm this fixes the problem for you?

  hw/virtio/vhost.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
hw/virtio/vhost.c +0 -0
index 8dd2f59..02c5604 100644
@@ -1016,10 +1016,13 @@ int vhost_dev_start(struct vhost_dev *hdev,
 VirtIODevice *vdev)
      }

hw/virtio/vhost.c int vhost_dev_start(struct vhost_dev *hdev, · line 1026

Quoted 10 lines
hw/virtio/vhost.c +3 -1
 
      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)log_base;
                                               ^^^^^^^^
Quoted 1 line

s/log_base/hdev->log ?

Also s/unsigned long/uintptr_t/ please. The subsequent cast to uint64_t is not necessary.

Paolo

Quoted 10 lines
Quoted 6 lines
hw/virtio/vhost.c +1 -0
+        r = hdev->vhost_ops->vhost_call(hdev, VHOST_SET_LOG_BASE,
 &log_base);
          if (r < 0) {
              r = -errno;
              goto fail_log;
#4 lore raw
Quoted 36 lines · Paolo Bonzini
Quoted 33 lines · zhanghailiang
Quoted 20 lines · Michael S. Tsirkin

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

---

Could you please confirm this fixes the problem for you?

  hw/virtio/vhost.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
hw/virtio/vhost.c +0 -0
index 8dd2f59..02c5604 100644
@@ -1016,10 +1016,13 @@ int vhost_dev_start(struct vhost_dev *hdev,
 VirtIODevice *vdev)
      }

hw/virtio/vhost.c int vhost_dev_start(struct vhost_dev *hdev, · line 1026

Quoted 10 lines
hw/virtio/vhost.c +3 -1
 
      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)log_base;
                                               ^^^^^^^^
Quoted 4 lines
Quoted 1 line

s/log_base/hdev->log ?

Also s/unsigned long/uintptr_t/ please. The subsequent cast to uint64_t is not necessary.

Should we also update vhost_dev_log_resize()?

Thanks
Wen Congyang

Quoted 15 lines

Paolo

Quoted 10 lines
Quoted 6 lines
hw/virtio/vhost.c +1 -0
+        r = hdev->vhost_ops->vhost_call(hdev, VHOST_SET_LOG_BASE,
 &log_base);
          if (r < 0) {
              r = -errno;
              goto fail_log;
#5 lore raw
In reply to Paolo Bonzini
Quoted 36 lines · Paolo Bonzini
Quoted 33 lines · zhanghailiang
Quoted 20 lines · Michael S. Tsirkin

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

---

Could you please confirm this fixes the problem for you?

  hw/virtio/vhost.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
hw/virtio/vhost.c +0 -0
index 8dd2f59..02c5604 100644
@@ -1016,10 +1016,13 @@ int vhost_dev_start(struct vhost_dev *hdev,
 VirtIODevice *vdev)
      }

hw/virtio/vhost.c int vhost_dev_start(struct vhost_dev *hdev, · line 1026

Quoted 10 lines
hw/virtio/vhost.c +3 -1
 
      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)log_base;
                                               ^^^^^^^^
Quoted 4 lines
Quoted 1 line

s/log_base/hdev->log ?

Also s/unsigned long/uintptr_t/ please. The subsequent cast to uint64_t is not necessary.

I think this is our remaining for-2.3 bug; would somebody like to produce and test a patch with all the fixes mentioned in this thread?

thanks
-- PMM

author maintainer
#6 lore raw
Quoted 42 lines · Peter Maydell
Quoted 36 lines · Paolo Bonzini
Quoted 33 lines · zhanghailiang
Quoted 20 lines · Michael S. Tsirkin

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

---

Could you please confirm this fixes the problem for you?

  hw/virtio/vhost.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
hw/virtio/vhost.c +0 -0
index 8dd2f59..02c5604 100644
@@ -1016,10 +1016,13 @@ int vhost_dev_start(struct vhost_dev *hdev,
 VirtIODevice *vdev)
      }

hw/virtio/vhost.c int vhost_dev_start(struct vhost_dev *hdev, · line 1026

Quoted 10 lines
hw/virtio/vhost.c +3 -1
 
      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)log_base;
                                               ^^^^^^^^
Quoted 4 lines
Quoted 1 line

s/log_base/hdev->log ?

Also s/unsigned long/uintptr_t/ please. The subsequent cast to uint64_t is not necessary.

Quoted 6 lines

I think this is our remaining for-2.3 bug; would somebody like to produce and test a patch with all the fixes mentioned in this thread?

thanks
-- PMM

I just posted it but it's not tested yet.