Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH 0/2] tracing: Fix a UAF and regex bug on trace-event
@ 2026-07-29  0:27 Masami Hiramatsu (Google)
  2026-07-29  0:27 ` [PATCH 1/2] tracing: Check return value of __register_event() in trace_module_add_events() Masami Hiramatsu (Google)
  2026-07-29  0:28 ` [PATCH 2/2] tracing/filters: Fix false positive match in regex_match_full() Masami Hiramatsu (Google)
  0 siblings, 2 replies; 3+ messages in thread
From: Masami Hiramatsu (Google) @ 2026-07-29  0:27 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu
  Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel

Hi,

Here are a couple of patches to fix a use-after-free bug in a
error case on registering events in a module, and regex match
problem.

Thanks,
---

Masami Hiramatsu (Google) (2):
      tracing: Check return value of __register_event() in trace_module_add_events()
      tracing/filters: Fix false positive match in regex_match_full()


 kernel/trace/trace_events.c        |    4 ++--
 kernel/trace/trace_events_filter.c |    3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

--
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] tracing: Check return value of __register_event() in trace_module_add_events()
  2026-07-29  0:27 [PATCH 0/2] tracing: Fix a UAF and regex bug on trace-event Masami Hiramatsu (Google)
@ 2026-07-29  0:27 ` Masami Hiramatsu (Google)
  2026-07-29  0:28 ` [PATCH 2/2] tracing/filters: Fix false positive match in regex_match_full() Masami Hiramatsu (Google)
  1 sibling, 0 replies; 3+ messages in thread
From: Masami Hiramatsu (Google) @ 2026-07-29  0:27 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu
  Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

trace_module_add_events() ignores the return value of __register_event()
and unconditionally calls __add_event_to_tracers() for each event.

If __register_event() fails (for example, if event_init() fails), the
trace_event_call is not added to ftrace_events list, but
__add_event_to_tracers() still creates a trace_event_file pointing to it.
If module loading subsequently fails and module memory is freed, tracing
state retains a stale trace_event_call pointer in trace_event_file,
leading to a use-after-free when tracefs or tracing subsystem operations
are later executed.

Fix this by checking the return value of __register_event() and only
calling __add_event_to_tracers() if event registration succeeded.

Fixes: ae63b31e4d0e ("tracing: Separate out trace events from global variables")
Cc: stable@vger.kernel.org
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 kernel/trace/trace_events.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 956692856fa8..c01b10b99f67 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -3933,8 +3933,8 @@ static void trace_module_add_events(struct module *mod)
 	end = mod->trace_events + mod->num_trace_events;
 
 	for_each_event(call, start, end) {
-		__register_event(*call, mod);
-		__add_event_to_tracers(*call);
+		if (!__register_event(*call, mod))
+			__add_event_to_tracers(*call);
 	}
 
 	update_cache_events(mod);


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] tracing/filters: Fix false positive match in regex_match_full()
  2026-07-29  0:27 [PATCH 0/2] tracing: Fix a UAF and regex bug on trace-event Masami Hiramatsu (Google)
  2026-07-29  0:27 ` [PATCH 1/2] tracing: Check return value of __register_event() in trace_module_add_events() Masami Hiramatsu (Google)
@ 2026-07-29  0:28 ` Masami Hiramatsu (Google)
  1 sibling, 0 replies; 3+ messages in thread
From: Masami Hiramatsu (Google) @ 2026-07-29  0:28 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu
  Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

regex_match_full() calls strncmp(str, r->pattern, len) where len is the
target field buffer size. When len is smaller than r->len (the filter
pattern length), strncmp() checks only len bytes of r->pattern against
str. If those len bytes match, strncmp() returns 0, resulting in a
false-positive match where a shorter string in a fixed-size field
matches a longer filter pattern.

For example, a 4-byte static string field containing "abcd" matched the
filter pattern "abcdefgh" because strncmp("abcd", "abcdefgh", 4)
returned 0. In this case, @len does NOT include '\0' because it is
fixed-size array.

Fix this by returning 0 (no match) early when len < r->len.

Fixes: 1889d20922d1 ("tracing/filters: Provide basic regex support")
Cc: stable@vger.kernel.org
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 kernel/trace/trace_events_filter.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 6385cd662d8d..2b46ca536045 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1027,6 +1027,9 @@ static int regex_match_full(char *str, struct regex *r, int len)
 	if (!len)
 		return strcmp(str, r->pattern) == 0;
 
+	if (len < r->len)
+		return 0;
+
 	return strncmp(str, r->pattern, len) == 0;
 }
 


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-29  0:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-29  0:27 [PATCH 0/2] tracing: Fix a UAF and regex bug on trace-event Masami Hiramatsu (Google)
2026-07-29  0:27 ` [PATCH 1/2] tracing: Check return value of __register_event() in trace_module_add_events() Masami Hiramatsu (Google)
2026-07-29  0:28 ` [PATCH 2/2] tracing/filters: Fix false positive match in regex_match_full() Masami Hiramatsu (Google)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox