Received: from mail-244121.protonmail.ch (mail-244121.protonmail.ch [109.224.244.121]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FB7D16A395 for ; Sat, 25 Jul 2026 14:39:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.121 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784990361; cv=none; b=eOTHPvdulBG2nrlg5SC6l7oelcHPLvaSm2GFjK73RnbWn2a1CO5GyNaMAcQw/6blOOFx5vNP/g2dvC3qxXmfe3TxVOOc7mRkp9EkovNxVJAPHOU6N5uvj0g0QTX12k8L5nWNS3OiknnPOPfiVej4f/HSWsRZLsT34os5mufztlk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784990361; c=relaxed/simple; bh=PGyqoj2YzouwWpP6a1Edv317ZHcGOyJUgEK0FLA4r3k=; h=Date:To:From:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=GDsr247hCqdoDAGGRnMvXU1S5DqrLSy2KWxDEH2d+WQCwf0MURTeD36MMZCC7k27Fi0I6qwIL0KohjPUbvfpWHtIYZXpXJsNXBAPYoeF8b9jOPrb/MzRyhzsIImBxfzjhwDOTTt2S3j635NhUegWOs7HgYNvScX27ciqcqEaViA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com; spf=pass smtp.mailfrom=protonmail.com; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b=VOkpvHux; arc=none smtp.client-ip=109.224.244.121 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=protonmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="VOkpvHux" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1784990351; x=1785249551; bh=ZSqJ8G6LNPLKdZPFCDh1YfMgK45/NbQBo3gthXVVDk4=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=VOkpvHuxtjmDhSXgMyggeWDFGelJZvF1snZrtiloOcJDDCKcJ5DMugppVcYel1oYa GJ4T0WZ4ULRIJNcDc2tJqC8IevSjO9douUdsNZp+GSmRjTmghKXxxywVggMsqeEjDU 2GzwqI+EDSJEAZtk+e5Sx2wHkyRSTJ36p5GLoXlpBSkX9z9VGhvVn1VDKPwnGqwqVo qyuptpbk+9FI/LHS9S8QLMNyATtcFt0Fl7RwtQnoqHg/c08/O8yQbN8PJPnP5wR/lE kE1nw1T9GF5BrSFNStujgxvr0KjE9Qzc7R6HKIQPcFG4s1yG2U5v9Uqf+xlMn9BTdT gYdllGo9NtvIg== Date: Sat, 25 Jul 2026 14:39:04 +0000 To: Zack Rusin , bcm-kernel-feedback-list@broadcom.com From: Jaeyeong Lee Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Jaeyeong Lee Subject: [PATCH] drm/vmwgfx: Erase the detached resource entry on resource release Message-ID: <20260725143859.797134-1-finpiler@protonmail.com> Feedback-ID: 169948533:user:proton X-Pm-Message-ID: d22200b5a0ef8f3eb9e9808278ffd416512e0d94 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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=09=09<-- 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. The code was analysed on v7.2-rc4; the erase call site has been the same since the commit below. Found by code inspection, not by a runtime reproducer. 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 --- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmw= gfx/vmwgfx_resource.c --- 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 kref *kref) =09=09} =09=09res->guest_memory_size =3D false; =09=09vmw_resource_mob_detach(res); +=09=09vmw_bo_del_detached_resource(res->guest_memory_bo, res); =09=09if (res->dirty) =09=09=09res->func->dirty_free(res); =09=09if (res->coherent) -- 2.43.0