cryptospore / rpms / qemu-kvm

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