[PATCH] hw/display/virtio-gpu: fix dmabuf_fd leak on remap failure

marcandre.lureau@redhat.com posted 1 patch 1 week, 5 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260713125622.111513-1-marcandre.lureau@redhat.com
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Dmitry Osipenko <dmitry.osipenko@collabora.com>, "Michael S. Tsirkin" <mst@redhat.com>
hw/display/virtio-gpu-udmabuf.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] hw/display/virtio-gpu: fix dmabuf_fd leak on remap failure
Posted by marcandre.lureau@redhat.com 1 week, 5 days ago
From: Marc-André Lureau <marcandre.lureau@redhat.com>

When virtio_gpu_create_udmabuf() succeeds but virtio_gpu_remap_udmabuf()
fails (mmap returns MAP_FAILED), virtio_gpu_init_udmabuf() returns early
without closing the dmabuf fd. Since res->blob is never set in this
path, later cleanup via virtio_gpu_cleanup_mapping() skips
virtio_gpu_fini_udmabuf() entirely, leaking the file descriptor.

Call virtio_gpu_destroy_udmabuf() before the early return to close
the fd. This function already handles partial state correctly: it
skips the munmap when res->remapped is NULL and closes the fd when
res->dmabuf_fd >= 0.

Fixes: 9b60cdf98723 ("virtio-gpu: Add udmabuf helpers")
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/display/virtio-gpu-udmabuf.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabuf.c
index d5ac1cfca0e..5f08c855dde 100644
--- a/hw/display/virtio-gpu-udmabuf.c
+++ b/hw/display/virtio-gpu-udmabuf.c
@@ -143,6 +143,7 @@ void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res)
         }
         virtio_gpu_remap_udmabuf(res);
         if (!res->remapped) {
+            virtio_gpu_destroy_udmabuf(res);
             return;
         }
         pdata = res->remapped;
-- 
2.55.0


Re: [PATCH] hw/display/virtio-gpu: fix dmabuf_fd leak on remap failure
Posted by Michael Tokarev 1 week ago
On 7/13/26 15:56, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> When virtio_gpu_create_udmabuf() succeeds but virtio_gpu_remap_udmabuf()
> fails (mmap returns MAP_FAILED), virtio_gpu_init_udmabuf() returns early
> without closing the dmabuf fd. Since res->blob is never set in this
> path, later cleanup via virtio_gpu_cleanup_mapping() skips
> virtio_gpu_fini_udmabuf() entirely, leaking the file descriptor.
> 
> Call virtio_gpu_destroy_udmabuf() before the early return to close
> the fd. This function already handles partial state correctly: it
> skips the munmap when res->remapped is NULL and closes the fd when
> res->dmabuf_fd >= 0.
> 
> Fixes: 9b60cdf98723 ("virtio-gpu: Add udmabuf helpers")
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

This too smells like a qemu-stable material (the issue is minor though).
I'm picking it up, please let me know if I should not.

Thanks,
/mjt


Re: [PATCH] hw/display/virtio-gpu: fix dmabuf_fd leak on remap failure
Posted by Akihiko Odaki 1 week, 2 days ago
On 2026/07/13 21:56, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> When virtio_gpu_create_udmabuf() succeeds but virtio_gpu_remap_udmabuf()
> fails (mmap returns MAP_FAILED), virtio_gpu_init_udmabuf() returns early
> without closing the dmabuf fd. Since res->blob is never set in this
> path, later cleanup via virtio_gpu_cleanup_mapping() skips
> virtio_gpu_fini_udmabuf() entirely, leaking the file descriptor.
> 
> Call virtio_gpu_destroy_udmabuf() before the early return to close
> the fd. This function already handles partial state correctly: it
> skips the munmap when res->remapped is NULL and closes the fd when
> res->dmabuf_fd >= 0.
> 
> Fixes: 9b60cdf98723 ("virtio-gpu: Add udmabuf helpers")
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>

Re: [PATCH] hw/display/virtio-gpu: fix dmabuf_fd leak on remap failure
Posted by Dmitry Osipenko 1 week, 4 days ago
On 7/13/26 15:56, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> When virtio_gpu_create_udmabuf() succeeds but virtio_gpu_remap_udmabuf()
> fails (mmap returns MAP_FAILED), virtio_gpu_init_udmabuf() returns early
> without closing the dmabuf fd. Since res->blob is never set in this
> path, later cleanup via virtio_gpu_cleanup_mapping() skips
> virtio_gpu_fini_udmabuf() entirely, leaking the file descriptor.
> 
> Call virtio_gpu_destroy_udmabuf() before the early return to close
> the fd. This function already handles partial state correctly: it
> skips the munmap when res->remapped is NULL and closes the fd when
> res->dmabuf_fd >= 0.
> 
> Fixes: 9b60cdf98723 ("virtio-gpu: Add udmabuf helpers")
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  hw/display/virtio-gpu-udmabuf.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabuf.c
> index d5ac1cfca0e..5f08c855dde 100644
> --- a/hw/display/virtio-gpu-udmabuf.c
> +++ b/hw/display/virtio-gpu-udmabuf.c
> @@ -143,6 +143,7 @@ void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res)
>          }
>          virtio_gpu_remap_udmabuf(res);
>          if (!res->remapped) {
> +            virtio_gpu_destroy_udmabuf(res);
>              return;
>          }
>          pdata = res->remapped;

Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>

-- 
Best regards,
Dmitry

Re: [PATCH] hw/display/virtio-gpu: fix dmabuf_fd leak on remap failure
Posted by Philippe Mathieu-Daudé 1 week, 4 days ago
On 13/7/26 14:56, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> When virtio_gpu_create_udmabuf() succeeds but virtio_gpu_remap_udmabuf()
> fails (mmap returns MAP_FAILED), virtio_gpu_init_udmabuf() returns early
> without closing the dmabuf fd. Since res->blob is never set in this
> path, later cleanup via virtio_gpu_cleanup_mapping() skips
> virtio_gpu_fini_udmabuf() entirely, leaking the file descriptor.
> 
> Call virtio_gpu_destroy_udmabuf() before the early return to close
> the fd. This function already handles partial state correctly: it
> skips the munmap when res->remapped is NULL and closes the fd when
> res->dmabuf_fd >= 0.
> 
> Fixes: 9b60cdf98723 ("virtio-gpu: Add udmabuf helpers")
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   hw/display/virtio-gpu-udmabuf.c | 1 +
>   1 file changed, 1 insertion(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>