Blame SOURCES/kvm-vhost-vsock-detach-the-virqueue-element-in-case-of-e.patch

f79135
From 3a8dff1446aaa9a3b93a16ea027214064e84a582 Mon Sep 17 00:00:00 2001
f79135
From: Jon Maloy <jmaloy@rehat.com>
f79135
Date: Thu, 14 Apr 2022 10:38:26 -0400
f79135
Subject: [PATCH 3/3] vhost-vsock: detach the virqueue element in case of error
f79135
f79135
RH-Author: Jon Maloy <jmaloy@redhat.com>
f79135
RH-MergeRequest: 179: vhost-vsock: detach the virqueue element in case of error
f79135
RH-Commit: [1/1] 9275dbff40eb3c7be2abca8369055ca4a1e1e52d (jmaloy/qemu-kvm)
f79135
RH-Bugzilla: 2075640
f79135
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
f79135
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
f79135
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
f79135
f79135
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2075640
f79135
Upstream: Merged
f79135
CVE: CVE-2022-26354
f79135
f79135
commit 8d1b247f3748ac4078524130c6d7ae42b6140aaf
f79135
Author: Stefano Garzarella <sgarzare@redhat.com>
f79135
Date:   Mon Feb 28 10:50:58 2022 +0100
f79135
f79135
    vhost-vsock: detach the virqueue element in case of error
f79135
f79135
    In vhost_vsock_common_send_transport_reset(), if an element popped from
f79135
    the virtqueue is invalid, we should call virtqueue_detach_element() to
f79135
    detach it from the virtqueue before freeing its memory.
f79135
f79135
    Fixes: fc0b9b0e1c ("vhost-vsock: add virtio sockets device")
f79135
    Fixes: CVE-2022-26354
f79135
    Cc: qemu-stable@nongnu.org
f79135
    Reported-by: VictorV <vv474172261@gmail.com>
f79135
    Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
f79135
    Message-Id: <20220228095058.27899-1-sgarzare@redhat.com>
f79135
    Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
f79135
    Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
f79135
    Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
f79135
f79135
(cherry picked from commit 8d1b247f3748ac4078524130c6d7ae42b6140aaf)
f79135
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
f79135
---
f79135
 hw/virtio/vhost-vsock-common.c | 10 +++++++---
f79135
 1 file changed, 7 insertions(+), 3 deletions(-)
f79135
f79135
diff --git a/hw/virtio/vhost-vsock-common.c b/hw/virtio/vhost-vsock-common.c
f79135
index 3f3771274e..ed706681ac 100644
f79135
--- a/hw/virtio/vhost-vsock-common.c
f79135
+++ b/hw/virtio/vhost-vsock-common.c
f79135
@@ -153,19 +153,23 @@ static void vhost_vsock_common_send_transport_reset(VHostVSockCommon *vvc)
f79135
     if (elem->out_num) {
f79135
         error_report("invalid vhost-vsock event virtqueue element with "
f79135
                      "out buffers");
f79135
-        goto out;
f79135
+        goto err;
f79135
     }
f79135
 
f79135
     if (iov_from_buf(elem->in_sg, elem->in_num, 0,
f79135
                      &event, sizeof(event)) != sizeof(event)) {
f79135
         error_report("vhost-vsock event virtqueue element is too short");
f79135
-        goto out;
f79135
+        goto err;
f79135
     }
f79135
 
f79135
     virtqueue_push(vq, elem, sizeof(event));
f79135
     virtio_notify(VIRTIO_DEVICE(vvc), vq);
f79135
 
f79135
-out:
f79135
+    g_free(elem);
f79135
+    return;
f79135
+
f79135
+err:
f79135
+    virtqueue_detach_element(vq, elem, 0);
f79135
     g_free(elem);
f79135
 }
f79135
 
f79135
-- 
f79135
2.31.1
f79135