[PATCH v2] drm/vmwgfx: Fix UAF race between dumb buffer creation and surface unref

From: Jayapal Ashwin Nair

Date: Thu Nov 19 2026 - 14:09:20 EST


vmw_dumb_create() hands the surface's TTM base reference to
vbo->dumb_surface by clearing refcount_release, but the surface handle
is already visible to userspace. A concurrent
DRM_IOCTL_VMW_UNREF_SURFACE can release the TTM base first, and its
destructor drops the reference the vbo was meant to inherit:

CPU0 (MODE_CREATE_DUMB) CPU1 (VMW_UNREF_SURFACE)
vmw_dumb_create()
vmw_gb_surface_define_ext_ioctl()
vmw_user_resource_lookup_handle()
vmw_user_surface_base_release()
vmw_resource_unreference()
refcount_release = NULL
vmw_resource_unreference(&res)
vmw_resource_release()
vmw_user_bo_unref() /* drops the GEM handle's ref, vbo freed */

The dumb buffer's GEM handle is left pointing at the freed vbo, and
DRM_IOCTL_GEM_CLOSE on it is a use-after-free.

Take a counted reference for vbo->dumb_surface and leave the base
destructor armed, so the base and the vbo each drop only their own
reference. Drop the WARN_ON() in vmw_user_surface_base_release(),
which no longer holds.

Fixes: f42c09e614f1 ("drm/vmwgfx: Fix dumb buffer leak")
Signed-off-by: Jayapal Ashwin Nair <jayapalashwin.nair@xxxxxxx>
---
v2:
- Rework: take a counted surface reference for vbo->dumb_surface
instead of only reordering the GEM put.
- The GEM put is still the last access to the vbo in
vmw_dumb_create(), so the v1 GEM_CLOSE race stays fixed. The
ttm_base_object use-after-free Sashiko reported on the GEM_CLOSE
path is also closed, since the base now keeps its own surface
reference:
https://lore.kernel.org/sashiko-outbox-188756@xxxxxxxxxx

v1: https://lore.kernel.org/7a822adb-ddb5-4338-8949-3ccb0942e0a0@xxxxxxx

I plan to send a separate IGT test later for the unref and
GEM_CLOSE races, thanks for review and suggestion!

drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
index bd0563741e89..942d2f39332b 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
@@ -666,13 +666,6 @@ static void vmw_user_surface_base_release(struct ttm_base_object **p_base)
struct vmw_resource *res = &user_srf->srf.res;

*p_base = NULL;
-
- /*
- * Dumb buffers own the resource and they'll unref the
- * resource themselves
- */
- WARN_ON(res && res->guest_memory_bo && res->guest_memory_bo->is_dumb);
-
vmw_resource_unreference(&res);
}

@@ -2331,15 +2324,9 @@ int vmw_dumb_create(struct drm_file *file_priv,

vbo = res->guest_memory_bo;
vbo->is_dumb = true;
- vbo->dumb_surface = vmw_res_to_srf(res);
+ /* Owned by the GEM handle, dropped in vmw_bo_free() */
+ vbo->dumb_surface = vmw_surface_reference(vmw_res_to_srf(res));
drm_gem_object_put(&vbo->tbo.base);
- /*
- * Unset the user surface dtor since this in not actually exposed
- * to userspace. The suface is owned via the dumb_buffer's GEM handle
- */
- struct vmw_user_surface *usurf = container_of(vbo->dumb_surface,
- struct vmw_user_surface, srf);
- usurf->prime.base.refcount_release = NULL;
err:
if (res)
vmw_resource_unreference(&res);

base-commit: 07940daf7b231273866376cc9657c09e47e7cef6
--
2.53.0