Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] tracing/probes: Guard probe dispatchers with tracepoint_srcu
Date: Fri, 04 Dec 2026 03:57:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-249074@kernel.org> (raw)
In-Reply-To: <undine-1796354989220575981-7aae146b9ada56e1@undined.local>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] tracing/uprobe: tracepoint_srcu held across faultable and
  sleepable paths
- [Medium] tracing/kprobes: missing rcu_is_watching() check before
  SRCU-fast guard
- [Low] tracing/probes: comments misstate trace_probe_remove_file() RCU
  lifetime
--

commit d2d94f4e6bcf3ecc5841896141107d3fa875d240
Author: Masami Hiramatsu (Google) <mhiramat@kernel.org>

tracing/probes: Guard probe dispatchers with tracepoint_srcu

This commit wraps the kprobe, kretprobe, fentry, fexit, uprobe, and uretprobe
dispatchers in guard(srcu_fast_notrace)(&tracepoint_srcu) so they synchronize
with tracepoint_synchronize_unregister().  It also updates the comments above
trace_probe_remove_file() in the eprobe, fprobe, and kprobe disable paths.

> diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c
> index f65393fb1c102..9e9b2e53b42d2 100644
> --- a/kernel/trace/trace_eprobe.c
> +++ b/kernel/trace/trace_eprobe.c
> @@ -711,7 +711,10 @@ static int disable_trace_eprobe(struct trace_event_call *call,
>  	for_each_trace_eprobe_tp(ep, tp)
>  		disable_eprobe(ep, file->tr);
>  
> -	/* Synchronization is done in below function. */
> +	/*
> +	 * disable_eprobe() synchronizes via tracepoint_synchronize_unregister(),
> +	 * and trace_probe_remove_file() defers freeing link and file via call_rcu().
> +	 */
>  	trace_probe_remove_file(tp, file);

[Severity: Low]
Does trace_probe_remove_file() actually defer freeing file via call_rcu()?

trace_probe_remove_file() only unlinks and frees the event_file_link via
kvfree_rcu_mightsleep(link); it does not hold or release a reference to
struct trace_event_file.  Instead, remove_event_file_dir() frees file
synchronously via event_file_put().

The same wording appears in the commit message, disable_trace_fprobe(), and
disable_trace_kprobe().  The disable_trace_kprobe() comment also overstates
teardown synchronization, since dynamic kprobe removal through
unregister_trace_kprobe() -> trace_remove_event_call() frees file without
calling tracepoint_synchronize_unregister().

[ ... ]

> diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> index 1dd6a6942eb7d..474c7fd8da614 100644
> --- a/kernel/trace/trace_kprobe.c
> +++ b/kernel/trace/trace_kprobe.c

[ ... ]

> @@ -1834,11 +1834,13 @@ 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);
> +	unsigned int flags;
>  	int ret = 0;
>  
>  	raw_cpu_inc(*tk->nhit);
>  
> +	guard(srcu_fast_notrace)(&tracepoint_srcu);
> +	flags = trace_probe_load_flag(&tk->tp);
>  	if (flags & TP_FLAG_TRACE)
>  		kprobe_trace_func(tk, regs);
>  #ifdef CONFIG_PERF_EVENTS
> @@ -1867,6 +1869,7 @@ kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs)
>  	tk = container_of(rp, struct trace_kprobe, rp);
>  	raw_cpu_inc(*tk->nhit);
>  
> +	guard(srcu_fast_notrace)(&tracepoint_srcu);
>  	flags = trace_probe_load_flag(&tk->tp);
>  	if (flags & TP_FLAG_TRACE)
>  		kretprobe_trace_func(tk, ri, regs);

[Severity: Medium]
Can kprobe_dispatcher() or kretprobe_dispatcher() enter
guard(srcu_fast_notrace)(&tracepoint_srcu) while RCU is not watching?

srcu_read_lock_fast_notrace() relies on synchronize_rcu() inside
synchronize_srcu(&tracepoint_srcu) instead of a read-side smp_mb() and
skips lockdep's !rcu_is_watching() check.  Unlike fprobe callbacks, ftrace,
optprobe, and rethook kprobe paths never check rcu_is_watching().

