From nobody Sat Sep 26 05:27:46 2026 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 6523E3CF212 for ; Fri, 4 Sep 2026 08:06:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788509191; cv=none; b=RKmD95Mp6amPpqblEr4FdiLktFCm5AynQenvCJZ3qQ026UqnwXWIzB7+x3fd945nf20JwjYRer21WVWJD3hGqojPXgyNrWGSaznBN45ho5meECMW2Aj+yBqzaTXVzCXZM8dbwFOgP46JQ2ByuKvHO10yCLykXlI7s1xzMK538q0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788509191; c=relaxed/simple; bh=566pGj/JIlarQnjQku7K9YiHj6xZhXg/CQfHU+iJ6cc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QpHlbBGTKiEro5jyjU682iHZaWAgbmJHG9g5LtgAKDYCKP1QsZvXWSkOi9P9qWTOAOeVzP5XzjP+hbaXKYxJ9WUdLej+lT22ukN3a12WpDqqXgZhmbWlIe2Pvx2DWG5Do4IQZUG1yOWfImzbobEhVMG9rQK6S96QN2f5KTCHUa0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=k8xYTChI; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k8xYTChI" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-39b2ad862bdso456879a91.2 for ; Fri, 04 Sep 2026 01:06:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788509189; x=1789113989; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=OLEldnOCQedCUETCWprtecBudZpW3CKJjf9frld/ASI=; b=k8xYTChI64+l3BJLKiJ51OZEBJDYq2aqGmNL+YeFmkvFwKrl5jMs0h1LFBfrwkg4mZ o+DRr9+BBBKKsJG1WyGFthddkwQOaifqPidMXPvyc3t3gUvTlCG0nDbBUtFKtf0gHhDY Pyijrz2MOOg8bVhssx9s9HBTfccCUEZa6e5lRtpZ6VSbGEzln0xcvzAKIZQyuvQIIuGS I+4MKk/366/VEzYIMzZTBy3q4hNK34pgUTMIc/gs0DYdudmsY55Lvk2Qh4HUlQzRyj/f h2VSl8MFOzRYTyCyk6cgdTM97ZK9uXKBakkalxCTC0U5uWo6zEiUGqYcFwx8ns9yiXzp i1JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788509189; x=1789113989; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=OLEldnOCQedCUETCWprtecBudZpW3CKJjf9frld/ASI=; b=FHo8VQkNKnLdOeHR4zmPu1vjB+yI63NMZ9A3RkktTwSFxRnS9Mp5ozD8E7fxvb48nm fCbtSBJYtF2GrUCmmFzLZPondgsroV8Ojb0JIitVt3IM4dEO3KXEVVxvCsBrh/JMZ8A7 6qw7g9sLQ55NXLoAYB2ZufbfaHJT010ZWaShdtLc1roWccVofpobjKUg6BynugbTNqUa DE5PTJ8qJMZ8tn3g8eb8v3bugTz10iV44aF67gyQeCjAkfMvLT1i+jS9PLKasQ8kbnx3 GKJVwtDbYoZKKh3pRbovhM2kgb8lcWgDZ+yJmpCKYkaJqOOCkZ7Z6c3L6oeA9JrQNSz5 fsJQ== X-Forwarded-Encrypted: i=1; AKwUvBy6TOinE2GPDUJsVGCLv9537aXH04MaIBm9wtw3YbBm0PGpUohdCVBtw62TmE2C58Sz9kiZZpGSwTfHIYw=@vger.kernel.org X-Gm-Message-State: AFuF++ntIB6OOrB3zmsoFLqVM0Tjygno03rNM2Ul3HpZ1+zdD4KpKsEJ 7rgeLWN+R5XueiyplsCwYhHCRyuAKUc6sU2rDafGvHoE6rdqQgWH+1s= X-Gm-Gg: AYBFou1BkaGCx/6fxH6zoF4X2rPiiexmtqBnxh8VS6JfTSFLQqdPPdqhUVHa3ipUr3G DLjCRycN5Fq9+tPlNnZ7qE13jZ34t6QI91KF8HgJ9+m94lrhCP5MajJKE0zd1tXA+qbdG2xlqbW 5bJa/43/ht9h6R6fxd+7ln0dydWeH8qh1txuMdtVH5AYXtSlC1VM9RCeAtqgqL+SSW1FXCzzueH DsTQk9yYd0uoOL98wEQv2q6wMWyUoIqA2QSh50oJ8EaqwEC/T1im4Ls5QjsAe1qq+j0bC6GVRP2 ZEO1c25sSnK4SQyvcGWwqJGmWPwumyvoyWQBYF7QsyoASwUOn21CjluRGEmkYnk9RNN5BjKcwrO 7HIbymDMZGciDdAtHry7dCImd/S3EQvQo5aTPb+Dosz8bJUHjbtImmKrITd3j7ilB1dwTViIvzI m0LC4ccomsVWyGmXDGRv4y8Hd5x+ipuD8LID1L6tXWlzWcftZ14Kc75Te0eVYiq8lyQ6xXMPzT5 wG74vXPG7DIEYkhDblaYx/j5Ns= X-Received: by 2002:a17:90a:ec8d:b0:38e:67e1:15b with SMTP id 98e67ed59e1d1-39b261002f5mr6201345a91.6.1788509187124; Fri, 04 Sep 2026 01:06:27 -0700 (PDT) Received: from MalHyuk.localdomain ([211.201.32.99]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39b261549f3sm3181153a91.16.2026.09.04.01.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 01:06:26 -0700 (PDT) From: "Jonghyuk Kim(MalHyuk)" To: phasta@kernel.org, christian.koenig@amd.com, tursulin@ursulin.net, matthew.brost@intel.com, dakr@kernel.org Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, mdaenzer@redhat.com, alessio.belle@imgtec.com, luigi.santivetti@imgtec.com, "Jonghyuk Kim(MalHyuk)" , stable@vger.kernel.org Subject: [PATCH v4 1/3] drm/sched: cache the timeline name to fix a use-after-free Date: Fri, 4 Sep 2026 17:06:16 +0900 Message-ID: <20260904080618.2098450-2-malhyuk97@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260904080618.2098450-1-malhyuk97@gmail.com> References: <20260904080618.2098450-1-malhyuk97@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" drm_sched_fence_get_timeline_name() returns fence->sched->name, and the drm_sched_fence ops keep a .release callback, so the fence is not ops-detached on signalling (dma_fence_signal_timestamp_locked() only clears ->ops for fences without .release/.wait). The callback therefore stays reachable on a long-signalled, userspace-held finished fence and unconditionally dereferences fence->sched. A driver that allocates a drm_gpu_scheduler at per-context/per-queue/per-VM granularity and frees it on an unprivileged context/fd close, while exporting the resulting finished fence to userspace (drm_syncobj / sync_file / dma_resv), leaves fence->sched dangling after the free. A subsequent SYNC_IOC_FILE_INFO ioctl (which calls get_timeline_name()) then reads the freed scheduler: BUG: KASAN: slab-use-after-free in drm_sched_fence_get_timeline_name This is the same class as CVE-2025-38703 (drm/xe) and CVE-2025-71302 (drm/panthor), which were fixed per-driver. amdxdna, nouveau and msm (VM_BIND) are still affected in mainline, so fix it in the core to cover any per-context-scheduler driver at once. Cache the scheduler's name pointer in the fence at init time, while the scheduler is guaranteed alive, and return the cached value from get_timeline_name() without dereferencing fence->sched. The timeline name is not guaranteed by the contract to outlive the scheduler, so document in struct drm_sched_init_args that the @name passed to drm_sched_init() must follow the dma-fence safe access rules and outlive any exported fence. Every in-tree driver passes a string literal, which satisfies this; commit 299bc6d50b1b ("drm/xe/guc: Keep scheduler timeline name alive") keeps drm/xe's dynamically-allocated name alive across the RCU grace and can be simplified on top of this. Fixes: 506aa8b02a8d ("dma-fence: Add safe access helpers and document the r= ules") Cc: stable@vger.kernel.org # we don't know since when Signed-off-by: Jonghyuk Kim(MalHyuk) Tested-by: Jonghyuk Kim(MalHyuk) --- drivers/gpu/drm/scheduler/sched_fence.c | 24 +++++++++++++++++++++++- include/drm/gpu_scheduler.h | 18 +++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/scheduler/sched_fence.c b/drivers/gpu/drm/sche= duler/sched_fence.c index 096fe28aa9c9..b2a842a1c9ba 100644 --- a/drivers/gpu/drm/scheduler/sched_fence.c +++ b/drivers/gpu/drm/scheduler/sched_fence.c @@ -92,7 +92,13 @@ static const char *drm_sched_fence_get_driver_name(struc= t dma_fence *fence) static const char *drm_sched_fence_get_timeline_name(struct dma_fence *f) { struct drm_sched_fence *fence =3D to_drm_sched_fence(f); - return (const char *)fence->sched->name; + + /* + * Do not dereference fence->sched here: a userspace-held finished + * fence can outlive a per-context scheduler. Return the name cached + * in drm_sched_fence_init() instead. + */ + return fence->sched_name; } =20 static void drm_sched_fence_free_rcu(struct rcu_head *rcu) @@ -180,6 +186,14 @@ static void drm_sched_fence_set_deadline_finished(stru= ct dma_fence *f, dma_fence_set_deadline(parent, deadline); } =20 +/* + * TODO: Both fences implement .release, so dma_fence keeps their ops atta= ched + * after signalling. Dropping the callbacks would let dma_fence detach the= ops, + * after which neither get_timeline_name() nor get_driver_name() can run a= gainst + * a freed scheduler or an unloaded module - the complete fix. It first re= quires + * auditing every to_drm_sched_fence() caller, since ops-detach makes the = helper + * return NULL for a signalled fence. See Documentation/gpu/todo.rst. + */ static const struct dma_fence_ops drm_sched_fence_ops_scheduled =3D { .get_driver_name =3D drm_sched_fence_get_driver_name, .get_timeline_name =3D drm_sched_fence_get_timeline_name, @@ -228,6 +242,14 @@ void drm_sched_fence_init(struct drm_sched_fence *fenc= e, unsigned seq; =20 fence->sched =3D entity->rq->sched; + /* + * Cache the scheduler's timeline name. The finished fence may be + * exported to userspace and outlive @sched (per-context schedulers are + * freed on context teardown), so get_timeline_name() must not + * dereference @sched. The name is required to outlive any exported + * fence (see @name in struct drm_sched_init_args). + */ + fence->sched_name =3D fence->sched->name; seq =3D atomic_inc_return(&entity->fence_seq); dma_fence_init(&fence->scheduled, &drm_sched_fence_ops_scheduled, &fence->lock, entity->fence_context, seq); diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h index 7a64cc11de08..412b8c4643f1 100644 --- a/include/drm/gpu_scheduler.h +++ b/include/drm/gpu_scheduler.h @@ -322,6 +322,17 @@ struct drm_sched_fence { * belongs to. */ struct drm_gpu_scheduler *sched; + /** + * @sched_name: the timeline name of @sched, cached at init time. + * + * &drm_sched_fence.finished may be exported to userspace (via a + * sync_file or drm_syncobj) and can outlive @sched: a driver using a + * per-context scheduler frees it on context teardown while a + * userspace-held finished fence still references it. The + * get_timeline_name() callback must therefore not dereference @sched; + * it returns this cached name instead. + */ + const char *sched_name; /** * @lock: the lock used by the scheduled and the finished fences. */ @@ -646,7 +657,12 @@ struct drm_gpu_scheduler { * @timeout: timeout value in jiffies for submitted jobs. * @timeout_wq: workqueue to use for timeout work. If NULL, the system_wq = is used. * @score: score atomic shared with other schedulers. May be NULL. - * @name: name (typically the driver's name). Used for debugging + * @name: name (typically the driver's name). Used for debugging, and as t= he + * dma-fence timeline name of the scheduler's fences. It must follow the + * dma-fence safe access rules: a &drm_sched_fence.finished exported to + * userspace can outlive the scheduler, so @name has to outlive any such + * fence - use a string literal, or free it only after an RCU grace period + * past the last exported fence. See drm_sched_fence_get_timeline_name(). * @dev: associated device. Used for debugging */ struct drm_sched_init_args { --=20 2.43.0 From nobody Sat Sep 26 05:27:46 2026 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.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 1D5143DA5B7 for ; Fri, 4 Sep 2026 08:06:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788509192; cv=none; b=pppxrsbwDUfA+5fH5mS1FSUXhethS45NHE0qBxZzCZUpEVJyIVu5/caPPoQpYAbsmCssbXBIY8s4XeS623ocKxk3KH1JVT5mAXPk1ZJNpmZ8aeiYPyYrkWSBTSjDv6Qp37i//4ocuBk2rVdHghplwHitSGWxYerU9no2N2fmtlM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788509192; c=relaxed/simple; bh=jJufBHy0XOHSgCuO4Zat9GBLKTZbHQ5kUy9KcZGBSaw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BAsaBJDzTq7lxAvxd+G5LBad8IjFgC7ZXx2GPoAkbnZJITlBamf/T92x0M8N6U88fEM+UVcoZzjkESNWp0hVza+7zp7QEk5HoOAnDqumqez08uJSSZTLg7MEfNBsl3Sj9bXYOPIggPr+FkY+q5lZw001I7jfQwaSpgO8gqympsE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cvIi2z3G; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cvIi2z3G" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-383b4a3755fso720381a91.3 for ; Fri, 04 Sep 2026 01:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788509190; x=1789113990; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=QTyILQ3Nb9xTYITTyUAAxXfDx2OTqAg1QFKIj6VFxCw=; b=cvIi2z3G/FyEPlEM6kzAS6FschP+zDTysHgRwMIBTKxUESG7Fqmt/rX/sOpqikxbWV U8qvJj7JyO/1hraa/mIU/rJaUdpUfpr78ZROhArNK70kcGO5Z5QucDfdyQAlMF6ZroF9 EWg9Z3s4hZ3ujb0/FJYPpk1fT9KUtCG6f1sygpNKaMniDhRdJwmjZfBqLCB9AAb1yPLH WmlqDOlxW61lL0E5Z+uS5xAgtAIdEx91tGOXQiepw9BVL4r3BeFNGrrez5fbDH1k9+x2 uvUY1Na2nZVuKbW82katZfLp4Xy/FLFiKNGdv+RzNxyZzYL6X0G8lKIc2YwParGSbryh djmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788509190; x=1789113990; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QTyILQ3Nb9xTYITTyUAAxXfDx2OTqAg1QFKIj6VFxCw=; b=aRnKEjKhYj9mDH98HobVna3zyYOA5gyWfKeGzKQIjWvPNFBLKS8NyPL6jyxUGpiRHY JjrqsETGW+TZuDnILQhmqdW3WOMwWAcrlebp1Cus+IpEU4RKaP4qKiAPL+cC1ulD5EXD bTwNNHE3YMv3PuK+BGBoyDQMclQsWj8pEDpKWLSc3KV1ob3+zvf7N+GFGvOdCtKvyLIK /suJ7yVMODEWCyjgvSBDsfiB8iBzafvX2ub5BnM8neJPznv/ranI5qf4zyOhYw4H8a5k AAltVlTNs850eK2CAO1HmShcDXqUuEJHQmoQqLP0zNln0ichGFDrhjbL9tY10lNB+knk bA+A== X-Forwarded-Encrypted: i=1; AKwUvBzmea6zSSTwMbPeV5TEoOcNNHgYipfbLSKqLoA/jiDA3WrY7BmurXVN/1dDVpSmGUyGSfsBd4U7Rjsy6nc=@vger.kernel.org X-Gm-Message-State: AFuF++nhTV8yXOaAr8OhlmEvjyQA7zNnR/5S6U6+8KxZmCIP3IT58VU9 0/hDgbkbTMyu8Vc9CPVDTcgy2ebfYkQZJN3RfEKbNM47oxYENoBH4fM= X-Gm-Gg: AYBFou35ur8nKkJlhDGUqRrk7FExEc7zqqQaHTNVV4g/yflC+fPyWWl84Jn1X1PoNjg QOAcdSSsBtSLZpqCuKt9LtDAYjx/97i0vjB5+oGtijCFrZ4SdOB6zrFbsc45HnmeQQTTlGve2Zx LnncUZoyky0SemcHRPlfhNRe3NN37mcavcT0lyM0FxUpXbc9K1URdInxka7wjjy00dwrVrU60K5 B7f2YS4ffuQMcUX7Iep88osGaiS+GrtzdKt0nMAYzo+wny2FRhv00cX3SQ1/FYnZ8DaVs/L3O4u qI+DmL87vtYEatIhZchrS+M3Jo//ma3d4yDIImIMX1Aj1u14i+Sosn5v2X6FI3xzv03rs/pkhcZ lYQetivtp6h4LGOBuCO0aIMpmKeVQPBP27MtLruYqt85hBhlbSwQQDtL9ls39UtooCYWnR852by ppvFBYPQMas+8iAuAkr/4lzuPvg9dugUjc4QB73BesWxsWG3pgeqelHh63Hq5vzQQQt5SrjzEmG jIsS3USRWM8dBZqE708jDl8RCI= X-Received: by 2002:a17:90b:28cc:b0:36d:b424:4f17 with SMTP id 98e67ed59e1d1-39b260e13d5mr7636395a91.1.1788509190441; Fri, 04 Sep 2026 01:06:30 -0700 (PDT) Received: from MalHyuk.localdomain ([211.201.32.99]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39b261549f3sm3181153a91.16.2026.09.04.01.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 01:06:29 -0700 (PDT) From: "Jonghyuk Kim(MalHyuk)" To: phasta@kernel.org, christian.koenig@amd.com, tursulin@ursulin.net, matthew.brost@intel.com, dakr@kernel.org Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, mdaenzer@redhat.com, alessio.belle@imgtec.com, luigi.santivetti@imgtec.com, "Jonghyuk Kim(MalHyuk)" Subject: [PATCH v4 2/3] drm/sched: add the fence ops-detach cleanup to the TODO list Date: Fri, 4 Sep 2026 17:06:17 +0900 Message-ID: <20260904080618.2098450-3-malhyuk97@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260904080618.2098450-1-malhyuk97@gmail.com> References: <20260904080618.2098450-1-malhyuk97@gmail.com> 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 The previous patch caches the timeline name so that get_timeline_name() no longer dereferences a scheduler that a userspace-held fence has outlived. That is a targeted fix: the underlying reason the callback is reachable at all is that both drm_sched fences implement .release, so dma_fence never detaches their ops on signalling. get_driver_name() has the same exposure for module unload. Dropping the .release callbacks is the complete fix, but it requires auditing every to_drm_sched_fence() caller (ops-detach makes it return NULL for signalled fences), a different identity mechanism for pvr_queue_fence_is_native(), and a rework of the shared allocation's reference handling. Record that as a TODO entry so the cleanup is not lost. Suggested-by: Philipp Stanner Signed-off-by: Jonghyuk Kim(MalHyuk) --- Documentation/gpu/todo.rst | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst index 14cf37590fc7..284aeba3c752 100644 --- a/Documentation/gpu/todo.rst +++ b/Documentation/gpu/todo.rst @@ -990,6 +990,45 @@ Contact: =20 Level: Beginner =20 +Detach the scheduler fence ops on signalling +-------------------------------------------- + +The dma-fence contract forbids touching driver-provided data - everything +reachable through &dma_fence.ops - once a fence is signalled. dma_fence en= forces +that by detaching a fence's ops on signalling, but only for fences that ca= rry +neither a .release nor a .wait callback (see +dma_fence_signal_timestamp_locked()). + +Both drm_sched fences implement .release, so their ops stay attached forev= er. +That leaves the callbacks reachable on a long-signalled fence that userspa= ce +still holds through a sync_file or drm_syncobj, even after the scheduler is +gone: get_timeline_name() used to dereference the freed &drm_sched_fence.s= ched +(fixed by caching the name), and get_driver_name() can still return a stri= ng +literal belonging to a module that has since been unloaded. + +Dropping the .release callbacks so that the ops are detached on signalling= is +the complete fix, and it is what the dma-fence rules ask for. It is not +straightforward: + +Tasks: + +- Audit every to_drm_sched_fence() caller. Detaching the ops makes the hel= per + return NULL for a signalled fence, and callers such as + amdgpu_cs_p2_dependencies() and amdgpu_ctx_fence_time() dereference the = result + unconditionally. +- drm/imagination uses the ops pointer as an identity test in + pvr_queue_fence_is_native(); that needs a different mechanism. +- Rework the reference handling. The scheduled and the finished fence shar= e one + allocation, and the finished fence's .release currently drops the schedu= led + fence's reference, so the callbacks cannot simply be deleted. + +Contact: + +- Philipp Stanner +- Christian K=C3=B6nig + +Level: Advanced + Outside DRM =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 --=20 2.43.0 From nobody Sat Sep 26 05:27:46 2026 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 A747F3DD502 for ; Fri, 4 Sep 2026 08:06:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788509196; cv=none; b=P7S7fekLwmlWF+BvxUKryoeP7LCk2jftRObVNdTS8r6t2akcktKzf6Ilbd2zsM6XDpeYgVxolzpez0XiPVzumO8r054J3LYFSvHvDkir5YivhcCveM+Lbgov0bOBbLTVo6Bqja3PLvOg5TaXl+JJZEXIpA/+sC1p1PTZFeDb3xA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788509196; c=relaxed/simple; bh=dpLdFWVE3fNkRLtb33Mz6KWyINNfY9Yz5XOlg4KbKVc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YzyQCvpjU1JrFOMENQvBijO3+QNEXDWurysIzM9ssiP7k7jXS3niWesi4zn/bB6A7QYy0ugSi4VBa6ojtVw14/sGGp2jnw4TTxtiJ9lZwCBYG9z6T8H5rAfDEgPY5JdSP2wuRC0efZ8ZvNCTuGWqghE5oCbSVx40hKF72ph3SW4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=O4/s4bOU; arc=none smtp.client-ip=209.85.215.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="O4/s4bOU" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-cc2276e6daeso657595a12.0 for ; Fri, 04 Sep 2026 01:06:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788509194; x=1789113994; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QaFo74pEjy74IX81W7yJ+GS8RxmbNRM1kYRnfOPg9z4=; b=O4/s4bOUmvy1k+QNMyGD529KVrzwvffZNlD2Q4+rqzfhZ50CZ5AD15UNEAb/ftswwE fwi/uaJ1TGRbgQtJBsRww2Pqj4+l3lJFW7V6f+YVF60p5sx1PW6LklWTpzsgD9du5q53 tTn6ARSNCgFyUJSfn1LAAkstdXHsbBSHT1lBpL5Ou5hBVG0ot2lLb8kPwZNIbY3OaoRd toY8YZw+fhmRYgVYlgJ3Elo+QJUdP9aHgBoIpL7TEWgZuKC4aVlvaYmfAw+yEyId3wle Tghsl+8h8onpxl+7W8P3jUNiQLc0y9OvvLHjnh0jnrdCarNw5rwKOwXhhE4jKmVsIc73 Ct5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788509194; x=1789113994; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=QaFo74pEjy74IX81W7yJ+GS8RxmbNRM1kYRnfOPg9z4=; b=CHhpWB+jxZnjvjK1Wko49WwDQOTLodQktGWNlAW4AOf7AXeTM42QMWrFaEoq8Jett3 YeDT+srYIjBQI3XpTP3qedwWNVPXzW5Bt/rdVDrd73AJ3yRrJYSWBj3XngvY3kY7cQUs 1VCbrN+oyDy+hRBXo0OIPLGqxYSE+HHg4XRxyQDs3O14Iq7MHsi/9aIv1/XzZhuwBZp3 KZG1KpP1b8oFSxIHvL/oVfTBBVnZrG7aRNi2YPdSS0F+BUOQ+aAsQa9yS4gMdE0OzHXk BGrPWW9595kK2qrWFKqz78/duTUavKyyV0pbLVuknZYMQWr5jeNbrOnP9rCplbJCEY3S qtrw== X-Forwarded-Encrypted: i=1; AKwUvBxQyzC6XBl9EBiGXM29qLD7tjJMaYizTfIUPBwUI8EU9BSYasj+kz7iOqbN47UHVTKoYt3Y23kjV7YOgkk=@vger.kernel.org X-Gm-Message-State: AFuF++l7ftAa/yDuME49EUzAvUJomV28NHwzCojEtH/mVZ8gtx3ZuEhn Ci2ZAKeW2KnBEDgNkB+vw761uNPqY1XrFr7C+VKerDQRyEIJX0h+5hs= X-Gm-Gg: AYBFou38tMnH8HOxLm+rf/b2JBZ1psZf+oYWOrXzwwEMBtyCAW5tbDi/Hh2q5xko9RB 3HwnO1kgQSaVwKnQXHxcswZkKVeM9S0TdzhUstMCPT0rvjpGnqfLn5aFnDWKb3MPok++nKOAWBN EyVVjC7R1zAviKx3mpsSJ7vYB9vhoNC1Vn5RW0KYZxpbhsoMJeBMWGeCbTnGI1l5oIzxoJmBysN jZUfKiYSInFw/MQrCoLiToWqXLKY1SnsPwicR1uN/CUPm7KYIEkb8NLrQ7KkkgKrLBxEZ0VyFXH /hr1FfeWFDZZhr+eW3bS+3coRlYQvbi+rQVeUEYPQh4cg7lODSzmAmqAS3fltkoKN5UTqBQtQgL /CCnDSIGgMwQnwxak2F20B5v7lcvgB3Ds06wYX8y3Zi/Eu+5EqwrQOJMrk9Xo1xmtShoPTLPWgK Spjer3lAsDDP14pmcrdvu+VuPzMVvkLxkE3ccaX3UaWsMyuF3Ej2//uafbGh+Fd7ujDXGufe67e maeJUqo5IRwMsP6UHfImJL/SVU= X-Received: by 2002:a17:90b:5705:b0:36d:9e0b:3801 with SMTP id 98e67ed59e1d1-39b2617ed3bmr7586853a91.8.1788509193780; Fri, 04 Sep 2026 01:06:33 -0700 (PDT) Received: from MalHyuk.localdomain ([211.201.32.99]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39b261549f3sm3181153a91.16.2026.09.04.01.06.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 01:06:32 -0700 (PDT) From: "Jonghyuk Kim(MalHyuk)" To: phasta@kernel.org, christian.koenig@amd.com, tursulin@ursulin.net, matthew.brost@intel.com, dakr@kernel.org Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, mdaenzer@redhat.com, alessio.belle@imgtec.com, luigi.santivetti@imgtec.com, "Jonghyuk Kim(MalHyuk)" Subject: [PATCH v4 3/3] drm/sched/tests: add a UAF regression test for the timeline name Date: Fri, 4 Sep 2026 17:06:18 +0900 Message-ID: <20260904080618.2098450-4-malhyuk97@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260904080618.2098450-1-malhyuk97@gmail.com> References: <20260904080618.2098450-1-malhyuk97@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a KUnit test that reproduces the drm_sched_fence timeline-name use-after-free fixed by the previous patch. It submits a job on the mock scheduler, takes an independent reference on the finished fence (standing in for a userspace sync_file), lets the job finish, frees the scheduler, and then queries the timeline name through dma_fence_timeline_name(). Without the fix get_timeline_name() dereferences fence->sched of the freed scheduler and KASAN reports a slab-use-after-free read in drm_sched_fence_get_timeline_name(); with the fix the name was cached at init and the freed scheduler is never touched. The test needs no hardware - it exercises the drm_sched core through the existing mock scheduler under KASAN. Per review it lives in a new tests_integration.c rather than in tests_basic.c, since it is about the scheduler's interaction with the dma-fence API rather than scheduler behaviour in isolation. Signed-off-by: Jonghyuk Kim(MalHyuk) --- drivers/gpu/drm/scheduler/tests/Makefile | 1 + .../drm/scheduler/tests/tests_integration.c | 88 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 drivers/gpu/drm/scheduler/tests/tests_integration.c diff --git a/drivers/gpu/drm/scheduler/tests/Makefile b/drivers/gpu/drm/sch= eduler/tests/Makefile index 9ec185fbbc15..10abe07c06d2 100644 --- a/drivers/gpu/drm/scheduler/tests/Makefile +++ b/drivers/gpu/drm/scheduler/tests/Makefile @@ -3,6 +3,7 @@ drm-sched-tests-y :=3D \ mock_scheduler.o \ tests_basic.o \ + tests_integration.o \ tests_scheduler.o =20 obj-$(CONFIG_DRM_SCHED_KUNIT_TEST) +=3D drm-sched-tests.o diff --git a/drivers/gpu/drm/scheduler/tests/tests_integration.c b/drivers/= gpu/drm/scheduler/tests/tests_integration.c new file mode 100644 index 000000000000..4a2d5571440d --- /dev/null +++ b/drivers/gpu/drm/scheduler/tests/tests_integration.c @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +#include "sched_tests.h" + +/* + * Integration-style regression tests that exercise the interaction betwee= n the + * DRM scheduler and the dma-fence API, rather than scheduler behaviour in + * isolation. + */ + +/* + * Reproduce the drm_sched_fence timeline-name use-after-free. + * + * drm_sched_fence_get_timeline_name() used to dereference fence->sched->n= ame. + * A driver may free a per-context/per-queue/per-VM drm_gpu_scheduler while + * userspace still holds the exported ->finished fence (via sync_file / + * drm_syncobj). Querying the timeline name afterwards must not touch the = freed + * scheduler. + * + * Without the fix this reads fence->sched->name from freed slab memory and + * KASAN reports a slab-use-after-free in drm_sched_fence_get_timeline_nam= e(); + * with the fix the name is cached at init and the freed scheduler is never + * dereferenced. Same class as CVE-2025-38703 (drm/xe) and CVE-2025-71302 + * (drm/panthor). + */ +static void drm_sched_dma_fence_uaf(struct kunit *test) +{ + struct drm_mock_sched_entity *entity; + struct drm_mock_scheduler *sched; + struct drm_mock_sched_job *job; + struct dma_fence *finished; + const char __rcu *name; + bool done; + + sched =3D drm_mock_sched_new(test, MAX_SCHEDULE_TIMEOUT); + entity =3D drm_mock_sched_entity_new(test, DRM_SCHED_PRIORITY_NORMAL, + sched); + job =3D drm_mock_sched_job_new(test, entity); + + /* The s_fence is only created by drm_sched_job_arm(). */ + drm_mock_sched_job_submit(job); + + /* Independent reference on the finished fence =3D=3D userspace sync_file= . */ + finished =3D dma_fence_get(&job->base.s_fence->finished); + + /* Let the job get scheduled (hw fence created), then signal + finish. */ + done =3D drm_mock_sched_job_wait_scheduled(job, HZ); + KUNIT_ASSERT_TRUE(test, done); + drm_mock_sched_advance(sched, 1); + done =3D drm_mock_sched_job_wait_finished(job, HZ); + KUNIT_ASSERT_TRUE(test, done); + + /* + * Free the per-context scheduler while the finished fence is held. + * kunit_kfree() releases the backing memory immediately (rather than at + * test teardown) so that fence->sched becomes a dangling pointer now. + */ + drm_mock_sched_entity_free(entity); + drm_mock_sched_fini(sched); + kunit_kfree(test, sched); + + /* + * Query the timeline name of the now-stale fence. With the fix the name + * was cached at init, so the freed scheduler is not dereferenced; + * without it this is a use-after-free read of the freed scheduler. + */ + rcu_read_lock(); + name =3D dma_fence_timeline_name(finished); + KUNIT_EXPECT_NOT_NULL(test, name); + rcu_read_unlock(); + + dma_fence_put(finished); +} + +static struct kunit_case drm_sched_dma_fence_tests[] =3D { + KUNIT_CASE(drm_sched_dma_fence_uaf), + {} +}; + +static struct kunit_suite drm_sched_dma_fence =3D { + .name =3D "drm_sched_dma_fence_uaf_tests", + .test_cases =3D drm_sched_dma_fence_tests, +}; + +kunit_test_suite(drm_sched_dma_fence); --=20 2.43.0