From: "Jonghyuk Kim(MalHyuk)" <malhyuk97@gmail.com>
To: tursulin@ursulin.net, phasta@kernel.org, matthew.brost@intel.com,
dakr@kernel.org
Cc: christian.koenig@amd.com, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org,
"Jonghyuk Kim(MalHyuk)" <malhyuk97@gmail.com>
Subject: [PATCH v3 2/2] drm/sched/tests: add a UAF regression test for the timeline name
Date: Wed, 2 Sep 2026 23:42:04 +0900 [thread overview]
Message-ID: <20260902144204.1843670-3-malhyuk97@gmail.com> (raw)
In-Reply-To: <20260902144204.1843670-1-malhyuk97@gmail.com>
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 the finished fence keeps its ops attached after
signalling, so this 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 ops are detached on
signalling and a static string is returned.
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) <malhyuk97@gmail.com>
---
drivers/gpu/drm/scheduler/tests/Makefile | 1 +
.../drm/scheduler/tests/tests_integration.c | 92 +++++++++++++++++++
2 files changed, 93 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/scheduler/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 := \
mock_scheduler.o \
tests_basic.o \
+ tests_integration.o \
tests_scheduler.o
obj-$(CONFIG_DRM_SCHED_KUNIT_TEST) += 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..5e1ca6c6fa5a
--- /dev/null
+++ b/drivers/gpu/drm/scheduler/tests/tests_integration.c
@@ -0,0 +1,92 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/dma-fence.h>
+#include <linux/rcupdate.h>
+
+#include "sched_tests.h"
+
+/*
+ * Integration-style regression tests that exercise the interaction between 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() dereferences fence->sched. 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.
+ *
+ * The dma-fence contract only permits access to driver-provided data (which
+ * includes the memory reached through &dma_fence.ops) before the fence is
+ * signalled. dma_fence_timeline_name() enforces this by returning a static
+ * string once the ops have been detached on signalling. For that detach to
+ * happen the finished fence must not carry a .release (or .wait) callback.
+ *
+ * Without the fix (finished fence keeps a .release callback) the ops are never
+ * detached, so this reads fence->sched->name from freed slab memory and KASAN
+ * reports a slab-use-after-free. 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 = drm_mock_sched_new(test, MAX_SCHEDULE_TIMEOUT);
+ entity = drm_mock_sched_entity_new(test, DRM_SCHED_PRIORITY_NORMAL,
+ sched);
+ job = 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 == userspace sync_file. */
+ finished = dma_fence_get(&job->base.s_fence->finished);
+
+ /* Let the job get scheduled (hw fence created), then signal + finish. */
+ done = drm_mock_sched_job_wait_scheduled(job, HZ);
+ KUNIT_ASSERT_TRUE(test, done);
+ drm_mock_sched_advance(sched, 1);
+ done = 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 ops
+ * have been detached on signalling and a static string is returned;
+ * without it this is a use-after-free read of the freed scheduler.
+ */
+ rcu_read_lock();
+ name = 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[] = {
+ KUNIT_CASE(drm_sched_dma_fence_uaf),
+ {}
+};
+
+static struct kunit_suite drm_sched_dma_fence = {
+ .name = "drm-sched-dma-fence-uaf",
+ .test_cases = drm_sched_dma_fence_tests,
+};
+
+kunit_test_suite(drm_sched_dma_fence);
--
2.43.0
next prev parent reply other threads:[~2026-09-03 7:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 14:42 [PATCH v3 0/2] drm/sched: fix use-after-free of the fence timeline name Jonghyuk Kim(MalHyuk)
2026-09-02 14:42 ` [PATCH v3 1/2] " Jonghyuk Kim(MalHyuk)
2026-09-02 14:58 ` sashiko-bot
2026-09-03 8:46 ` Philipp Stanner
2026-09-03 10:02 ` Christian König
2026-09-03 10:22 ` Christian König
2026-09-03 18:01 ` Jonghyuk Kim(MalHyuk)
2026-09-04 7:42 ` Philipp Stanner
2026-09-02 14:42 ` Jonghyuk Kim(MalHyuk) [this message]
2026-09-02 15:04 ` [PATCH v3 2/2] drm/sched/tests: add a UAF regression test for the " sashiko-bot
2026-09-02 16:09 ` [PATCH v3 0/2] drm/sched: fix use-after-free of the fence " Philipp Stanner
2026-09-02 17:25 ` Philipp Stanner
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=20260902144204.1843670-3-malhyuk97@gmail.com \
--to=malhyuk97@gmail.com \
--cc=christian.koenig@amd.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew.brost@intel.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