From: Steven Rostedt <rostedt@goodmis.org>
To: sashiko-bot@kernel.org
Cc: sashiko-reviews@lists.linux.dev,
"Antoine Tenart" <atenart@kernel.org>,
linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2] tracing/probes: fix race between probe execution and event file removal
Date: Wed, 2 Dec 2026 13:45:34 -0500 [thread overview]
Message-ID: <20261202134534.45108fef@gandalf.local.home> (raw)
In-Reply-To: <sashiko-outbox-246248@kernel.org>
On Wed, 02 Dec 2026 16:45:48 +0000
sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [High] tracing/probes: UAF on file->filter and file->tr after
> free_link_rcu()
> --
>
> commit e46b0b6beaf53f9316361be522e07400739512b0
> Author: Antoine Tenart <atenart@kernel.org>
>
> tracing/probes: fix race between probe execution and event file removal
>
> This commit takes an event_file_get() reference on link->file in
> trace_probe_add_file() and releases it via call_rcu() in
> trace_probe_remove_file() so link->file is not freed while a probe handler
> is still running.
>
> > diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> > index cff55dcae36f2..c249256dea80d 100644
> > --- a/kernel/trace/trace_probe.c
> > +++ b/kernel/trace/trace_probe.c
> > @@ -2812,6 +2812,7 @@ int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file)
> > return -ENOMEM;
> >
> > link->file = file;
> > + event_file_get(file);
> > INIT_LIST_HEAD(&link->list);
> > list_add_tail_rcu(&link->list, &tp->event->files);
> > trace_probe_set_flag(tp, TP_FLAG_TRACE);
> > @@ -2831,6 +2832,14 @@ struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp,
> > return NULL;
> > }
> >
> > +static void free_link_rcu(struct rcu_head *rcu)
> > +{
> > + struct event_file_link *link = container_of(rcu, struct event_file_link, rcu);
> > +
> > + event_file_put(link->file);
> > + kvfree(link);
> > +}
> > +
> > int trace_probe_remove_file(struct trace_probe *tp,
> > struct trace_event_file *file)
> > {
> > @@ -2841,7 +2850,7 @@ int trace_probe_remove_file(struct trace_probe *tp,
> > return -ENOENT;
> >
> > list_del_rcu(&link->list);
> > - kvfree_rcu_mightsleep(link);
> > + call_rcu(&link->rcu, free_link_rcu);
>
> [Severity: High]
> Can an in-flight probe handler still hit a use-after-free on file->filter
> or file->tr even with event_file_get() holding a reference on file?
>
> event_file_get() only delays freeing the struct trace_event_file slab
> object itself; it does not delay the teardown of sub-objects hanging off
> file when trace_probe_remove_file() returns without waiting for an RCU
> grace period.
>
> CPU0 CPU1
> kretprobe_trace_func()
> file = link->file
> disable_trace_kprobe()
> trace_probe_remove_file()
> list_del_rcu(&link->list)
> call_rcu(&link->rcu, free_link_rcu)
> unregister_trace_kprobe()
> unregister_kprobe_event()
> ...
> remove_event_file_dir()
> free_event_filter(file->filter)
> file->flags |= EVENT_FILE_FL_FREED
> event_file_put(file)
> __kretprobe_trace_func()
> trace_event_buffer_commit()
> __event_trigger_test_discard()
> filter_match_preds(file->filter, ...)
> <-- use-after-free on file->filter
>
> remove_event_file_dir() frees file->filter synchronously before calling
> event_file_put() and leaves EVENT_FILE_FL_FILTERED set in file->flags.
I wonder if you had put a lore link to my suggestion if Sashiko would have
know that we cover this.
>
> Similarly, during trace instance removal (__remove_instance() ->
> event_trace_del_tracer()), tracepoint_synchronize_unregister() only waits
> on tracepoint_srcu and rcu_tasks_trace rather than standard RCU, so
> __remove_instance() can free tr->array_buffer.buffer and tr while an
> in-flight probe handler is still accessing link->file->tr.
>
Now this can be an issue where kprobes and tracing use two different
synchronization methods. Kprobes uses RCU where as tracing uses RCU tasks.
-- Steve
prev parent reply other threads:[~2026-12-02 18:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 16:23 [PATCH v2] tracing/probes: fix race between probe execution and event file removal Antoine Tenart
2026-12-02 16:33 ` Steven Rostedt
2026-12-02 16:45 ` sashiko-bot
2026-12-02 18:45 ` 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=20261202134534.45108fef@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=atenart@kernel.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