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 3/3] drm/sched/tests: add a UAF regression test for the timeline name
Date: Fri, 4 Sep 2026 17:06:18 +0900 [thread overview]
Message-ID: <20260904080618.2098450-4-malhyuk97@gmail.com> (raw)
In-Reply-To: <20260904080618.2098450-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 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) <malhyuk97@gmail.com>
---
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/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..4a2d5571440d
--- /dev/null
+++ b/drivers/gpu/drm/scheduler/tests/tests_integration.c
@@ -0,0 +1,88 @@
+// 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() used to dereference fence->sched->name.
+ * 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_name();
+ * 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 = 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 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 = 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_tests",
+ .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-05 15:04 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 8:06 [PATCH v4 0/3] drm/sched: fix use-after-free of the fence timeline name Jonghyuk Kim(MalHyuk)
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:18 ` sashiko-bot
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-07 9:15 ` Tvrtko Ursulin
2026-09-07 9:42 ` Philipp Stanner
2026-09-07 9:49 ` Philipp Stanner
2026-09-07 10:28 ` Tvrtko Ursulin
2026-09-07 10:34 ` Tvrtko Ursulin
2026-09-07 10:47 ` Philipp Stanner
2026-09-07 11:06 ` Tvrtko Ursulin
2026-09-07 11:15 ` Philipp Stanner
2026-09-07 12:59 ` Christian König
2026-09-07 13:38 ` Philipp Stanner
2026-09-07 15:21 ` Christian König
2026-09-08 10:49 ` Jonghyuk Kim(MalHyuk)
2026-09-08 11:07 ` Philipp Stanner
2026-09-09 0:37 ` Jonghyuk Kim(MalHyuk)
2026-09-09 7:44 ` Philipp Stanner
2026-09-07 12:28 ` Tvrtko Ursulin
2026-09-08 15:20 ` Tvrtko Ursulin
2026-09-07 12:18 ` Alessio Belle
2026-09-07 11:42 ` Christian König
2026-09-07 11:54 ` 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 ` Jonghyuk Kim(MalHyuk) [this message]
2026-09-04 8:15 ` [PATCH v4 3/3] drm/sched/tests: add a UAF regression test for the timeline name sashiko-bot
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-4-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.