tracing: Reject .function on the function trace event
Subsystems (2)
PATCH 1/1 tracing: Reject .function on the function trace event
For the function event, parse_pred() handles the .function suffix before the ftrace_event_is_function() case, so "ip.function == schedule" builds a predicate with no regex. Setting it through perf then dereferences the NULL pred->regex in ftrace_function_set_filter_pred().
The "ip" field of that event already takes a function name, so reject the suffix there.
--- kernel/trace/trace_events_filter.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/trace/trace_events_filter.c +6 -0
@@ -1743,6 +1743,12 @@ static int parse_pred(const char *str, void *data, pred->op = op;if (function) { +/* Function events already take a function name on 'ip' */ +if (ftrace_event_is_function (call)) { +parse_error (pe,FILT_ERR_ILLEGAL_FIELD_OP , pos + i); + goto err_free; + } +/* The field must be the same size as long */ if (field->size !=sizeof (long )) {parse_error (pe,FILT_ERR_ILLEGAL_FIELD_OP , pos + i);
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] tracing: out-of-bounds read in…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Critical] tracing: out-of-bounds read in parse_pred() on empty function filter operand [1]
--
commit e67c952556cf8df0fc74a91895fdbea1c0dd54b5
Author: David Carlier <[email protected]>
tracing: Reject .function on the function trace event
This commit rejects the .function filter suffix on the function trace event so that parse_pred() does not build a predicate with a NULL regex.
Quoted 7 lines
kernel/trace/trace_events_filter.c +0
-0@@ -1744,6 +1744,12 @@ static int parse_pred(const char *str, void *data, pred->op = op;
kernel/trace/trace_events_filter.c static int parse_pred(const char *str, void *data, · line 1755
Quoted 10 lines
kernel/trace/trace_events_filter.c +6
-0if (function) { +/* Function events already take a function name on 'ip' */ +if (ftrace_event_is_function (call)) { +parse_error (pe,FILT_ERR_ILLEGAL_FIELD_OP , pos + i); + goto err_free; + } +/* The field must be the same size as long */ if (field->size !=sizeof (long )) {parse_error (pe,FILT_ERR_ILLEGAL_FIELD_OP , pos + i);
[Severity: Critical]
This problem wasn't introduced by this patch, but can the paired ftrace_event_is_function(call) branch in parse_pred() read past the end of str [1] when the filter has no operand after the operator (for example, "ip ==")?
kernel/trace/trace_events_filter.c:parse_pred() {
...
} else if (ftrace_event_is_function(call)) {
...
if (str[i] == '\'' || str[i] == '"')
q = str[i];
else
q = 0;
for (i++; str[i]; i++) {
...
}When str ends after the operator and optional whitespace, str[i] is the terminating NUL byte and q is set to 0. The loop initializer i++ then advances i one byte past the NUL terminator before checking str[i], so parse_pred() scans out-of-bounds slab memory, copies it into pred->regex->pattern, and returns the out-of-bounds offset to predicate_parse().
[1] https://sashiko.dev/#/bug/linux-911099f1-cea5-4f84-ba41-25fbcbb66dad
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 1 line · On Sat, 14 Nov 2026 19:59:14 +0000 David Carlier <[email protected]> wrote:
Fixes e6745a4da964 ("tracing: Add a way to filter function addresses to function names")
regex was an embedded struct in filter_pred until cfb58e278c6a ("tracing/filters: Dynamically allocate filter_pred.regex"). Before that the pattern came out of the zeroed predicate empty and __ftrace_function_set_filter() returned -EINVAL, so cfb58e278c6a looks like the tag you want.
Steven Rostedt
maintainerQuoted 22 lines · On Sat, 14 Nov 2026 19:59:14 +0000 David Carlier <[email protected]> wrote:
For the function event,
parse_pred()handles the .function suffix before theftrace_event_is_function()case, so "ip.function == schedule" builds a predicate with no regex. Setting it through perf then dereferences the NULLpred->regexinftrace_function_set_filter_pred().The "ip" field of that event already takes a function name, so reject the suffix there.
Fixes e6745a4da964 ("tracing: Add a way to filter function addresses to function names")Signed-off-by David Carlier <[email protected]>--- kernel/trace/trace_events_filter.c | 6 ++++++ 1 file changed, 6 insertions(+)kernel/trace/trace_events_filter.c +0
-0@@ -1743,6 +1743,12 @@ static int parse_pred(const char *str, void *data, pred->op = op;
kernel/trace/trace_events_filter.c static int parse_pred(const char *str, void *data, · line 1754
Quoted 10 lines
kernel/trace/trace_events_filter.c +6
-0if (function) { +/* Function events already take a function name on 'ip' */ +if (ftrace_event_is_function (call)) { +parse_error (pe,FILT_ERR_ILLEGAL_FIELD_OP , pos + i); + goto err_free; + } +/* The field must be the same size as long */ if (field->size !=sizeof (long )) {parse_error (pe,FILT_ERR_ILLEGAL_FIELD_OP , pos + i);
Instead of rejecting it, why not just ignore it?
kernel/trace/trace_events_filter.c +3 -1
@@ -1742,7 +1742,9 @@ static int parse_pred(const char *str, void *data,/* See if the field is a kernel function name */ if ((len =str_has_prefix (str + i,".function" ))) { - function = true; +/* Ignore if event is already a function */ +if (!ftrace_event_is_function (call)) + function = true; i += len; }
The above fixes the issue as well, and allows things to work as expected.
-- Steve