Re: [PATCH v4 08/15] tracing/filters: Reject unsupported field sizes in parse_pred()
From: Masami Hiramatsu (Google)
Date: Wed Nov 18 2026 - 20:23:27 EST
On Tue, 17 Nov 2026 19:17:00 -0500, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> On Thu, 29 Oct 2026 10:38:39 +0900
> "Masami Hiramatsu (Google)" <mhiramat@xxxxxxxxxx> wrote:
>
> > From: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
> >
> > Prior to commit 80765597bc58 ("tracing: Rewrite filter logic to be simpler
> > and faster"), parse_pred() checked whether select_comparison_fn() returned
> > NULL and failed with FILT_ERR_INVALID_OP and -EINVAL. That check was lost
> > during the rewrite, and commit 3cbec9d7b93d ("tracing/filters: Enable
> > filtering a scalar field by a cpumask") similarly omitted a default error
> > case when matching field->size for CPUS{} comparisons.
> >
> > If a non-string field (FILTER_OTHER) has a size other than 1, 2, 4, or 8
> > (such as a fixed-size integer array field), pred->fn_num remains
> > FILTER_PRED_FN_NOP (0) and parse_pred() returns success. Subsequently,
> > update_preds() rejects FILTER_PRED_FN_NOP via WARN_ON_ONCE() and returns
> > -EINVAL without setting a parse_error() message, triggering a kernel
> > warning from user-supplied filter input.
> >
> > Restore the check for FILTER_PRED_FN_NOP in both the numeric scalar and
> > CPUS{} branches of parse_pred() and report FILT_ERR_INVALID_OP.
>
> Again, please show real examples of what fails, so I can test it.
Yeah, this is much easier to check via tracefs.
# cd /sys/kernel/tracing
# cat events/raw_syscalls/sys_enter/format | grep args
field:unsigned long args[6]; offset:24; size:48; signed:0;
So this event has args[6] array field. So filter needs [] to specify
the element. However,
# echo 'args == 0' > events/raw_syscalls/sys_enter/filter
# echo $?
0
This passed, and
# cat events/raw_syscalls/sys_enter/filter
args == 0
With this patch,
# echo 'args == 0' > events/raw_syscalls/sys_enter/filter
sh: write error: Invalid argument
# cat error_log
[ 23.864399] event filter parse error: error: Invalid operator
Command: args == 0
Thanks,
>
> Thanks,
>
> -- Steve
>
> >
> > Fixes: 80765597bc58 ("tracing: Rewrite filter logic to be simpler and faster")
> > Fixes: 3cbec9d7b93d ("tracing/filters: Enable filtering a scalar field by a cpumask")
> > Cc: stable@xxxxxxxxxxxxxxx
> > Signed-off-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
> > ---
> > kernel/trace/trace_events_filter.c | 8 ++++++++
> > 1 file changed, 8 insertions(+)
> >
> > diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
> > index a645af9eb1f8..40efcef94e02 100644
> > --- a/kernel/trace/trace_events_filter.c
> > +++ b/kernel/trace/trace_events_filter.c
> > @@ -2013,6 +2013,10 @@ static int parse_pred(const char *str, void *data,
> > break;
> > }
> > }
> > + if (pred->fn_num == FILTER_PRED_FN_NOP) {
> > + parse_error(pe, FILT_ERR_INVALID_OP, pos + i);
> > + goto err_free;
> > + }
> >
> > /* This is either a string, or an integer */
> > } else if (str[i] == '\'' || str[i] == '"') {
> > @@ -2166,6 +2170,10 @@ static int parse_pred(const char *str, void *data,
> > else {
> > pred->fn_num = select_comparison_fn(pred->op, field->size,
> > field->is_signed);
> > + if (pred->fn_num == FILTER_PRED_FN_NOP) {
> > + parse_error(pe, FILT_ERR_INVALID_OP, pos + i);
> > + goto err_free;
> > + }
> > if (pred->op == OP_NE)
> > pred->not = 1;
> > }
>
>
>
--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>