]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/vmwgfx: drop dma_buf reference on foreign-fd prime import
authorZack Rusin <zack.rusin@broadcom.com>
Tue, 5 May 2026 22:22:26 +0000 (18:22 -0400)
committerZack Rusin <zack.rusin@broadcom.com>
Mon, 27 Jul 2026 15:29:24 +0000 (11:29 -0400)
ttm_prime_fd_to_handle() returns -ENOSYS when the imported fd's
dma_buf->ops do not match the ttm_object_device's ops, but does so
without releasing the reference acquired by dma_buf_get().  Any
unprivileged renderD client passing a non-vmwgfx prime fd through the
DRM_VMW_GB_SURFACE_REF{,_EXT} path leaks one dma_buf reference per
call and indefinitely pins the foreign exporter's GEM resources.

Funnel the error path through the existing dma_buf_put() so the
reference is always dropped.

Fixes: 65981f7681ab ("drm/ttm: Add a minimal prime implementation for ttm base objects")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4.7
Signed-off-by: Zack Rusin <zack.rusin@broadcom.com>
Reviewed-by: Ian Forbes <ian.forbes@broadcom.com>
Link: https://patch.msgid.link/20260505222728.519626-6-zack.rusin@broadcom.com
drivers/gpu/drm/vmwgfx/ttm_object.c

index 2421b0dd057c01d1cdd8ca14689707f0a9d9b6fa..f9042bafdc938e423dffeb65d9fc62e9b749ed45 100644 (file)
@@ -547,14 +547,17 @@ int ttm_prime_fd_to_handle(struct ttm_object_file *tfile,
        if (IS_ERR(dma_buf))
                return PTR_ERR(dma_buf);
 
-       if (dma_buf->ops != &tdev->ops)
-               return -ENOSYS;
+       if (dma_buf->ops != &tdev->ops) {
+               ret = -ENOSYS;
+               goto out;
+       }
 
        prime = (struct ttm_prime_object *) dma_buf->priv;
        base = &prime->base;
        *handle = base->handle;
        ret = ttm_ref_object_add(tfile, base, NULL, false);
 
+out:
        dma_buf_put(dma_buf);
 
        return ret;