Linux Trace Kernel
 help / color / mirror / Atom feed
* [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

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