Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] tracing/filters: Fix glob matching on zero size string fields
@ 2026-11-26 21:52 David Carlier
  0 siblings, 0 replies; only message in thread
From: David Carlier @ 2026-11-26 21:52 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu
  Cc: Mathieu Desnoyers, Huihui Huang, linux-trace-kernel, linux-kernel,
	David Carlier, stable

The "buf" field of the ftrace print event is a char[] of size zero,
and filter_pred_string() passes that size as the length. The regex
callbacks take a zero length as a NUL-terminated string of unknown
length, but since regex_match_glob() was switched to glob_match_len()
it treats it as an empty string, so a glob never matches:

  # echo 'snapshot if buf ~ "st*r*"' > events/ftrace/print/trigger
  # echo start > trace_marker

Use glob_match() when the length is zero.

Fixes: 0a6070839b1e ("tracing: Prevent out-of-bounds read in glob matching")
Cc: stable@vger.kernel.org
Signed-off-by: David Carlier <devnexen@gmail.com>
---
 kernel/trace/trace_events_filter.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index a9d77df3e19a..42a57cb57ff9 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1118,6 +1118,10 @@ static int regex_match_end_dynstr(char *str, struct regex *r, int len)
 
 static int regex_match_glob(char *str, struct regex *r, int len)
 {
+	/* Zero is reserved for a NUL-terminated string of unknown length. */
+	if (!len)
+		return glob_match(r->pattern, str);
+
 	return glob_match_len(r->pattern, str, len) ? 1 : 0;
 }
 
-- 
2.55.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-26 21:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 21:52 [PATCH] tracing/filters: Fix glob matching on zero size string fields David Carlier

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