From: sashiko-bot@kernel.org
To: "Ali Ahmet Memiş" <aliamemis@disroot.org>
Cc: "Alexander Gordeev" <agordeev@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
linux-trace-kernel@vger.kernel.org,
"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH] tracing: Don't dereference trace_event_file in deferred trigger free
Date: Fri, 11 Sep 2026 16:24:41 +0000 [thread overview]
Message-ID: <20260911162441.D00B81F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260911155650.354844-1-aliamemis@disroot.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] trace_event_file UAF and trigger memory leak on module unload
--
commit a41f148580cfeaf3b10b318f7d55d016bb4307cc
Author: Ali Ahmet Memiş <aliamemis@disroot.org>
tracing: Don't dereference trace_event_file in deferred trigger free
This commit addresses a use-after-free by avoiding the dereference of
trace_event_file during a deferred trigger free. It does so by directly
keeping the trace_event_call in the enable_trigger_data structure.
Link: https://lore.kernel.org/all/20260828134340.2501683A24-agordeev@linux.ibm.com/
> diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
> index 5e76f94e7a80e..0e4baecc7c737 100644
> --- a/kernel/trace/trace.h
> +++ b/kernel/trace/trace.h
> @@ -1952,6 +1952,7 @@ struct event_trigger_data {
>
> struct enable_trigger_data {
> struct trace_event_file *file;
> + struct trace_event_call *call;
> bool enable;
> bool hist;
> };
> diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_events_trigger.c
> index 149300cc5e8ad..4d2fde996c0f6 100644
> --- a/kernel/trace/trace_events_trigger.c
> +++ b/kernel/trace/trace_events_trigger.c
> @@ -1728,7 +1728,8 @@ static void enable_trigger_private_data_free(struct event_trigger_data *data)
> {
> struct enable_trigger_data *enable_data = data->private_data;
>
> - trace_event_put_ref(enable_data->file->event_call);
> + /* The file may already be freed here, only the call is kept alive */
> + trace_event_put_ref(enable_data->call);
[Severity: High]
This isn't a bug introduced by this patch, but it is a preexisting issue in
the subsystem's module unload handling.
When a privileged user registers a trace event trigger (like traceon or
enable_event) on a trace event defined in a kernel module and then unloads
that module, trace_module_remove_events() removes the events and eventually
frees the trace_event_file structure synchronously:
kernel/trace/trace_events.c:remove_event_file_dir() {
...
file->flags |= EVENT_FILE_FL_FREED;
event_file_put(file);
...
}
kernel/trace/trace_events.c:event_file_put() {
...
if (refcount_dec_and_test(&file->ref)) {
/* Count should only go to zero when it is freed */
if (WARN_ON_ONCE(!(file->flags & EVENT_FILE_FL_FREED)))
return;
kmem_cache_free(file_cachep, file);
}
}
Does this code leak the file->triggers list and cause memory corruption?
Because remove_event_file_dir() does not wait for an RCU grace period via
tracepoint_synchronize_unregister() before freeing the file, couldn't
concurrent RCU readers executing the tracepoint probe dereference the freed
file pointer?
Also, without cleaning up the triggers attached to file->triggers, are these
trigger structures permanently leaked?
> kfree(enable_data);
> }
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260911155650.354844-1-aliamemis@disroot.org?part=1
prev parent reply other threads:[~2026-09-11 16:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 15:56 [PATCH] tracing: Don't dereference trace_event_file in deferred trigger free Ali Ahmet Memiş
2026-09-11 16:24 ` sashiko-bot [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=20260911162441.D00B81F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=aliamemis@disroot.org \
--cc=borntraeger@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-s390@vger.kernel.org \
--cc=linux-trace-kernel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.