[PATCH v3 06/16] tracing/filters: Check for missing operand after operator in parse_pred()

From: Masami Hiramatsu (Google)

Date: Tue Oct 27 2026 - 20:44:43 EST


From: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>

In parse_pred(), after matching the operator and skipping whitespace,
the filter string may terminate (str[i] == '\0') if the operand is
missing (e.g. "ip ==" or "common_pid ==").

For function events, the loop 'for (i++; str[i]; i++)' unconditionally
increments 'i' past the NUL terminator, causing an out-of-bounds read.
For other event types, allocating a predicate only to fail later during
value parsing is wasteful.

Check if 'str[i]' is NUL immediately after skipping whitespace after
the operator, and report FILT_ERR_INVALID_FILTER.

Fixes: 80765597bc58 ("tracing: Rewrite filter logic to be simpler and faster")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
---
Changes in v3:
- Split from the monolithic function event parsing patch.
- Check if str[i] is NUL immediately after skipping whitespace after
the operator in parse_pred() across all event types, as suggested
by Steven Rostedt.
---
kernel/trace/trace_events_filter.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 2554120ff6d6..3d2a075ec425 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1756,6 +1756,11 @@ static int parse_pred(const char *str, void *data,
while (isspace(str[i]))
i++;

+ if (!str[i]) {
+ parse_error(pe, FILT_ERR_INVALID_FILTER, pos + i);
+ goto err_free;
+ }
+
s = i;

pred = kzalloc_obj(*pred);