From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD5893A9017 for ; Wed, 8 Jul 2026 15:22:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783524131; cv=none; b=OFlBwp6ggCxx8Yn3hytl1mIgy2/uSPBdVeQrDCG4Rwuc3N4xduIhQUuCXdSnbPEAu3Na7bjT5k4BT3SfOVeTgcbnyMa73TOsONlUShpaFHDZfLlJ2CsjGUDXkbbJrVj16B+M3/HXnewS2UJCH03OCusXSHb8hLl0r2NS0mYWAQs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783524131; c=relaxed/simple; bh=NAe5ipfAWpbnz6hRDdeQSkmmoh9BsNhifBuHOhAQsgU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BtEKkBlfW2C+kqX0lsJIG8IdTLZP0bWaOdss7zCwImz5COHTqZPQ09O03D0zGIwM5uBJbJ5morE3iG45k6oM7fV2GPDxBtDTeWiOxgserMWrZ5u4W6wAJfUveLq1Ke86aI+i2KXGbWGePVIbb7U2vUl+gVqC0t650liJXE0b+y8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=oKCQhpiQ; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="oKCQhpiQ" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-69a5ecbbfb2so1427427a12.2 for ; Wed, 08 Jul 2026 08:22:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783524128; x=1784128928; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=RZIUQ8lhybvuqUO/Qu4fqmCKQSSQtg8HD8yQYy4im0M=; b=oKCQhpiQCa2dwzFjxUvNxgyJJl+dqtwc6st1Rj72vJL1ensrH1/5ilfNV0fS7AzIb4 Q2vtHCy+an+l8YC7CYjZH9uZGuVHyorH0Nc0gTwtdUX6HekGBtdxDt89JtMlk8RHc5NR epTrZiaz5VA27dJgDYr0TnOJyTApavcs6Z37XyCVCmEeRVSyETNFEa69IqazW/7+eqRr RpspogJm+uzzh8l/YMMKwhCt8l1APi3SlV1xLbTsNox6kJ+A8+bHxuY8zB7dQ9EkN0NW k5Pv4p0I2dZGM7PgsvtX+C2PAObFsBK4wUmNY2KaVr488sd/v5+I8r3xQSfnbJxNc6QK UBEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783524128; x=1784128928; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=RZIUQ8lhybvuqUO/Qu4fqmCKQSSQtg8HD8yQYy4im0M=; b=jGMFxdDU9B7g8AwVIAe1PfEUBtTcOuJhdH8StmYySQVL2y2/5bo2ui6aw2Ae1fCFZ0 ndInKAx9+1IEXJyJmGD+HSSt4sL/g3b8VTT2pvyDI39V+bHc/EIFqllikCuhJPyz6KuG ursxVie25tedeQFU4RFsZx8PqIvBX4iKZ4xzTBCR+t9b0sz308WwuKEv5qfFuZFLJKg6 QkDlv/4P8vYKTc2O8lR/NtoheN1kyHSZwYIFla7SQfA3ywFh0kMpBrl3tUHTzK5khf6C ZWEDQuXokjzPzAYZfTb6Esq1I3hDaS8RtfJTtC2hRdJEsfih2orBZefUSfsa8yOdPA8O NTHg== X-Forwarded-Encrypted: i=1; AHgh+RryTUWaJwXI9c4msdQ7f/16i0P1L3Nbfp2tRoJgxya4Dimw05ZavMmiqSXV6CvDbS/6lDZLUgt+ZuAlZG0=@vger.kernel.org X-Gm-Message-State: AOJu0YyJE44EbWRu82uEQnvA7CTu3SxHkiJszn9rqmA5F4PQgBKDZKi6 mM3v8ruyLBLw5NxuUPECFHEuazvgNLIwhqHkqUdpHcyEK3ALA1mBPHWzb9BW55dk8PC5+7UJjKe 2bZiO9hw= X-Gm-Gg: AfdE7ckSN/XnF/Jcdnr2EfdjgGhNBOFx3ZAH1pRFyiYXGAFIP1JT2qXcB+LvF/g9nzL 21fFmUzCYI/rrCnkfWjcRb85213EbwBud4Uq1oKUq4igP8izRzZyZDpq6h9Ev6210ni5Qw5xbba tmerAb2tdNoB3uEHzJQFzVb09Ra5Ex1S3C1fBivWr0IV/Pxo1dOYWMnr4SKT2c1rQ2M6MMrNwL+ ZtYZAl2xklh51Zp3BbYS1ccwHkzfxrIPrdxIJwRfTZGNtuGcewRw0w94OBpQd4rGo3lg/kk16fQ /nh0oYJVMBEqFIUFcmP2RrSE5nOBVzMR4OCsXoqWxr73+yGL48tKqcoBco8RwO1Ki8nwIDdUQkl IkVaxHswyV9+88HS9G1ldE+yo1Js1HFheSQMmK74nsq8ezQmkCemVblWfATELXEf+lwd6CxYml0 p8iFAarpQFe2koOusydEkg1WK+YcYb1Mhns1ZJD4Kwof/Rs32J6/nO1/2PTGsq0LWIChsdceBIi HqLFlU= X-Received: by 2002:a17:906:f0d1:b0:c15:cc30:6c70 with SMTP id a640c23a62f3a-c15ce0c06damr103325566b.42.1783524128259; Wed, 08 Jul 2026 08:22:08 -0700 (PDT) Received: from puffmais2.c.googlers.com (181.179.204.35.bc.googleusercontent.com. [35.204.179.181]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c15beb53b86sm213932966b.25.2026.07.08.08.22.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2026 08:22:07 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 08 Jul 2026 16:22:05 +0100 Subject: [PATCH v2 1/2] drm/drm_crtc: ensure dma_fence_ops remain valid during device unbind 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: 8bit Message-Id: <20260708-linux-drm_crtc_fix2-v2-1-cf72be75d75a@linaro.org> References: <20260708-linux-drm_crtc_fix2-v2-0-cf72be75d75a@linaro.org> In-Reply-To: <20260708-linux-drm_crtc_fix2-v2-0-cf72be75d75a@linaro.org> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Tvrtko Ursulin , Boris Brezillon , Philipp Stanner Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, Peter Griffin , Tudor Ambarus , Juan Yescas , kernel-team@android.com, =?utf-8?q?Andr=C3=A9_Draszik?= X-Mailer: b4 0.14.3 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 Signed-off-by: André Draszik --- drivers/gpu/drm/drm_crtc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 63ead8ba6756..d55f1377ec36 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -501,6 +501,12 @@ 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.55.0.795.g602f6c329a-goog