From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796356666; b=E3k577Ah5TTWkV40Y0EI5NU2dbD+tuF0no3KTYVy+mpA+BYTvAwFDeAaqxI+KIYPqzTL Jciqekc+kJhEEXmJPvrCMqgKZ3FdzMY7T1CL1hIM2QVs6cOC2YrsSDig95zumL62IyrPI jRhiw3mlvua0l/GJqK+j9McTmxV+rwAdZMRBdHyBVqBqcFca6UboSZU4hdUsL0mFY3W0d G0AJQUOf7q69UJewv/9PvmukTVswqMtz5OXpn5Wh68tuw520tQq94HKpvA0EnRyr7tRz5 bzWzSlkG5R8dxNfU+6IRxGbpH64PAnZdnoQlmM0MLgmkWMVcs1TkygMBssewW/sBAfw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796356666; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=NknSgtpjmC8aodYO25Mk95HA7f/ZfnDR63I95DDA7YY=; b=PB7nsikDQLuWrFGvrhzYfNHjOTLclNqDWcWzQnnFcVUJ427AL57saTqI0+WdUkIWzpdf 575CHGDhexHiIBp78bbxkJdCjvEZCpwcHJNyfl84fZZzCWidQxsnDS1e+n8WnrYgZPgoF 0UnlyFEpz5h6oXc6tkx5MPLQ3rDbT6T7eE/DmGe3XHfvhXaqf/quk8eCbHYS/3iG3P0Ks yfm+nfsT/UdpTsZyo77HUzNDcw/ZOcpnJxnLZC9w0Ss/ixh8EFT40UnkB+u+vFE7ww1Q1 CCd67zK3MaZyyE8T2XKB64FOLiuAwLRAU1XWhX1K4TEUB1+JVO8JUh8lfLt0tFhdotQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Bpo5ytpW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D39F606A322 for ; Fri, 4 Dec 2026 03:57:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Bpo5ytpW Received: by smtp.kernel.org (Postfix) with ESMTPSA id 890E21F000C2; Fri, 4 Dec 2026 03:57:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796356665; bh=NknSgtpjmC8aodYO25Mk95HA7f/ZfnDR63I95DDA7YY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Bpo5ytpWRBx6OsKNIXnYej93UYTJqVR45CDaElSw56t1LVlRSviT8PEO7/BXY+GY8 lmMrjGD8vhAdbG7FiMHikvG/jpXp/9w1JB3p+XGnHLEb5GSKsIPq//EVzPI7Gv4wjF var2V4HzxbuZddxGaqeNa4RSCLI43auB+Fzoq4OfRGIDFxf5rCR5etPvzYascThdXZ zjhHfpNrbT6IDQmxuRY5ddwYJ/11M5Cj2KOehuSFHvSym0NqWugtk7+P30ndshK3cz baAt3g44lnV+b+mwNZ5kNgPgyVGuO4NU9vGJhRF/R1M1SsuTk/uqwJNiH1GDxLnw7E 9FN4biL0gYEeA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] tracing/probes: Guard probe dispatchers with tracepoint_srcu Reply-To: sashiko-reviews@lists.linux.dev To: =?utf-8?b?TWFzYW1pIEhpcmFtYXRzdSAoR29vZ2xlKQ==?= Cc: linux-trace-kernel@vger.kernel.org In-Reply-To: References: <20261202162333.168965-1-atenart@kernel.org> <20261202134534.45108fef@gandalf.local.home> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 03:57:45 +0000 X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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) tracing/probes: Guard probe dispatchers with tracepoint_srcu This commit wraps the kprobe, kretprobe, fentry, fexit, uprobe, and uretpro= be dispatchers in guard(srcu_fast_notrace)(&tracepoint_srcu) so they synchroni= ze with tracepoint_synchronize_unregister(). It also updates the comments abo= ve 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_c= all *call, > for_each_trace_eprobe_tp(ep, tp) > disable_eprobe(ep, file->tr); > =20 > - /* 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_cal= l *event, > static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs) > { > struct trace_kprobe *tk =3D container_of(kp, struct trace_kprobe, rp.kp= ); > - unsigned int flags =3D trace_probe_load_flag(&tk->tp); > + unsigned int flags; > int ret =3D 0; > =20 > raw_cpu_inc(*tk->nhit); > =20 > + guard(srcu_fast_notrace)(&tracepoint_srcu); > + flags =3D 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 =3D container_of(rp, struct trace_kprobe, rp); > raw_cpu_inc(*tk->nhit); > =20 > + guard(srcu_fast_notrace)(&tracepoint_srcu); > flags =3D 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; > =20 > + guard(srcu_fast_notrace)(&tracepoint_srcu); > flags =3D trace_probe_load_flag(&tu->tp); > if (flags & TP_FLAG_TRACE) > ret |=3D uprobe_trace_func(tu, regs, &ucb); > @@ -1600,6 +1601,7 @@ static int uretprobe_dispatcher(struct uprobe_consu= mer *con, > if (WARN_ON_ONCE(!uprobe_cpu_buffer)) > return 0; > =20 > + guard(srcu_fast_notrace)(&tracepoint_srcu); > flags =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/undine-179635498922= 0575981-7aae146b9ada56e1@undined.local?part=3D1