tracing: Fix crash passing ERR_PTR to kthread_stop()
authorHui Su <sh_def@163.com>
Mon, 17 Aug 2026 12:06:44 +0000 (20:06 +0800)
committerSteven Rostedt <rostedt@goodmis.org>
Sat, 22 Aug 2026 21:35:50 +0000 (17:35 -0400)
event_test_stuff() calls kthread_run() and unconditionally passes the
returned task_struct pointer to kthread_stop(). kthread_run() returns an
error pointer such as ERR_PTR(-ENOMEM) when kthread creation fails, for
example under memory pressure during the boot-time event self-test.
kthread_stop() then dereferences the invalid pointer, crashing the kernel.

Check the result of kthread_run() before passing it to kthread_stop(). Use
WARN_ON() so that a failure to create the self-test thread does not go
unnoticed, matching the ring-buffer self-test fix in commit
91542863abad ("ring-buffer: Fix crash passing ERR_PTR to kthread_stop()").

Cc: stable@vger.kernel.org
Fixes: e6187007d6c3 ("tracing/events: add startup tests for events")
Link: https://patch.msgid.link/20260817120642.668375-3-sh_def@163.com
Signed-off-by: Hui Su <sh_def@163.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/trace_events.c

index 9f8f2d0..1d39eaf 100644 (file)
@@ -5019,6 +5019,8 @@ static __init void event_test_stuff(void)
        struct task_struct *test_thread;
 
        test_thread = kthread_run(event_test_thread, NULL, "test-events");
+       if (WARN_ON(IS_ERR(test_thread)))
+               return;
        msleep(1);
        kthread_stop(test_thread);
 }