thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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