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=1795046203; b=DTS6JsO6zf2KltstAkCyQ2KLbx+Af3XVJcLG1ZbiCjMcp+tQhEq68xTQy2174VThfjMD jvT5+Zs52SPF32gGG09cvnypMypj1HKt+/bHA8879PZQ6te2JFu8uJI0YAfnhZu1iAL+F NDB9SEFAS5dQBEvpCzoUB918gdCcG1pO9w4+2Hw5UJTsAu51dYQxx4Tu7wLq9xLvDbWnf xm+5r0wId3pVhUw6IRK7aeabqSNoJMO1eQx7BaaMBeTqrkh9BdYrtzxsVqgwUPQup7k7p HWh2O37S93j+p1yRdpavzBxMMIp8yW+xPWqZip2ZmQH2Ul7tFdPE6T6N3fnIGBrEg6Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795046203; 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-Type:Content-Transfer-Encoding; bh=Bw1HlXjhBPNOeqSm2+g+us0Pu8jo+oVDxFKTKC8GTvM=; b=YwnANYipTgXc3r9nS/9cVTtTqcPm9rGdDbKBgbVI7cWYjbuh5RsWCk4S7EIhIrtwlg4x QpbygL+NA7wzf1sPdFFS13GIrLCWIyakUsMBCqx5j0T/Gh6rlXYVQ9EoSzgx6ECeycwRZ i/prFG4EnK3GbSQMb/z1UYt7/pTV0U1kOF2fh+Vsrl7Blk0spSKFXX4CzdmvWRl183Vhr VSgwYIhBN2qnXjll++Rlb4cqTFwtav/iUXSAQOKqEd2aqpqPotgm7bEgCV4HmMx/J/Ye0 9HvnphuJ3WV7RjtAQmgRqvVVyCocW5T/6Ti+T3DeaYXfyX86WS8AMKrtXLXmw99EBwQ== 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=yAzuC8os; 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 89AAE606A33D; Wed, 18 Nov 2026 23:56:43 +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=yAzuC8os Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB5C21F000C9; Wed, 18 Nov 2026 23:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795046203; bh=Bw1HlXjhBPNOeqSm2+g+us0Pu8jo+oVDxFKTKC8GTvM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=yAzuC8osEesVdId7fH7axZeIH7VYUYWNsQ6o+xoFqnNMbXCQWxGGLYcHnIWcUmIo6 UDDINulisD1tbXWrN1gtaezrDUFV+f5MMeSsAj31Q5m7SnIbctnKOrb/aufpdWrt6u cvXGy4xdk95I7Fl0fUu2q/WnCwX76HsXunX7N6y8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Andr=C3=A9=20Draszik?= , Philipp Stanner , =?UTF-8?q?Christian=20K=C3=B6nig?= , Sasha Levin Subject: [PATCH 6.1 1196/2857] drm/drm_crtc: ensure dma_fence_ops remain valid during device unbind Date: Wed, 18 Nov 2026 15:37:10 +0100 Message-ID: <20261118150244.682415989@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150201.293410965@linuxfoundation.org> References: <20261118150201.293410965@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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: André Draszik [ Upstream commit 3be436cbd3d265fe4fcfbb5b650edad7b2108443 ] In [1], sashiko reported the following issue: === snip === Looking at how these fences are managed, drm_crtc_create_fence() creates a dma_fence without taking a reference to the drm_device or drm_crtc. Because the sync_file framework exposes this fence to userspace, the fence can outlive the CRTC. The dma_fence contract requires that data accessed by dma_fence_ops (like get_driver_name) must remain valid for an RCU grace period after the fence is signaled. However, drm_crtc_cleanup() and the subsequent freeing of the device do not wait for an RCU grace period via synchronize_rcu(). If userspace calls ioctl(SYNC_IOC_FILE_INFO) concurrently with a device hot-unplug: CPU1 (Userspace) sync_file_get_name() ops = rcu_dereference(fence->ops); if (!dma_fence_test_signaled_flag()) // Preempted or delayed here CPU2 (Driver Teardown) Signals the fence (setting fence->ops = NULL) Destroys and frees the CRTC without waiting for an RCU grace period CPU1 (Resumes) ops->get_driver_name(fence) -> drm_crtc_fence_get_driver_name() crtc = fence_to_crtc(fence); // Casts to the freed CRTC return crtc->dev->driver->name; // Use-after-free ... Does the CRTC or DRM device need to be kept alive for the RCU grace period, or should the fence hold a proper reference to prevent the use-after-free when get_driver_name() and get_timeline_name() access the freed CRTC structure? === snap === I believe this to be a correct observation and this patch implements the suggestion of waiting for an RCU grace period before proceeding with destruction of the drm_crtc, so that get_driver_name() and get_timeline_name() can still work. Link: https://sashiko.dev/#/patchset/20260618-linux-drm_crtc_fix2-v1-1-c03e77b36f34@linaro.org?part=1 Fixes: 6d6003c4b613 ("drm/fence: add fence timeline to drm_crtc") Cc: stable@vger.kernel.org Signed-off-by: André Draszik Reviewed-by: Philipp Stanner Reviewed-by: Christian König Link: https://lore.kernel.org/r/20260721-linux-drm_crtc_fix2-v3-1-afa8c71506e6@linaro.org Signed-off-by: Christian König Signed-off-by: Sasha Levin --- drivers/gpu/drm/drm_crtc.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 65f9f66933bba..6b210bfd6ac0d 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -489,14 +489,23 @@ EXPORT_SYMBOL(__drmm_crtc_alloc_with_planes); * drm_crtc_cleanup - Clean up the core crtc usage * @crtc: CRTC to cleanup * - * This function cleans up @crtc and removes it from the DRM mode setting - * core. Note that the function does *not* free the crtc structure itself, - * this is the responsibility of the caller. + * This function cleans up @crtc and removes it from the DRM mode setting core, + * after first waiting an RCU grace period to ensure @crtc->dev can safely be + * dereferenced by our dma_fence_ops. + * + * Note that the function does *not* free the crtc structure itself, this is the + * responsibility of the caller. */ void drm_crtc_cleanup(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; + /* Ensure our dma_fence_ops remain valid for an RCU grace period after + * the fence is signaled. This is necessary because our dma_fence_ops + * dereference crtc->dev. + */ + synchronize_rcu(); + /* Note that the crtc_list is considered to be static; should we * remove the drm_crtc at runtime we would have to decrement all * the indices on the drm_crtc after us in the crtc_list. -- 2.53.0