* [PATCH] tracing: unwind trigger state when event enable fails
@ 2026-12-03 16:56 Kyuwon Cho
2026-12-03 18:11 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Kyuwon Cho @ 2026-12-03 16:56 UTC (permalink / raw)
To: Steven Rostedt
Cc: Masami Hiramatsu, Mathieu Desnoyers, Tom Zanussi, linux-kernel,
linux-trace-kernel
trace_event_trigger_enable_disable() increments the trigger and soft-mode
references before enabling the event. If event registration fails, it
returns the error while leaving those references and the corresponding
flags set.
Trigger registration callers remove the failed trigger from their lists,
so later cleanup cannot balance the leaked state. A callback can remain
registered after its trace instance and event file are freed.
Undo the soft enable, clear the recorded and trigger-mode flags, and drop
the trigger reference before returning an enable error.
Fixes: 85f2b08268c0 ("tracing: Add basic event trigger framework")
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
The issue was found by an LLM-guided test generator that we are
developing as a research prototype.
The reproducers use fault injection or an invalid uprobe offset to make
event callback registration fail after the trigger references have been
taken. They then remove the trace instance and invoke the affected
tracepoint or uprobe. Access to tracefs and fault injection requires root
in the initial namespace.
Two representative decoded traces are:
BUG: KASAN: slab-use-after-free in __uprobe_trace_func
Read of size 8
__uprobe_trace_func (kernel/trace/trace_uprobe.c:1045)
uprobe_dispatcher (kernel/trace/trace_uprobe.c:1084
kernel/trace/trace_uprobe.c:1574)
handler_chain (kernel/events/uprobes.c:2562)
BUG: KASAN: slab-use-after-free in trace_event_raw_event_task_rename
Read of size 8
trace_event_raw_event_task_rename (include/linux/trace_events.h:767
include/trace/events/task.h:34)
__set_task_comm (include/trace/events/task.h:34 fs/exec.c:1102)
__do_sys_prctl (kernel/sys.c:2611)
The same leaked callback also reproduced in
trace_event_raw_event_sched_process_fork(). The patch was tested on
v7.4-rc5 and rebased onto tracing commit 175e5f3eddc6 ("tracing: Use
test_bit() in event_enable_count_probe()").
kernel/trace/trace_events_trigger.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_events_trigger.c
index a2487ad7fef8..f6ad7e5caf30 100644
--- a/kernel/trace/trace_events_trigger.c
+++ b/kernel/trace/trace_events_trigger.c
@@ -610,6 +610,13 @@ int trace_event_trigger_enable_disable(struct trace_event_file *file,
return ret;
set_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags);
ret = trace_event_enable_disable(file, 1, 1);
+ if (ret) {
+ trace_event_enable_disable(file, 0, 1);
+ clear_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags);
+ clear_bit(EVENT_FILE_FL_RECORDED_TGID_BIT, &file->flags);
+ clear_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags);
+ atomic_dec(&file->tm_ref);
+ }
} else {
if (atomic_dec_return(&file->tm_ref) > 0)
return ret;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tracing: unwind trigger state when event enable fails
2026-12-03 16:56 [PATCH] tracing: unwind trigger state when event enable fails Kyuwon Cho
@ 2026-12-03 18:11 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 18:11 UTC (permalink / raw)
To: Kyuwon Cho; +Cc: linux-trace-kernel
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] tracing: double unwind underflows refs on hist_trigger_enable()
failure
- [High] tracing: refcount underflow after enable_eprobe() ignores
enable error
--
commit 3ca2342579b82be365f7dc89e7d3686ead104b2e
Author: Kyuwon Cho <kyuwon.cho@skku.edu>
tracing: unwind trigger state when event enable fails
This commit updates trace_event_trigger_enable_disable() to undo the soft
enable, clear the recorded and trigger-mode flags, and decrement tm_ref
when trace_event_enable_disable() fails.
> diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_events_trigger.c
> index a2487ad7fef85..f6ad7e5caf308 100644
> --- a/kernel/trace/trace_events_trigger.c
> +++ b/kernel/trace/trace_events_trigger.c
> @@ -610,6 +610,13 @@ int trace_event_trigger_enable_disable(struct trace_event_file *file,
> return ret;
> set_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags);
> ret = trace_event_enable_disable(file, 1, 1);
> + if (ret) {
> + trace_event_enable_disable(file, 0, 1);
> + clear_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags);
> + clear_bit(EVENT_FILE_FL_RECORDED_TGID_BIT, &file->flags);
> + clear_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags);
> + atomic_dec(&file->tm_ref);
> + }
[Severity: High]
Can this double-unwind file->tm_ref and file->sm_ref when installing a
histogram trigger fails?
On error, hist_trigger_enable() leaves trigger_data on file->triggers so
event_hist_trigger_parse() cleans it up via hist_unregister_trigger().
That calls trace_event_trigger_enable_disable(file, 0) a second time,
underflowing file->tm_ref and file->sm_ref to -1.
It also runs an unbalanced trace_buffered_event_disable(). With
file->sm_ref at -1, __ftrace_event_enable_disable() keeps soft_mode true,
so a later normal enable and instance removal skip unregistering the event
callback and cause a use-after-free on the freed trace_event_file.
[Severity: High]
Will enable_eprobe() also underflow file->tm_ref and file->sm_ref when
enabling the target event fails?
enable_eprobe() in kernel/trace/trace_eprobe.c ignores the return value of
trace_event_trigger_enable_disable(file, 1) and leaves trigger on
file->triggers. Because this patch now unwinds the refs on error, later
cleanup in disable_eprobe() underflows file->tm_ref and file->sm_ref to -1.
That also runs an unbalanced trace_buffered_event_disable(), and leaving
file->sm_ref at -1 keeps soft_mode true in __ftrace_event_enable_disable()
so a later enable and instance removal can cause a use-after-free.
enable_eprobe() should check the return value and unlink and free trigger.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179620737571.2194197.8563884881260690416@skku.edu?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 18:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 16:56 [PATCH] tracing: unwind trigger state when event enable fails Kyuwon Cho
2026-12-03 18:11 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox