Linux Trace Kernel
 help / color / mirror / Atom feed
From: David Carlier <devnexen@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] tracing/filters: Fix MATCH_END_ONLY on dynamic char arrays
Date: Thu,  3 Dec 2026 14:58:22 +0000	[thread overview]
Message-ID: <20261203145822.591395-1-devnexen@gmail.com> (raw)

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


                 reply	other threads:[~2026-12-03 14:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203145822.591395-1-devnexen@gmail.com \
    --to=devnexen@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox