From 3a8dff1446aaa9a3b93a16ea027214064e84a582 Mon Sep 17 00:00:00 2001 From: Jon Maloy Date: Thu, 14 Apr 2022 10:38:26 -0400 Subject: [PATCH 3/3] vhost-vsock: detach the virqueue element in case of error RH-Author: Jon Maloy RH-MergeRequest: 179: vhost-vsock: detach the virqueue element in case of error RH-Commit: [1/1] 9275dbff40eb3c7be2abca8369055ca4a1e1e52d (jmaloy/qemu-kvm) RH-Bugzilla: 2075640 RH-Acked-by: Miroslav Rezanina RH-Acked-by: Stefano Garzarella RH-Acked-by: Laurent Vivier Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2075640 Upstream: Merged CVE: CVE-2022-26354 commit 8d1b247f3748ac4078524130c6d7ae42b6140aaf Author: Stefano Garzarella Date: Mon Feb 28 10:50:58 2022 +0100 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") Fixes: CVE-2022-26354 Cc: qemu-stable@nongnu.org Reported-by: VictorV Signed-off-by: Stefano Garzarella Message-Id: <20220228095058.27899-1-sgarzare@redhat.com> Reviewed-by: Stefan Hajnoczi Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin (cherry picked from commit 8d1b247f3748ac4078524130c6d7ae42b6140aaf) Signed-off-by: Jon Maloy --- hw/virtio/vhost-vsock-common.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-vsock-common.c b/hw/virtio/vhost-vsock-common.c index 3f3771274e..ed706681ac 100644 --- a/hw/virtio/vhost-vsock-common.c +++ b/hw/virtio/vhost-vsock-common.c @@ -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); } -- 2.31.1