hw/display/virtio-gpu: fix dmabuf_fd leak on remap failure
PATCH 1/1 hw/display/virtio-gpu: fix dmabuf_fd leak on remap failure
From: Marc-André Lureau <[email protected]>
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.
--- hw/display/virtio-gpu-udmabuf.c | 1 + 1 file changed, 1 insertion(+)
hw/display/virtio-gpu-udmabuf.c +1 -0
@@ -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;
Signature · 1 line
2.55.0
Quoted 13 lines · On 13/7/26 14:56, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
When
virtio_gpu_create_udmabuf()succeeds butvirtio_gpu_remap_udmabuf()fails (mmap returnsMAP_FAILED),virtio_gpu_init_udmabuf()returns early without closing the dmabuf fd. Sinceres->blobis never set in this path, later cleanup viavirtio_gpu_cleanup_mapping()skipsvirtio_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 whenres->remappedis NULL and closes the fd whenres->dmabuf_fd>= 0.
Quoted 5 lines
Fixes 9b60cdf98723 ("virtio-gpu: Add udmabuf helpers")Signed-off-by Marc-André Lureau <[email protected]>--- hw/display/virtio-gpu-udmabuf.c | 1 + 1 file changed, 1 insertion(+)
Quoted 24 lines · On 7/13/26 15:56, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
When
virtio_gpu_create_udmabuf()succeeds butvirtio_gpu_remap_udmabuf()fails (mmap returnsMAP_FAILED),virtio_gpu_init_udmabuf()returns early without closing the dmabuf fd. Sinceres->blobis never set in this path, later cleanup viavirtio_gpu_cleanup_mapping()skipsvirtio_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 whenres->remappedis NULL and closes the fd whenres->dmabuf_fd>= 0.Fixes 9b60cdf98723 ("virtio-gpu: Add udmabuf helpers")Signed-off-by Marc-André Lureau <[email protected]>--- hw/display/virtio-gpu-udmabuf.c | 1 + 1 file changed, 1 insertion(+)hw/display/virtio-gpu-udmabuf.c +0
-0
hw/display/virtio-gpu-udmabuf.c void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res) · line 149
Quoted 7 lines
hw/display/virtio-gpu-udmabuf.c +1
-0@@ -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;
Signature · 2 lines
Best regards, Dmitry
Quoted 8 lines · On 2026/07/13 21:56, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
When
virtio_gpu_create_udmabuf()succeeds butvirtio_gpu_remap_udmabuf()fails (mmap returnsMAP_FAILED),virtio_gpu_init_udmabuf()returns early without closing the dmabuf fd. Sinceres->blobis never set in this path, later cleanup viavirtio_gpu_cleanup_mapping()skipsvirtio_gpu_fini_udmabuf()entirely, leaking the file descriptor.
Quoted 7 lines
Call
virtio_gpu_destroy_udmabuf()before the early return to close the fd. This function already handles partial state correctly: it skips the munmap whenres->remappedis NULL and closes the fd whenres->dmabuf_fd>= 0.Fixes 9b60cdf98723 ("virtio-gpu: Add udmabuf helpers")Signed-off-by Marc-André Lureau <[email protected]>
Quoted 8 lines · On 7/13/26 15:56, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
When
virtio_gpu_create_udmabuf()succeeds butvirtio_gpu_remap_udmabuf()fails (mmap returnsMAP_FAILED),virtio_gpu_init_udmabuf()returns early without closing the dmabuf fd. Sinceres->blobis never set in this path, later cleanup viavirtio_gpu_cleanup_mapping()skipsvirtio_gpu_fini_udmabuf()entirely, leaking the file descriptor.
Quoted 7 lines
Call
virtio_gpu_destroy_udmabuf()before the early return to close the fd. This function already handles partial state correctly: it skips the munmap whenres->remappedis NULL and closes the fd whenres->dmabuf_fd>= 0.Fixes 9b60cdf98723 ("virtio-gpu: Add udmabuf helpers")Signed-off-by Marc-André Lureau <[email protected]>
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