Skip to contentSkip to conversation

vhost-vsock: detach the virqueue element in case of error

PATCH In review Stefano Garzarella 2 participants 2 messages Feb 28, 2022 – Mar 1, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost-vsock: detach the virqueue element in case of error

In vhost_vsock_common_send_transport_reset(), if an element popped from the virtqueue is invalid, we should call virtqueue_detach_element() to detach it from the virtqueue before freeing its memory.

Fixes fc0b9b0e1c ("vhost-vsock: add virtio sockets device")
---
 hw/virtio/vhost-vsock-common.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
hw/virtio/vhost-vsock-common.c +7 -3
index 3f3771274e..ed706681ac 100644
@@ -153,19 +153,23 @@ static void vhost_vsock_common_send_transport_reset(VHostVSockCommon *vvc)
     if (elem->out_num) {
         error_report("invalid vhost-vsock event virtqueue element with "
                      "out buffers");
-        goto out;
+        goto err;
     }
 
     if (iov_from_buf(elem->in_sg, elem->in_num, 0,
                      &event, sizeof(event)) != sizeof(event)) {
         error_report("vhost-vsock event virtqueue element is too short");
-        goto out;
+        goto err;
     }
 
     virtqueue_push(vq, elem, sizeof(event));
     virtio_notify(VIRTIO_DEVICE(vvc), vq);
 
-out:
+    g_free(elem);
+    return;
+
+err:
+    virtqueue_detach_element(vq, elem, 0);
     g_free(elem);
 }
 
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Stefano Garzarella

In vhost_vsock_common_send_transport_reset(), if an element popped from the virtqueue is invalid, we should call virtqueue_detach_element() to detach it from the virtqueue before freeing its memory.

Fixes fc0b9b0e1c ("vhost-vsock: add virtio sockets device")
---
 hw/virtio/vhost-vsock-common.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)