From: Steven Rostedt <rostedt@goodmis.org>
To: Breno Leitao <leitao@debian.org>
Cc: mark.rutland@arm.com, mhiramat@kernel.org,
linux-trace-kernel@vger.kernel.org
Subject: Re: ftrace: UAF in ftrace_regex_open() on a removed tracing instance
Date: Fri, 28 Aug 2026 12:34:30 -0400 [thread overview]
Message-ID: <20260828123430.22d43b44@gandalf.local.home> (raw)
In-Reply-To: <apGwPEj65dcbZFxS@gmail.com>
On Fri, 28 Aug 2026 08:59:39 -0700
Breno Leitao <leitao@debian.org> wrote:
>
> My LLM came up with something like the following, and it doesn't
> reproduce the problem anymore. Very similar to your code above:
I know the solution but there's subtle things I want to make sure that
works.
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index f9d80c7bd9f16..37845399fe5cf 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -4788,22 +4788,37 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
> static int
> ftrace_filter_open(struct inode *inode, struct file *file)
> {
> - struct ftrace_ops *ops = inode->i_private;
> + struct trace_array *tr = inode->i_private;
> + int ret;
>
> - /* Checks for tracefs lockdown */
> - return ftrace_regex_open(ops,
> - FTRACE_ITER_FILTER | FTRACE_ITER_DO_PROBES,
> - inode, file);
> + /* Checks for tracefs lockdown, and that the instance is still alive */
> + ret = tracing_check_open_get_tr(tr);
> + if (ret)
> + return ret;
> +
> + ret = ftrace_regex_open(tr->ops,
> + FTRACE_ITER_FILTER | FTRACE_ITER_DO_PROBES,
> + inode, file);
> + /* ftrace_regex_open() holds its own reference on success */
> + trace_array_put(tr);
> + return ret;
> }
>
> static int
> ftrace_notrace_open(struct inode *inode, struct file *file)
> {
> - struct ftrace_ops *ops = inode->i_private;
> + struct trace_array *tr = inode->i_private;
> + int ret;
> +
> + /* Checks for tracefs lockdown, and that the instance is still alive */
> + ret = tracing_check_open_get_tr(tr);
> + if (ret)
> + return ret;
>
> - /* Checks for tracefs lockdown */
> - return ftrace_regex_open(ops, FTRACE_ITER_NOTRACE,
> - inode, file);
> + ret = ftrace_regex_open(tr->ops, FTRACE_ITER_NOTRACE, inode, file);
> + /* ftrace_regex_open() holds its own reference on success */
> + trace_array_put(tr);
> + return ret;
> }
>
> /* Type for quick search ftrace basic regexes (globs) from filter_parse_regex */
> @@ -7496,11 +7511,15 @@ void ftrace_create_filter_files(struct ftrace_ops *ops,
> struct dentry *parent)
> {
>
> + /*
> + * Pass the trace array and not @ops, as @ops is freed when the
> + * instance is removed, but the trace array can still be validated.
> + */
I hate these comments. It's really pointless to state this. It's a "no shit" comment ;-)
> trace_create_file("set_ftrace_filter", TRACE_MODE_WRITE, parent,
> - ops, &ftrace_filter_fops);
> + ops->private, &ftrace_filter_fops);
But this also assumes that ops->private is always a trace_array. Which may
someday change and we will get a hidden bug if it does.
-- Steve
>
> trace_create_file("set_ftrace_notrace", TRACE_MODE_WRITE, parent,
> - ops, &ftrace_notrace_fops);
> + ops->private, &ftrace_notrace_fops);
> }
>
> /*
WARNING: multiple messages have this Message-ID (diff)
From: Steven Rostedt <rostedt@goodmis.org>
To: Breno Leitao <leitao@debian.org>
Cc: mark.rutland@arm.com, mhiramat@kernel.org,
linux-trace-kernel@vger.kernel.org
Subject: Re: ftrace: UAF in ftrace_regex_open() on a removed tracing instance
Date: Fri, 28 Aug 2026 12:34:52 -0400 [thread overview]
Message-ID: <20260828123430.22d43b44@gandalf.local.home> (raw)
Message-ID: <20260828163452.FSU7ejbJe9onK4amKMjmoCOJqemfXwQZjCrHsdy33eY@z> (raw)
In-Reply-To: <apGwPEj65dcbZFxS@gmail.com>
On Fri, 28 Aug 2026 08:59:39 -0700
Breno Leitao <leitao@debian.org> wrote:
>
> My LLM came up with something like the following, and it doesn't
> reproduce the problem anymore. Very similar to your code above:
I know the solution but there's subtle things I want to make sure that
works.
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index f9d80c7bd9f16..37845399fe5cf 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -4788,22 +4788,37 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
> static int
> ftrace_filter_open(struct inode *inode, struct file *file)
> {
> - struct ftrace_ops *ops = inode->i_private;
> + struct trace_array *tr = inode->i_private;
> + int ret;
>
> - /* Checks for tracefs lockdown */
> - return ftrace_regex_open(ops,
> - FTRACE_ITER_FILTER | FTRACE_ITER_DO_PROBES,
> - inode, file);
> + /* Checks for tracefs lockdown, and that the instance is still alive */
> + ret = tracing_check_open_get_tr(tr);
> + if (ret)
> + return ret;
> +
> + ret = ftrace_regex_open(tr->ops,
> + FTRACE_ITER_FILTER | FTRACE_ITER_DO_PROBES,
> + inode, file);
> + /* ftrace_regex_open() holds its own reference on success */
> + trace_array_put(tr);
> + return ret;
> }
>
> static int
> ftrace_notrace_open(struct inode *inode, struct file *file)
> {
> - struct ftrace_ops *ops = inode->i_private;
> + struct trace_array *tr = inode->i_private;
> + int ret;
> +
> + /* Checks for tracefs lockdown, and that the instance is still alive */
> + ret = tracing_check_open_get_tr(tr);
> + if (ret)
> + return ret;
>
> - /* Checks for tracefs lockdown */
> - return ftrace_regex_open(ops, FTRACE_ITER_NOTRACE,
> - inode, file);
> + ret = ftrace_regex_open(tr->ops, FTRACE_ITER_NOTRACE, inode, file);
> + /* ftrace_regex_open() holds its own reference on success */
> + trace_array_put(tr);
> + return ret;
> }
>
> /* Type for quick search ftrace basic regexes (globs) from filter_parse_regex */
> @@ -7496,11 +7511,15 @@ void ftrace_create_filter_files(struct ftrace_ops *ops,
> struct dentry *parent)
> {
>
> + /*
> + * Pass the trace array and not @ops, as @ops is freed when the
> + * instance is removed, but the trace array can still be validated.
> + */
I hate these comments. It's really pointless to state this. It's a "no shit" comment ;-)
> trace_create_file("set_ftrace_filter", TRACE_MODE_WRITE, parent,
> - ops, &ftrace_filter_fops);
> + ops->private, &ftrace_filter_fops);
But this also assumes that ops->private is always a trace_array. Which may
someday change and we will get a hidden bug if it does.
This is the exact reason I want to look deeper at it.
-- Steve
>
> trace_create_file("set_ftrace_notrace", TRACE_MODE_WRITE, parent,
> - ops, &ftrace_notrace_fops);
> + ops->private, &ftrace_notrace_fops);
> }
>
> /*
next prev parent reply other threads:[~2026-08-28 16:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 13:38 ftrace: UAF in ftrace_regex_open() on a removed tracing instance Breno Leitao
2026-08-28 14:42 ` Steven Rostedt
2026-08-28 15:59 ` Breno Leitao
2026-08-28 16:34 ` Steven Rostedt [this message]
2026-08-28 16:34 ` Steven Rostedt
2026-08-28 17:49 ` Steven Rostedt
2026-08-28 18:04 ` Steven Rostedt
2026-08-28 19:55 ` Steven Rostedt
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=20260828123430.22d43b44@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=leitao@debian.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
/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