From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380754; b=F1Vka+7/w5YEvji6zo9xxDIbgZ0JdlmsW/+K8VqUIB9RTBnmkDthW2MQGAvw5GEEcTli xFGQYzxrt2udqIgQZig2j9UxEjkNafrODUuojRbyql4k7Gmch07Tz9GbeNY40OPMLsQjZ uoSvjakRPV38k6yOxg5R1FaCsKqzu1fyTmInqzO+TSaX1yY9+os1OeKv6iR/yjjYD6meZ nXy3v9YnctkQF6GUgCLsjQ6JLSmjIEywtD80s7oSLlyho5m+ZlfNSxhC+Lvs+YW7xsrfK nGjyiCI6rXVWvAnmY0PSGlqrbXaW0e4AnvPLThHAESj6nlOlOcspwcJNNBTi5ItVTgQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380754; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=JD806ShCFpT/kktxAt4JSSFE3dPjhM8J7Zi+9A37f7E=; b=SmYwXxR9MaDnaxOs6qVD7VE+2P/ee8pisb/O8spN4tGkWbFKmNJWZUdex9oZKKAIjj0t WpnZ08uNB1cnFSqmqiY29KgExz5e2fToIR2VEDFA24GAH73q9SUOi7bl9BpX1FgngZE4Q EA7xLPG20rmnAjHk6CYb+cudfldioscbQfsnEas75sVvIVv09MZRWdUUcUMg0KTqlF4vF YHXY+CECGJTXteL80S+rsaJP8IYHoJ4SF9bL8Ghz7jmndJe0Eq2V7ZGdY4NFprPMAjZ2K UjCEE1ARt1gxEHUpe/MwM89GRm0cgaed+i/7uGK4jmYxe0FuMfhALBlMYHaBLuAfpbQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=H4cLR7Xz; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 338E4606A330; Fri, 4 Dec 2026 10:39:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=H4cLR7Xz Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1B7D1F000CE; Fri, 4 Dec 2026 10:39:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380754; bh=JD806ShCFpT/kktxAt4JSSFE3dPjhM8J7Zi+9A37f7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=H4cLR7XzkMy49jR+1iVhMHSz3bfJ1jRdPXkQHeqlsZ5Ly5I29RYs15ONqXIMWr+Sw +uuRwaiBUBSLwvokxkFW/xPybeahIDteFE/XrRUcz/rtJ24/9Wm04ttdKq1Oyy19oE 2R/eCgvHYap+hcw2fgrj6uqPWrvZI9bP9FzUBVjk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jaeyeong Lee , Zack Rusin Subject: [PATCH 7.3 411/742] drm/vmwgfx: Erase the detached resource entry on resource release Date: Fri, 4 Dec 2026 19:04:35 +0900 Message-ID: <20261204100646.020286446@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jaeyeong Lee commit c4b134969ce350cdd4e726b5102b85b8a2d6fad5 upstream. vmw_bo_add_detached_resource() stores a raw struct vmw_resource pointer in bo->detached_resources without taking a reference on the resource, and the only place that erases the entry again is vmw_resource_mob_attach(). A resource that is never validated, and therefore never attached to its backing mob, keeps its entry until the buffer object itself is destroyed. vmw_resource_release() detaches the resource from the mob RB tree and drops its reference on the backing buffer object, but leaves the detached_resources entry in place. Userspace can hold an independent GEM handle on that buffer object, either because DRM_VMW_GB_SURFACE_CREATE returned one in rep.buffer_handle, or because DRM_VMW_GB_SURFACE_REF minted one with drm_gem_handle_create(). The buffer object then outlives the surface while still holding a pointer to freed memory. Any later surface lookup for that buffer object dereferences it: vmw_prime_handle_to_fd() vmw_lookup_surface_handle_for_buffer() vmw_lookup_user_surface_for_buffer() vmw_bo_surface() res->func->res_type <-- use-after-free read vmw_bo_surface() walks detached_resources before the mob RB tree, so the stale entry is matched first. The kref_get_unless_zero() in vmw_lookup_user_surface_for_buffer() does not help here: it runs after the dereference, and struct vmw_user_surface is freed with kfree_rcu() on a slab that is not SLAB_TYPESAFE_BY_RCU, so the memory is handed out to unrelated allocations once the grace period elapses. A sequence that reaches this from userspace is to create a guest-backed surface with drm_vmw_surface_flag_create_buffer, never validate it, release it with DRM_VMW_UNREF_SURFACE, and then call DRM_IOCTL_PRIME_HANDLE_TO_FD on the buffer handle returned by the create ioctl. All of the ioctls involved are DRM_RENDER_ALLOW. Erase the entry next to the existing vmw_resource_mob_detach() call, so that a released resource is removed from both containers, mirroring what vmw_resource_mob_attach() does. The dumb buffer teardown path in vmw_bo_free() clears res->guest_memory_bo before dropping its surface reference, so it does not reach this code and is unaffected. Fixes: d6667f0ddf46 ("drm/vmwgfx: Fix handling of dumb buffers") Cc: stable@vger.kernel.org Signed-off-by: Jaeyeong Lee Reviewed-by: Zack Rusin [zack: rebased; dropped the v7.2-rc4 analysis note from the commit message] Signed-off-by: Zack Rusin Link: https://patch.msgid.link/20260725143859.797134-1-finpiler@protonmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 1 + 1 file changed, 1 insertion(+) --- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c @@ -138,6 +138,7 @@ static void vmw_resource_release(struct } res->guest_memory_dirty = false; vmw_resource_mob_detach(res); + vmw_bo_del_detached_resource(res->guest_memory_bo, res); if (res->dirty) res->func->dirty_free(res); if (res->coherent)