The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] tracing/filters: Fix MATCH_END_ONLY on dynamic char arrays
@ 2026-12-03 14:58 David Carlier
  2026-12-03 19:28 ` kernel test robot
  2026-12-03 19:39 ` Steven Rostedt
  0 siblings, 2 replies; 3+ messages in thread
From: David Carlier @ 2026-12-03 14:58 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu
  Cc: Mathieu Desnoyers, linux-trace-kernel, linux-kernel

regex_match_end() assumes the length counts a trailing NUL, which is
wrong for a __dynamic_array() of char. On xfs_lookup,
'name ~ "*.txt"' misses "foo.txt" and matches "a.txtz".

Remove it and use regex_match_end_str() for all MATCH_END_ONLY
filters. The char pointer path passes strlen() + 1, so it behaves the
same as before.

Fixes: a3291c14ecf0 ("tracing/filters: Fix MATCH_END_ONLY filter matching")
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: David Carlier <devnexen@gmail.com>
---
Changes in v2:
- Remove regex_match_end() and use regex_match_end_str() for all
  MATCH_END_ONLY filters (Steven)
- v1: https://lore.kernel.org/linux-trace-kernel/20261126215228.1205862-1-devnexen@gmail.com/

 kernel/trace/trace_events_filter.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 42a57cb57ff9..93fa6f6e3124 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1082,16 +1082,6 @@ static int regex_match_middle(char *str, struct regex *r, int len)
 	return strnstr(str, r->pattern, len) != NULL;
 }
 
-static int regex_match_end(char *str, struct regex *r, int len)
-{
-	int strlen = len - 1;
-
-	if (strlen >= r->len &&
-	    memcmp(str + strlen - r->len, r->pattern, r->len) == 0)
-		return 1;
-	return 0;
-}
-
 static int regex_match_end_str(char *str, struct regex *r, int len)
 {
 	int slen;
@@ -1203,7 +1193,7 @@ static void filter_build_regex(struct filter_pred *pred)
 		r->match = regex_match_middle;
 		break;
 	case MATCH_END_ONLY:
-		r->match = regex_match_end;
+		r->match = regex_match_end_str;
 		break;
 	case MATCH_GLOB:
 		r->match = regex_match_glob;
@@ -2061,18 +2051,12 @@ static int parse_pred(const char *str, void *data,
 
 		if (field->filter_type == FILTER_COMM) {
 			pred->fn_num = FILTER_PRED_FN_COMM;
-			if (pred->regex->match == regex_match_end)
-				pred->regex->match = regex_match_end_str;
-
 		} else if (field->filter_type == FILTER_STATIC_STRING) {
 			pred->fn_num = FILTER_PRED_FN_STRING;
 			pred->regex->field_len = field->size;
-			if (pred->regex->match == regex_match_end) {
-				if (!field->size)
-					pred->regex->match = regex_match_end_dynstr;
-				else
-					pred->regex->match = regex_match_end_str;
-			}
+			if (pred->regex->match == regex_match_end_str &&
+			    !field->size)
+				pred->regex->match = regex_match_end_dynstr;
 
 		} else if (field->filter_type == FILTER_DYN_STRING) {
 			pred->fn_num = FILTER_PRED_FN_STRLOC;
-- 
2.55.0


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

end of thread, other threads:[~2026-12-03 19:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 14:58 [PATCH v2] tracing/filters: Fix MATCH_END_ONLY on dynamic char arrays David Carlier
2026-12-03 19:28 ` kernel test robot
2026-12-03 19:39 ` Steven Rostedt

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