0005-vhost-user-gpu-fix-memory-leak-in-virgl_cmd_resource.patch 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. CVE: CVE-2021-3544
  2. Upstream-Status: Backport
  3. Signed-off-by: Ross Burton <ross.burton@arm.com>
  4. From f6091d86ba9ea05f4e111b9b42ee0005c37a6779 Mon Sep 17 00:00:00 2001
  5. From: Li Qiang <liq3ea@163.com>
  6. Date: Sat, 15 May 2021 20:04:00 -0700
  7. Subject: [PATCH 5/7] vhost-user-gpu: fix memory leak in
  8. 'virgl_cmd_resource_unref' (CVE-2021-3544)
  9. MIME-Version: 1.0
  10. Content-Type: text/plain; charset=UTF-8
  11. Content-Transfer-Encoding: 8bit
  12. The 'res->iov' will be leaked if the guest trigger following sequences:
  13. virgl_cmd_create_resource_2d
  14. virgl_resource_attach_backing
  15. virgl_cmd_resource_unref
  16. This patch fixes this.
  17. Fixes: CVE-2021-3544
  18. Reported-by: Li Qiang <liq3ea@163.com>
  19. virtio-gpu fix: 5e8e3c4c75 ("virtio-gpu: fix resource leak
  20. in virgl_cmd_resource_unref"
  21. Signed-off-by: Li Qiang <liq3ea@163.com>
  22. Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
  23. Message-Id: <20210516030403.107723-6-liq3ea@163.com>
  24. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
  25. ---
  26. contrib/vhost-user-gpu/virgl.c | 7 +++++++
  27. 1 file changed, 7 insertions(+)
  28. diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c
  29. index 6a332d601f..c669d73a1d 100644
  30. --- a/contrib/vhost-user-gpu/virgl.c
  31. +++ b/contrib/vhost-user-gpu/virgl.c
  32. @@ -108,9 +108,16 @@ virgl_cmd_resource_unref(VuGpu *g,
  33. struct virtio_gpu_ctrl_command *cmd)
  34. {
  35. struct virtio_gpu_resource_unref unref;
  36. + struct iovec *res_iovs = NULL;
  37. + int num_iovs = 0;
  38. VUGPU_FILL_CMD(unref);
  39. + virgl_renderer_resource_detach_iov(unref.resource_id,
  40. + &res_iovs,
  41. + &num_iovs);
  42. + g_free(res_iovs);
  43. +
  44. virgl_renderer_resource_unref(unref.resource_id);
  45. }
  46. --
  47. 2.25.1