mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jayapal Ashwin Nair <jayapalashwin.nair@amd.com>
To: <dri-devel@lists.freedesktop.org>, <zack.rusin@broadcom.com>
Cc: <linux-kernel@vger.kernel.org>,
	<bcm-kernel-feedback-list@broadcom.com>,
	<maaz.mombasawala@broadcom.com>, <mripard@kernel.org>,
	<maarten.lankhorst@linux.intel.com>, <tzimmermann@suse.de>,
	<airlied@gmail.com>, <simona@ffwll.ch>,
	<jayapalashwin.nair@amd.com>
Subject: [PATCH v2] drm/vmwgfx: Fix UAF race between dumb buffer creation and surface unref
Date: Fri, 20 Nov 2026 00:37:05 +0530	[thread overview]
Message-ID: <20261119190705.11305-1-jayapalashwin.nair@amd.com> (raw)

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@amd.com>
---
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@kernel.org

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

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


                 reply	other threads:[~2026-11-19 19:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119190705.11305-1-jayapalashwin.nair@amd.com \
    --to=jayapalashwin.nair@amd.com \
    --cc=airlied@gmail.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=maaz.mombasawala@broadcom.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    --cc=zack.rusin@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®