From: Steven Rostedt <rostedt@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>,
stable@vger.kernel.org, Yuanhe Shu <xiangzao@linux.alibaba.com>
Subject: [for-linus][PATCH 10/13] tracing: Fix NULL pointer dereference in func_set_flag()
Date: Tue, 07 Jul 2026 09:46:14 -0400 [thread overview]
Message-ID: <20260707134624.833964338@kernel.org> (raw)
In-Reply-To: 20260707134604.275787924@kernel.org
From: Yuanhe Shu <xiangzao@linux.alibaba.com>
func_set_flag() dereferences tr->current_trace_flags before verifying
that the current tracer is actually the function tracer. When the active
tracer has been switched away from "function" (e.g., to "wakeup_rt"),
tr->current_trace_flags can be NULL, leading to a NULL pointer
dereference and kernel crash.
The call chain that triggers this is:
trace_options_write()
-> __set_tracer_option()
-> trace->set_flag() /* func_set_flag */
In func_set_flag(), the first operation is:
if (!!set == !!(tr->current_trace_flags->val & bit))
This dereferences tr->current_trace_flags unconditionally. The safety
check that guards against a non-function tracer:
if (tr->current_trace != &function_trace)
return 0;
is placed *after* the dereference, which is too late.
This was observed with the following crash dump:
BUG: unable to handle page fault at 0000000000000000
RIP: func_set_flag+0xd
Call Trace:
__set_tracer_option+0x27
trace_options_write+0x75
vfs_write+0x12a
ksys_write+0x66
do_syscall_64+0x5b
RIP: ffffffff914c973d RSP: ff67ec88b01dfdf0 RFLAGS: 00010202
RAX: 0000000000000000 RBX: ff3a826e80354580 RCX: 0000000000000001
RDX: 0000000000000001 RSI: 0000000000000000 RDI: ffffffff93918080
The disassembly confirms the fault:
func_set_flag+0: mov 0x1f08(%rdi), %rax ; RAX = tr->current_trace_flags = NULL
func_set_flag+13: mov (%rax), %eax ; page fault: dereference NULL
At the time of the crash:
tr->current_trace_flags = 0x0 (NULL)
tr->current_trace = wakeup_rt_tracer (not function_trace)
The scenario is that a process opens a function tracer option file (such
as "func_stack_trace"), then the current tracer is switched to another
tracer (e.g., "wakeup_rt"), which sets current_trace_flags to NULL. When
the process subsequently writes to the option file, func_set_flag() is
invoked and crashes on the NULL dereference.
Fix this by moving the current_trace check before the
current_trace_flags dereference, so that func_set_flag() returns early
when the function tracer is not active.
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20260624061715.1445655-1-xiangzao@linux.alibaba.com
Fixes: 76680d0d2825 ("tracing: Have function tracer define options per instance")
Signed-off-by: Yuanhe Shu <xiangzao@linux.alibaba.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/trace_functions.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
index f283391a4dc8..cd37f2013758 100644
--- a/kernel/trace/trace_functions.c
+++ b/kernel/trace/trace_functions.c
@@ -458,12 +458,12 @@ func_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
ftrace_func_t func;
u32 new_flags;
- /* Do nothing if already set. */
- if (!!set == !!(tr->current_trace_flags->val & bit))
+ /* We can change this flag only when current tracer is function. */
+ if (tr->current_trace != &function_trace)
return 0;
- /* We can change this flag only when not running. */
- if (tr->current_trace != &function_trace)
+ /* Do nothing if already set. */
+ if (!!set == !!(tr->current_trace_flags->val & bit))
return 0;
new_flags = (tr->current_trace_flags->val & ~bit) | (set ? bit : 0);
--
2.53.0
next prev parent reply other threads:[~2026-07-07 13:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 13:46 [for-linus][PATCH 00/13] tracing: Fixes for 7.2 Steven Rostedt
2026-07-07 13:46 ` [for-linus][PATCH 01/13] tracing/synthetic: Free pending field on error path Steven Rostedt
2026-07-07 13:46 ` [for-linus][PATCH 02/13] ring-buffer: Fix event length with forced 8-byte alignment Steven Rostedt
2026-07-07 13:46 ` [for-linus][PATCH 03/13] tracing/osnoise: Call synchronize_rcu() when unregistering Steven Rostedt
2026-07-07 13:46 ` [for-linus][PATCH 04/13] tracing: Remove unused ret assignment in tracing_set_tracer() Steven Rostedt
2026-07-07 13:46 ` [for-linus][PATCH 05/13] ring_buffer: Check page order under reader_lock Steven Rostedt
2026-07-07 14:37 ` Steven Rostedt
2026-07-07 13:46 ` [for-linus][PATCH 06/13] ring-buffer: Fix ring_buffer_read_page() copying only one event per page Steven Rostedt
2026-07-07 13:46 ` [for-linus][PATCH 07/13] tracing: make tracepoint_printk static as not exported Steven Rostedt
2026-07-07 13:46 ` [for-linus][PATCH 08/13] tracing/user_events: Fix use-after-free of enabler in user_event_mm_dup() Steven Rostedt
2026-07-07 13:46 ` [for-linus][PATCH 09/13] samples: ftrace: Fix typos in benchmark comment Steven Rostedt
2026-07-07 13:46 ` Steven Rostedt [this message]
2026-07-07 13:46 ` [for-linus][PATCH 11/13] ufs: core: tracing: Do not dereference pointers in TP_printk() Steven Rostedt
2026-07-07 13:46 ` [for-linus][PATCH 12/13] tracing: Prevent out-of-bounds read in glob matching Steven Rostedt
2026-07-07 13:46 ` [for-linus][PATCH 13/13] tracing: Add a no-rcu-check version of trace_##event##_enabled() 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=20260707134624.833964338@kernel.org \
--to=rostedt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=stable@vger.kernel.org \
--cc=xiangzao@linux.alibaba.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 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.