Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH] tracing/filters: Fix MATCH_END_ONLY on dynamic char arrays
@ 2026-11-26 21:52 David Carlier
  2026-12-03 13:28 ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: David Carlier @ 2026-11-26 21:52 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu
  Cc: Mathieu Desnoyers, linux-trace-kernel, linux-kernel,
	David Carlier

regex_match_end() takes the string length as "len - 1", which holds
for __string() fields where the length counts the trailing NUL. A
__dynamic_array() of char does not have to be NUL-terminated or
filled to its length. The xfs namespace events copy name->len bytes
with no NUL, so the compare is off by one:

  # echo 'name ~ "*.txt"' > events/xfs/xfs_lookup/filter

misses "foo.txt" and matches "a.txtz".

Use regex_match_end_str() for dynamic strings as well, which finds
the end with strnlen().

Fixes: a3291c14ecf0 ("tracing/filters: Fix MATCH_END_ONLY filter matching")
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 42a57cb57ff9..68a20f5d68fa 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -2076,8 +2076,12 @@ static int parse_pred(const char *str, void *data,
 
 		} else if (field->filter_type == FILTER_DYN_STRING) {
 			pred->fn_num = FILTER_PRED_FN_STRLOC;
+			if (pred->regex->match == regex_match_end)
+				pred->regex->match = regex_match_end_str;
 		} else if (field->filter_type == FILTER_RDYN_STRING) {
 			pred->fn_num = FILTER_PRED_FN_STRRELLOC;
+			if (pred->regex->match == regex_match_end)
+				pred->regex->match = regex_match_end_str;
 		} else if (field->filter_type == FILTER_WITHIN) {
 			unsigned long func;
 
-- 
2.55.0


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

* Re: [PATCH] tracing/filters: Fix MATCH_END_ONLY on dynamic char arrays
  2026-11-26 21:52 [PATCH] tracing/filters: Fix MATCH_END_ONLY on dynamic char arrays David Carlier
@ 2026-12-03 13:28 ` Steven Rostedt
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2026-12-03 13:28 UTC (permalink / raw)
  To: David Carlier
  Cc: Masami Hiramatsu, Mathieu Desnoyers, linux-trace-kernel,
	linux-kernel

On Thu, 26 Nov 2026 21:52:28 +0000
David Carlier <devnexen@gmail.com> wrote:

> regex_match_end() takes the string length as "len - 1", which holds
> for __string() fields where the length counts the trailing NUL. A
> __dynamic_array() of char does not have to be NUL-terminated or
> filled to its length. The xfs namespace events copy name->len bytes
> with no NUL, so the compare is off by one:
> 
>   # echo 'name ~ "*.txt"' > events/xfs/xfs_lookup/filter
> 
> misses "foo.txt" and matches "a.txtz".
> 
> Use regex_match_end_str() for dynamic strings as well, which finds
> the end with strnlen().

After this change, does anything actually use regex_match_end?

Why not just remove it or replace it with regex_match_end_str?

-- Steve

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

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

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 21:52 [PATCH] tracing/filters: Fix MATCH_END_ONLY on dynamic char arrays David Carlier
2026-12-03 13:28 ` Steven Rostedt

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