* [PATCH v2] tracing: Fix crash passing ERR_PTR to kthread_stop()
@ 2026-08-17 12:06 Hui Su
2026-08-17 12:15 ` sashiko-bot
0 siblings, 1 reply; 3+ messages in thread
From: Hui Su @ 2026-08-17 12:06 UTC (permalink / raw)
To: rostedt, mhiramat, mathieu.desnoyers
Cc: linux-trace-kernel, linux-kernel, stable, Hui Su
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()").
Fixes: e6187007d6c3 ("tracing/events: add startup tests for events")
Cc: stable@vger.kernel.org
Signed-off-by: Hui Su <sh_def@163.com>
---
Changes in v2:
- Use WARN_ON(IS_ERR(test_thread)) so thread creation failures are not
silently ignored, as suggested by Steven Rostedt.
v1: https://lore.kernel.org/r/20260815190151.568893-4-sh_def@163.com/
kernel/trace/trace_events.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 3650d84d4f16..28167b229419 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -4901,6 +4901,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);
}
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] tracing: Fix crash passing ERR_PTR to kthread_stop()
2026-08-17 12:06 [PATCH v2] tracing: Fix crash passing ERR_PTR to kthread_stop() Hui Su
@ 2026-08-17 12:15 ` sashiko-bot
2026-08-17 13:26 ` Steven Rostedt
0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-08-17 12:15 UTC (permalink / raw)
To: Hui Su; +Cc: linux-trace-kernel
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Using `WARN_ON` inside `event_test_stuff()` causes a massive warning storm and potential soft lockup if kthread creation repeatedly fails.
--
--- Patch [1]: [PATCH v2] tracing: Fix crash passing ERR_PTR to kthread_stop() ---
commit 692df106ab8d8e56701ad9c14c135871ee02df4a
Author: Hui Su <sh_def@163.com>
tracing: Fix crash passing ERR_PTR to kthread_stop()
This commit adds a check for the return value of kthread_run() in
event_test_stuff() to prevent passing an ERR_PTR to kthread_stop() if thread
creation fails under memory pressure during boot-time trace self tests.
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index 0356cae0cf74e..9e941e5805f5e 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -3866,6 +3866,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;
[Severity: High]
Does this risk causing a console flood and soft lockup if thread creation
persistently fails?
During boot-time trace self tests, event_test_stuff() is called within
large loops spanning all trace events:
kernel/trace/trace_events.c:event_trace_self_tests() {
...
list_for_each_entry(file, &tr->events, list) {
...
ftrace_event_enable_disable(file, 1);
event_test_stuff();
ftrace_event_enable_disable(file, 0);
...
}
If kthread creation fails, WARN_ON prints a full stack trace and returns.
Since event_test_stuff() returns void, the caller blindly continues to the
next trace event, potentially leading to thousands of consecutive stack
dumps.
Could this be changed to WARN_ON_ONCE() or modified to abort the test loop
gracefully?
> msleep(1);
> kthread_stop(test_thread);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260817120642.668375-3-sh_def@163.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] tracing: Fix crash passing ERR_PTR to kthread_stop()
2026-08-17 12:15 ` sashiko-bot
@ 2026-08-17 13:26 ` Steven Rostedt
0 siblings, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2026-08-17 13:26 UTC (permalink / raw)
To: sashiko-bot; +Cc: sashiko-reviews, Hui Su, linux-trace-kernel
On Mon, 17 Aug 2026 12:15:32 +0000
sashiko-bot@kernel.org wrote:
> > diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> > index 0356cae0cf74e..9e941e5805f5e 100644
> > --- a/kernel/trace/trace_events.c
> > +++ b/kernel/trace/trace_events.c
> > @@ -3866,6 +3866,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;
>
> [Severity: High]
> Does this risk causing a console flood and soft lockup if thread creation
> persistently fails?
>
If that happens than the system is doomed to begin with. We don't care
here. This patch is good enough. It's for a debugging feature, not
anything that would be run in production.
Just look at the name of the function: event_test_stuff()
This is where AI has a hard time with subtle requirements.
Thanks,
-- Steve
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-17 13:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-17 12:06 [PATCH v2] tracing: Fix crash passing ERR_PTR to kthread_stop() Hui Su
2026-08-17 12:15 ` sashiko-bot
2026-08-17 13:26 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox