From 3fec4e1981039157ad30daaa7aaa226fed17ba33 Mon Sep 17 00:00:00 2001
From: Li Qiang <liq3ea@163.com>
Date: Tue, 15 Jun 2021 10:05:40 +0800
Subject: [PATCH] vhost-user-gpu: fix memory leak in 'virgl_cmd_resource_unref'
 (CVE-2021-3544)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fix CVE-2021-3544

The 'res->iov' will be leaked if the guest trigger following sequences:

	virgl_cmd_create_resource_2d
	virgl_resource_attach_backing
	virgl_cmd_resource_unref

This patch fixes this.

Fixes: CVE-2021-3544
Reported-by: default avatarLi Qiang <liq3ea@163.com>
virtio-gpu fix: 5e8e3c4c

 ("virtio-gpu: fix resource leak
in virgl_cmd_resource_unref"
Signed-off-by: default avatarLi Qiang <liq3ea@163.com>
Reviewed-by: Marc-André Lureau's avatarMarc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20210516030403.107723-6-liq3ea@163.com>
Signed-off-by: Gerd Hoffmann's avatarGerd Hoffmann <kraxel@redhat.com>

Signed-off-by: Jiajie Li <lijiajie11@huawei.com>
---
 contrib/vhost-user-gpu/virgl.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c
index 43413e29df..4b8b536edf 100644
--- a/contrib/vhost-user-gpu/virgl.c
+++ b/contrib/vhost-user-gpu/virgl.c
@@ -105,8 +105,14 @@ virgl_cmd_resource_unref(VuGpu *g,
                          struct virtio_gpu_ctrl_command *cmd)
 {
     struct virtio_gpu_resource_unref unref;
+    struct iovec *res_iovs = NULL;
+    int num_iovs = 0;
 
     VUGPU_FILL_CMD(unref);
+    virgl_renderer_resource_detach_iov(unref.resource_id,
+                                       &res_iovs,
+                                       &num_iovs);
+    g_free(res_iovs);
 
     virgl_renderer_resource_unref(unref.resource_id);
 }
-- 
2.27.0

