vhost: fix log base address
Michael S. Tsirkin
maintainerPATCH 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
@@ -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
Quoted 18 lines · Michael S. Tsirkin
VHOST_SET_LOG_BASEgot an incorrect address, causing migration errors and potentially even memory corruption.Cc Peter Maydell <[email protected]>Reported-by Wen Congyang <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>---
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
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;
Quoted 31 lines · zhanghailiang
Quoted 18 lines · Michael S. Tsirkin
VHOST_SET_LOG_BASEgot an incorrect address, causing migration errors and potentially even memory corruption.Cc Peter Maydell <[email protected]>Reported-by Wen Congyang <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>---
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
-0hw/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;.
Quoted 33 lines · zhanghailiang
Quoted 20 lines · Michael S. Tsirkin
VHOST_SET_LOG_BASEgot an incorrect address, causing migration errors and potentially even memory corruption.Cc Peter Maydell <[email protected]>Reported-by Wen Congyang <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>---
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@@ -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
-1if (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;
Quoted 36 lines · Paolo Bonzini
Quoted 33 lines · zhanghailiang
Quoted 20 lines · Michael S. Tsirkin
VHOST_SET_LOG_BASEgot an incorrect address, causing migration errors and potentially even memory corruption.Cc Peter Maydell <[email protected]>Reported-by Wen Congyang <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>---
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@@ -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
-1if (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_tis 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;
Quoted 36 lines · Paolo Bonzini
Quoted 33 lines · zhanghailiang
Quoted 20 lines · Michael S. Tsirkin
VHOST_SET_LOG_BASEgot an incorrect address, causing migration errors and potentially even memory corruption.Cc Peter Maydell <[email protected]>Reported-by Wen Congyang <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>---
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@@ -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
-1if (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_tis 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
Michael S. Tsirkin
maintainerQuoted 42 lines · Peter Maydell
Quoted 36 lines · Paolo Bonzini
Quoted 33 lines · zhanghailiang
Quoted 20 lines · Michael S. Tsirkin
VHOST_SET_LOG_BASEgot an incorrect address, causing migration errors and potentially even memory corruption.Cc Peter Maydell <[email protected]>Reported-by Wen Congyang <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>---
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@@ -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
-1if (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_tis 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.