From: Peter Zijlstra <peterz@infradead.org>
To: chenyuan_fl@163.com
Cc: mhiramat@kernel.org, bigeasy@linutronix.de, chenyuan@kylinos.cn,
john.ogness@linutronix.de, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org,
mathieu.desnoyers@efficios.com, rostedt@goodmis.org
Subject: Re: [PATCH v4] tracing: Fix race condition in kprobe initialization causing NULL pointer dereference
Date: Wed, 1 Oct 2025 14:32:00 +0200 [thread overview]
Message-ID: <20251001123200.GN4067720@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20251001022025.44626-1-chenyuan_fl@163.com>
On Wed, Oct 01, 2025 at 03:20:25AM +0100, chenyuan_fl@163.com wrote:
>
> v1->v2: Fix race analysis (per Masami) - kprobe arms in class->reg().
> v2->v3: Adopt RELEASE/ACQUIRE semantics per Peter/John's suggestions,
> aligning with Steven's clarification on barrier purposes.
> v3->v4: Introduce load_flag() (Masami) and optimize barrier usage in
> checks/clear (Peter).
Stuff like this ought to go below the --- such that git-am and similar
tools throw it out.
> Signed-off-by: Yuan Chen <chenyuan@kylinos.cn>
> ---
> diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> index ccae62d4fb91..b1b793b8f191 100644
> --- a/kernel/trace/trace_kprobe.c
> +++ b/kernel/trace/trace_kprobe.c
> @@ -1813,14 +1813,15 @@ static int kprobe_register(struct trace_event_call *event,
> static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs)
> {
> struct trace_kprobe *tk = container_of(kp, struct trace_kprobe, rp.kp);
> + unsigned int flags = trace_probe_load_flag(&tk->tp);
> int ret = 0;
>
> raw_cpu_inc(*tk->nhit);
>
> - if (trace_probe_test_flag(&tk->tp, TP_FLAG_TRACE))
> + if (flags & TP_FLAG_TRACE)
> kprobe_trace_func(tk, regs);
> #ifdef CONFIG_PERF_EVENTS
> - if (trace_probe_test_flag(&tk->tp, TP_FLAG_PROFILE))
> + if (flags & TP_FLAG_PROFILE)
> ret = kprobe_perf_func(tk, regs);
> #endif
> return ret;
> @@ -1832,6 +1833,7 @@ kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs)
> {
> struct kretprobe *rp = get_kretprobe(ri);
> struct trace_kprobe *tk;
> + unsigned int flags;
>
> /*
> * There is a small chance that get_kretprobe(ri) returns NULL when
> @@ -1844,10 +1846,11 @@ kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs)
> tk = container_of(rp, struct trace_kprobe, rp);
> raw_cpu_inc(*tk->nhit);
>
> - if (trace_probe_test_flag(&tk->tp, TP_FLAG_TRACE))
> + flags = trace_probe_load_flag(&tk->tp);
> + if (flags & TP_FLAG_TRACE)
> kretprobe_trace_func(tk, ri, regs);
> #ifdef CONFIG_PERF_EVENTS
> - if (trace_probe_test_flag(&tk->tp, TP_FLAG_PROFILE))
> + if (flags & TP_FLAG_PROFILE)
> kretprobe_perf_func(tk, ri, regs);
> #endif
> return 0; /* We don't tweak kernel, so just return 0 */
These two are inconsistent in that the first does load_flag before
inc(nhit) while the second does it after. I don't think it matters, but
I noticed the inconsistent style and had to tell.
Anyway, patch looks reasonable now. Rest is up to Steve, this is his
code.
next prev parent reply other threads:[~2025-10-01 12:32 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-29 3:11 [PATCH] " chenyuan_fl
2025-09-29 5:39 ` Masami Hiramatsu
2025-09-29 6:57 ` [PATCH v2] " chenyuan_fl
2025-09-29 8:48 ` Steven Rostedt
2025-09-29 9:12 ` Peter Zijlstra
2025-09-29 9:32 ` John Ogness
2025-09-29 10:12 ` Peter Zijlstra
2025-09-30 8:58 ` Masami Hiramatsu
2025-09-30 10:10 ` Peter Zijlstra
2025-09-30 15:37 ` Masami Hiramatsu
2025-09-30 8:18 ` [PATH v3] " chenyuan_fl
2025-09-30 8:46 ` Peter Zijlstra
2025-09-30 15:37 ` Masami Hiramatsu
2025-10-01 2:20 ` [PATCH v4] " chenyuan_fl
2025-10-01 12:32 ` Peter Zijlstra [this message]
2025-10-01 14:31 ` Steven Rostedt
2025-10-01 22:59 ` Masami Hiramatsu
2025-10-02 14:04 ` Masami Hiramatsu
2025-10-01 23:23 ` Masami Hiramatsu
2025-09-30 9:13 ` [PATH v3] " John Ogness
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=20251001123200.GN4067720@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bigeasy@linutronix.de \
--cc=chenyuan@kylinos.cn \
--cc=chenyuan_fl@163.com \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.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
Powered by JetHome