From: "Jonghyuk Kim(MalHyuk)" <malhyuk97@gmail.com>
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)" <malhyuk97@gmail.com>
Subject: [PATCH v4 0/3] drm/sched: fix use-after-free of the fence timeline name
Date: Fri, 4 Sep 2026 17:06:15 +0900 [thread overview]
Message-ID: <20260904080618.2098450-1-malhyuk97@gmail.com> (raw)
drm_sched_fence_get_timeline_name() dereferences fence->sched->name. A driver
that allocates a drm_gpu_scheduler per context, queue or VM frees that scheduler
on context teardown, but the finished fence can outlive it: unprivileged
userspace holds the exported fence via a sync_file or drm_syncobj and later
queries its timeline name (e.g. SYNC_IOC_FILE_INFO), reading the freed
scheduler. Same class as CVE-2025-38703 (drm/xe) and CVE-2025-71302
(drm/panthor); amdxdna, nouveau and msm (VM_BIND) are still affected in
mainline, so this fixes it in the core.
v3 tried to drop the finished fence's ->release so that dma_fence detaches the
ops on signalling. That turned out not to be viable:
- amdgpu dereferences to_drm_sched_fence() unconditionally
(amdgpu_cs_p2_dependencies(), amdgpu_ctx_fence_time()), and ops-detach makes
the helper return NULL for a signalled fence - a deterministic NULL deref
reachable by an unprivileged process;
- drm/imagination uses the ops pointer as an identity test in
pvr_queue_fence_is_native(), which Philipp showed would then race; and
- Christian pointed out that the reference must go from the finished to the
scheduled fence, not the other way around, so v3's refcount rework was wrong.
So v4 goes back to the minimal caching fix: get_timeline_name() returns a name
cached at fence init and never dereferences ->sched. Both .release callbacks,
the shared allocation, the call_rcu() free and to_drm_sched_fence() all stay
exactly as they are today, so there is no amdgpu/pvr regression and nothing new
for the backend to reason about.
Detaching the ops is still the better fix in the long run - it is what the
dma-fence rules ask for, and it would also cover get_driver_name(), which can
return a string literal from a module that has since been unloaded. Patch 2
records that as a TODO entry (and a comment next to the fence ops) with the
three blockers that have to be solved first, so the cleanup is not lost.
There is no unrelated formatting churn in this version; the kerneldoc reflow
that was mixed into v3 is gone.
Tested with KUnit under KASAN and kmemleak (kunit.py --arch=x86_64), matched
pair:
- unfixed (get_timeline_name() dereferencing ->sched):
[FAILED] drm_sched_dma_fence_uaf
BUG: KASAN: slab-use-after-free in
drm_sched_fence_get_timeline_name+0x9c/0xb0
- fixed (this series):
[PASSED] drm_sched_dma_fence_uaf
Testing complete. Ran 43 tests: passed: 43
No kmemleak reports, and the whole drm_sched suite passes with no regressions.
Link to v3 (ops-detach):
https://lore.kernel.org/lkml/20260902144204.1843670-1-malhyuk97@gmail.com/
Link to v2 (caching):
https://lore.kernel.org/lkml/20260902105808.1541063-1-malhyuk97@gmail.com/
v4:
- Drop the ops-detach/refcount rework; return to caching the timeline name
(per the amdgpu/pvr regression above and Christian's reference-direction
point).
- Add a TODO comment and a Documentation/gpu/todo.rst entry for the
ops-detach cleanup (per Philipp).
- Keep Cc: stable with "we don't know since when" (per Philipp).
- No formatting-only hunks in the fix patch.
- Test suite renamed to drm_sched_dma_fence_uaf_tests for consistency with the
sibling suites; re-verified under kmemleak as well as KASAN.
Jonghyuk Kim(MalHyuk) (3):
drm/sched: cache the timeline name to fix a use-after-free
drm/sched: add the fence ops-detach cleanup to the TODO list
drm/sched/tests: add a UAF regression test for the timeline name
Documentation/gpu/todo.rst | 39 ++++++++
drivers/gpu/drm/scheduler/sched_fence.c | 24 ++++-
drivers/gpu/drm/scheduler/tests/Makefile | 1 +
.../drm/scheduler/tests/tests_integration.c | 88 +++++++++++++++++++
include/drm/gpu_scheduler.h | 18 +++-
5 files changed, 168 insertions(+), 2 deletions(-)
create mode 100644 drivers/gpu/drm/scheduler/tests/tests_integration.c
--
2.43.0
next reply other threads:[~2026-09-04 8:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 8:06 Jonghyuk Kim(MalHyuk) [this message]
2026-09-04 8:06 ` [PATCH v4 1/3] drm/sched: cache the timeline name to fix a use-after-free Jonghyuk Kim(MalHyuk)
2026-09-04 8:20 ` Christian König
2026-09-04 8:31 ` Philipp Stanner
2026-09-04 12:49 ` Christian König
2026-09-04 19:06 ` Philipp Stanner
2026-09-04 8:31 ` Jonghyuk Kim(MalHyuk)
2026-09-04 8:39 ` Philipp Stanner
2026-09-04 9:11 ` Jonghyuk Kim(MalHyuk)
2026-09-04 9:07 ` Tvrtko Ursulin
2026-09-04 9:57 ` Danilo Krummrich
2026-09-04 10:51 ` Philipp Stanner
2026-09-04 8:06 ` [PATCH v4 2/3] drm/sched: add the fence ops-detach cleanup to the TODO list Jonghyuk Kim(MalHyuk)
2026-09-04 8:06 ` [PATCH v4 3/3] drm/sched/tests: add a UAF regression test for the timeline name Jonghyuk Kim(MalHyuk)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260904080618.2098450-1-malhyuk97@gmail.com \
--to=malhyuk97@gmail.com \
--cc=alessio.belle@imgtec.com \
--cc=christian.koenig@amd.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luigi.santivetti@imgtec.com \
--cc=matthew.brost@intel.com \
--cc=mdaenzer@redhat.com \
--cc=phasta@kernel.org \
--cc=tursulin@ursulin.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®