A kprobe on a non-noinstr, non-blacklisted function running while RCU is
not watching (such as snooze_loop() in cpuidle-powernv.c after
ct_cpuidle_enter(), or native_play_dead() after rcutree_report_cpu_dead())
can then run on a CPU ignored by synchronize_rcu():

CPU0 (RCU not watching)           CPU1
kprobe_dispatcher()
  guard(srcu_fast_notrace)(...)
                                  event_trace_del_tracer()
                                    tracepoint_synchronize_unregister()
                                      synchronize_srcu(&tracepoint_srcu)
                                        synchronize_rcu()  /* skips CPU0 */
                                    free_trace_buffer(tr)
  kprobe_trace_func()
    ... dereferences file->tr  <-- use-after-free

Checking rcu_is_watching() (and excluding offline CPUs, since
rcutree_report_cpu_dead() leaves CT_RCU_WATCHING set) before acquiring
tracepoint_srcu would avoid this race.

> diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
> index fb7991543db7d..a53ffd8b27903 100644
> --- a/kernel/trace/trace_uprobe.c
> +++ b/kernel/trace/trace_uprobe.c
> @@ -1569,6 +1569,7 @@ static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs,
>  	if (WARN_ON_ONCE(!uprobe_cpu_buffer))
>  		return 0;
>  
> +	guard(srcu_fast_notrace)(&tracepoint_srcu);
>  	flags = trace_probe_load_flag(&tu->tp);
>  	if (flags & TP_FLAG_TRACE)
>  		ret |= uprobe_trace_func(tu, regs, &ucb);
> @@ -1600,6 +1601,7 @@ static int uretprobe_dispatcher(struct uprobe_consumer *con,
>  	if (WARN_ON_ONCE(!uprobe_cpu_buffer))
>  		return 0;
>  
> +	guard(srcu_fast_notrace)(&tracepoint_srcu);
>  	flags = trace_probe_load_flag(&tu->tp);
>  	if (flags & TP_FLAG_TRACE)
>  		uretprobe_trace_func(tu, func, regs, &ucb);

[Severity: High]
Will holding tracepoint_srcu across uprobe_dispatcher() and
uretprobe_dispatcher() stall non-faultable tracepoint grace periods
system-wide?

Every caller in kernel/events/uprobes.c (handle_swbp(),
handle_syscall_uprobe(), and handle_uretprobe_chain()) already holds
rcu_read_lock_trace(), which tracepoint_synchronize_unregister() waits on
via synchronize_rcu_tasks_trace().

Inside these dispatchers, prepare_uprobe_buffer() acquires
mutex_lock(&ucb->mutex) and performs faultable user-memory reads
(strnlen_user(), copy_from_user(), strncpy_from_user()), and
__uprobe_perf_func() runs sleepable BPF programs.

If a uprobe sleeps on a slow user page fault (for example via FUSE, NFS, or
userfaultfd) or ucb->mutex, it stalls tracepoint_srcu grace periods.  That
blocks tp_rcu_cond_sync() under the global tracepoints_mutex for unrelated
tracepoint register/unregister operations and delays call_srcu() cleanup.

Dropping the tracepoint_srcu guard from both uprobe dispatchers keeps
faultable readers on rcu_tasks_trace as intended.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/undine-1796354989220575981-7aae146b9ada56e1@undined.local?part=1

      reply	other threads:[~2026-12-04  3:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 16:23 [PATCH v2] tracing/probes: fix race between probe execution and event file removal Antoine Tenart
2026-12-02 16:33 ` Steven Rostedt
2026-12-03  1:20   ` Masami Hiramatsu (Google)
2026-12-03  2:06     ` Steven Rostedt
2026-12-04  3:05       ` Masami Hiramatsu (Google)
2026-12-02 16:45 ` sashiko-bot
2026-12-02 18:45   ` Steven Rostedt
2026-12-03  2:03     ` Masami Hiramatsu (Google)
2026-12-03 13:11       ` Steven Rostedt
2026-12-03 14:36         ` Masami Hiramatsu (Google)
2026-12-03 15:37           ` Steven Rostedt
2026-12-04  3:29       ` [PATCH] tracing/probes: Guard probe dispatchers with tracepoint_srcu Masami Hiramatsu (Google)
2026-12-04  3:57         ` 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=sashiko-outbox-249074@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox