Re: [PATCH v2] tracing/filters: Fix MATCH_END_ONLY on dynamic char arrays

From: Steven Rostedt

Date: Thu Dec 03 2026 - 14:39:31 EST


On Thu, 3 Dec 2026 14:58:22 +0000
David Carlier <devnexen@xxxxxxxxx> wrote:

> 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@xxxxxxxxxxx>
> Signed-off-by: David Carlier <devnexen@xxxxxxxxx>
> ---
> 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@xxxxxxxxx/
>
> 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)

Actually I was also thinking this should rename regex_match_end_str to
regex_match_end() and the dynamic one to regex_match_end_dyn()

-- Steve


> {
> 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;