From: Steven Rostedt <rostedt@goodmis.org>
To: sashiko-bot@kernel.org
Cc: sashiko-reviews@lists.linux.dev,
"Linux Trace Kernel" <linux-trace-kernel@vger.kernel.org>
Subject: Re: [PATCH] tracing: Free all event filters after RCU synchronization
Date: Tue, 1 Dec 2026 15:37:48 -0500 [thread overview]
Message-ID: <20261201153748.4f6ba182@gandalf.local.home> (raw)
In-Reply-To: <sashiko-outbox-244183@kernel.org>
On Tue, 01 Dec 2026 20:23:29 +0000
sashiko-bot@kernel.org wrote:
> [ ... ]
> > @@ -1495,47 +1464,33 @@ static void filter_free_subsystem_filters(struct trace_subsystem_dir *dir,
> [ ... ]
> > - list_for_each_entry(file, &tr->events, list) {
> > - if (file->system != dir || !file->filter)
> > - continue;
> > - __free_subsystem_filter(file);
> > + event_clear_filter(file);
> > }
> > - __free_filter(filter);
> > +
> > + delay_free_filter(filter_list);
> > }
>
> [Severity: Low]
> Removing the fallback path in filter_free_subsystem_filters() leaves
> __free_subsystem_filter() unused. Should it be removed as well?
Oh yes, thanks!
>
> > @@ -2377,9 +2332,9 @@ static int process_system_preds(struct trace_subsystem_dir *dir,
> > char *filter_string)
> > {
> > struct trace_event_file *file;
> > - struct filter_list *filter_item;
> > struct event_filter *filter = NULL;
> > - struct filter_head *filter_list;
> > + struct event_filter *filter_list;
> > + struct event_filter *efilter;
> > bool fail = true;
> > int ret = -ENOMEM;
> > int err;
> > @@ -2413,18 +2368,16 @@ static int process_system_preds(struct trace_subsystem_dir *dir,
> > fail = false;
> > }
> >
> > - filter_item = kzalloc_obj(*filter_item);
> > - if (!filter_item)
> > - goto fail_mem;
> > -
> > - list_add_tail(&filter_item->list, &filter_list->list);
> > /*
> > * Regardless of if this returned an error, we still
> > * replace the filter for the call.
> > */
> > - filter_item->filter = event_filter(file);
> > + efilter = event_filter(file);
> > event_set_filter(file, filter);
> > filter = NULL;
> > +
> > + if (efilter)
> > + list_add_tail(&efilter->list, &filter_list->list);
> > }
>
> [Severity: High]
> Does free_filter_list() pass uninitialized filter_list->prog and
> filter_list->filter_string pointers to free_prog() and kfree()?
>
> process_system_preds() still allocates a dummy filter_list with
> kmalloc_obj() and only initializes filter_list->list:
Bah, I was thinking that kmalloc_obj() zeroed out the memory, but it's just
a normal kmalloc. I need to switch that to a kzalloc_obj().
>
> kernel/trace/trace_events_filter.c:process_system_preds() {
> ...
> filter_list = kmalloc_obj(*filter_list);
> if (!filter_list)
> return -ENOMEM;
>
> INIT_LIST_HEAD(&filter_list->list);
> ...
> }
>
> Because free_filter_list() now calls __free_filter(filter_list) on the
> list head itself instead of kfree(filter_list), writing a subsystem filter
> causes __free_filter() to dereference and free uninitialized heap memory
> from filter_list->prog and filter_list->filter_string.
>
> Could process_system_preds() initialize filter_list to NULL and use the
> first non-NULL efilter as the list head, matching
> filter_free_subsystem_filters()?
>
Yes, and that's because I thought the temporary filter was zeroed out, but
it wasn't.
v2 on the way.
-- Steve
prev parent reply other threads:[~2026-12-01 20:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 20:15 [PATCH] tracing: Free all event filters after RCU synchronization Steven Rostedt
2026-12-01 20:23 ` sashiko-bot
2026-12-01 20:37 ` Steven Rostedt [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201153748.4f6ba182@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=sashiko-bot@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox