From: Steven Rostedt <rostedt@goodmis.org>
To: Guikun Yang <yangguikun19@qq.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [BUG] tracing: trigger filter use-after-free in set_trigger_filter() ENOMEM path
Date: Sat, 24 Oct 2026 11:17:56 -0400 [thread overview]
Message-ID: <20261024111756.14a393ac@fedora> (raw)
In-Reply-To: <tencent_51CD3420AAC8A722EA2FD5FEFB6524D4A905@qq.com>
On Sat, 24 Oct 2026 22:48:16 +0800
Guikun Yang <yangguikun19@qq.com> wrote:
> Fix: either free the new filter before publishing (i.e., don't
> rcu_assign_pointer until the filter_str copy succeeded), or perform
> tracepoint_synchronize_unregister() before free_event_filter() in the
> ENOMEM path, mirroring the normal path. The first variant is
> cheaper: move the kstrdup above the "assign:" label and release the
> pointer only after the string copy succeeded.
Note, the entire trigger code needs a rewrite. Something I'm looking at
doing when I get time.
This is a bug but one that would be very hard to hit as it would
require and admin to enable a trigger with a filter during major memory
pressure.
That said, the simplest fix is to simply copy the filter_str at near
the start and use that.
That is, something like this (not even compiled tested):
diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_events_trigger.c
index 4d2fde996c0f..1a6ea4261066 100644
--- a/kernel/trace/trace_events_trigger.c
+++ b/kernel/trace/trace_events_trigger.c
@@ -1195,6 +1195,7 @@ int set_trigger_filter(char *filter_str,
{
struct event_trigger_data *data = trigger_data;
struct event_filter *filter = NULL, *tmp;
+ char *str __free(kfree) = NULL;
int ret = -EINVAL;
char *s;
@@ -1209,9 +1210,13 @@ int set_trigger_filter(char *filter_str,
if (!filter_str)
return ret;
+ str = kstrdup(filter_str, GFP_KERNEL);
+ if (!str)
+ return -ENOMEM;
+
/* The filter is for the 'trigger' event, not the triggered event */
ret = create_event_filter(file->tr, file->event_call,
- filter_str, true, &filter);
+ str, true, &filter);
/* Only enabled set_str for error handling */
if (filter) {
@@ -1243,14 +1248,9 @@ int set_trigger_filter(char *filter_str,
kfree(data->filter_str);
data->filter_str = NULL;
- if (filter_str) {
- data->filter_str = kstrdup(filter_str, GFP_KERNEL);
- if (!data->filter_str) {
- free_event_filter(rcu_access_pointer(data->filter));
- data->filter = NULL;
- ret = -ENOMEM;
- }
- }
+ if (str)
+ data->filter_str = no_free_ptr(str);
+
return ret;
}
prev parent reply other threads:[~2026-10-24 15:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-24 14:48 [BUG] tracing: trigger filter use-after-free in set_trigger_filter() ENOMEM path Guikun Yang
2026-10-24 15:17 ` 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=20261024111756.14a393ac@fedora \
--to=rostedt@goodmis.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=yangguikun19@qq.com \
/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