[for-linus][PATCH 26/32] tracing: Properly match strings that start with numbers

From: Steven Rostedt

Date: Fri Nov 20 2026 - 12:43:25 EST


From: Brian Norris <briannorris@xxxxxxxxxxxx>

As an optimization, set_ftrace_filter supports writing indices (numbers)
instead of function names. This support was added to the generic glob
(fake regex) function, which breaks the ability to filter string
patterns that start with a number. For example, PCI device names tend to
look like '0001:01:00.0', and a reasonable filter might be:

echo 'name ~ "0001:*"' > /sys/kernel/tracing/events/rpm/rpm_resume/filter

Move the MATCH_INDEX code out to the only place it actually was intended
to work -- ftrace match_records(), with a 'func' and no 'mod'.

As a side effect, this also fixes :mod:<module> function filtering for
modules whose names start with a digit.

Link: https://patch.msgid.link/20261116182710.1.Ic0625a2bd2e6f8960c0f75e5d15f14f3c84d1d38@changeid
Fixes: f79b3f338564 ("ftrace: Allow enabling of filters via index of available_filter_functions")
Signed-off-by: Brian Norris <briannorris@xxxxxxxxxxxx>
Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
---
kernel/trace/ftrace.c | 3 ++-
kernel/trace/trace.h | 1 -
kernel/trace/trace_events_filter.c | 5 -----
3 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index c7d74b33d36d..6654da9d1bbf 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -5029,7 +5029,8 @@ match_records(struct ftrace_hash *hash, char *func, int len, char *mod)
if (unlikely(ftrace_disabled))
return 0;

- if (func_g.type == MATCH_INDEX)
+ if (func_g.type == MATCH_FULL && !mod &&
+ func_g.search && isdigit(func_g.search[0]))
return add_rec_by_index(hash, &func_g, clear_filter);

do_for_each_ftrace_rec(pg, rec) {
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 6b695a7f42c8..1fec567e789e 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -1807,7 +1807,6 @@ enum regex_type {
MATCH_MIDDLE_ONLY,
MATCH_END_ONLY,
MATCH_GLOB,
- MATCH_INDEX,
};

struct regex {
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index a1c298210059..6704ef3d9520 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1152,9 +1152,6 @@ enum regex_type filter_parse_regex(char *buff, int len, char **search, int *not)

*search = buff;

- if (isdigit(buff[0]))
- return MATCH_INDEX;
-
for (i = 0; i < len; i++) {
if (buff[i] == '*') {
if (!i) {
@@ -1192,8 +1189,6 @@ static void filter_build_regex(struct filter_pred *pred)
}

switch (type) {
- /* MATCH_INDEX should not happen, but if it does, match full */
- case MATCH_INDEX:
case MATCH_FULL:
r->match = regex_match_full;
break;
--
2.53.0