* [PATCH bpf-next v2] bpf: Add rcu_read_unlock_special() into btf id deny list
@ 2026-11-25 4:01 Sechang Lim
2026-11-25 4:23 ` sashiko-bot
2026-11-25 4:44 ` Alexei Starovoitov
0 siblings, 2 replies; 3+ messages in thread
From: Sechang Lim @ 2026-11-25 4:01 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi
Cc: John Fastabend, Martin KaFai Lau, Song Liu, Yonghong Song,
Jiri Olsa, Emil Tsalapatis, Ihor Solodrai, Bradley Morgan,
Paul E. McKenney, Frederic Weisbecker, Neeraj Upadhyay,
Joel Fernandes, Josh Triplett, Boqun Feng, Uladzislau Rezki,
Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan, Zqiang, rcu,
bpf
The BPF trampoline takes and drops the RCU read lock itself. When the
outermost rcu_read_unlock() finds ->rcu_read_unlock_special.s set, it
calls rcu_read_unlock_special(). If a fentry program is attached to
rcu_read_unlock_special(), the unlock on the trampoline exit path still
sees .s set and calls rcu_read_unlock_special() again, which recurses
until the stack overflows:
BUG: TASK stack guard page was hit at ffffc90001657ff8
...
bpf_trampoline_6442575622+0x5e/0xac
rcu_read_unlock_special+0x5/0x490
__rcu_read_unlock+0x9c/0x120
rcu_read_unlock_migrate+0x93/0x220
bpf_trampoline_6442575622+0x5e/0xac
rcu_read_unlock_special+0x5/0x490
...
With fexit it recurses even earlier, from percpu_ref_get() in
__bpf_tramp_enter(), which takes and drops the RCU read lock before the
program runs.
__rcu_read_unlock() is in the deny list for the same reason. Add
rcu_read_unlock_special() too.
Suggested-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev>
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
v2:
- Deny the attach in btf_id_deny instead of marking the function
notrace (Alexei)
v1: https://lore.kernel.org/rcu/20261124185659.1370644-1-rhkrqnwk98@gmail.com/
kernel/bpf/verifier.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index e7013ed8cadd..0e8afc0250b5 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -24735,6 +24735,7 @@ BTF_ID(func, preempt_count_sub)
#ifdef CONFIG_PREEMPT_RCU
BTF_ID(func, __rcu_read_lock)
BTF_ID(func, __rcu_read_unlock)
+BTF_ID(func, rcu_read_unlock_special)
#endif
BTF_SET_END(btf_id_deny)
--
2.56.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next v2] bpf: Add rcu_read_unlock_special() into btf id deny list
2026-11-25 4:01 [PATCH bpf-next v2] bpf: Add rcu_read_unlock_special() into btf id deny list Sechang Lim
@ 2026-11-25 4:23 ` sashiko-bot
2026-11-25 4:44 ` Alexei Starovoitov
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-25 4:23 UTC (permalink / raw)
To: Sechang Lim; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf: unresolved BTF_ID for static inlinable
rcu_read_unlock_special()
--
commit d423a98c605ab7698cdc1fbadbd9de2303d91def
Author: Sechang Lim <rhkrqnwk98@gmail.com>
bpf: Add rcu_read_unlock_special() into btf id deny list
This commit adds rcu_read_unlock_special() to the btf_id_deny set under
CONFIG_PREEMPT_RCU to prevent infinite recursion when attaching fentry or
fexit BPF programs to it.
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index e7013ed8cadd7..0e8afc0250b54 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -24735,6 +24735,7 @@ BTF_ID(func, preempt_count_sub)
> #ifdef CONFIG_PREEMPT_RCU
> BTF_ID(func, __rcu_read_lock)
> BTF_ID(func, __rcu_read_unlock)
> +BTF_ID(func, rcu_read_unlock_special)
> #endif
> BTF_SET_END(btf_id_deny)
[Severity: Medium]
Can resolve_btfids fail to resolve rcu_read_unlock_special when the
compiler inlines it?
rcu_read_unlock_special() is defined in kernel/rcu/tree_plugin.h as a
static function without noinline, and __rcu_read_unlock() is its only
caller. When the compiler inlines it and elides the out-of-line
definition, no BTF_KIND_FUNC entry is emitted in vmlinux, causing
resolve_btfids to emit an unresolved symbol warning (or fail the build
when CONFIG_WERROR=y passes --fatal_warnings). Should
rcu_read_unlock_special() be marked noinline as well?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125040106.2200628-1-rhkrqnwk98@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next v2] bpf: Add rcu_read_unlock_special() into btf id deny list
2026-11-25 4:01 [PATCH bpf-next v2] bpf: Add rcu_read_unlock_special() into btf id deny list Sechang Lim
2026-11-25 4:23 ` sashiko-bot
@ 2026-11-25 4:44 ` Alexei Starovoitov
1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2026-11-25 4:44 UTC (permalink / raw)
To: Sechang Lim, Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman,
Kumar Kartikeya Dwivedi
Cc: John Fastabend, Martin KaFai Lau, Song Liu, Yonghong Song,
Jiri Olsa, Emil Tsalapatis, Ihor Solodrai, Bradley Morgan,
Paul E. McKenney, Frederic Weisbecker, Neeraj Upadhyay,
Joel Fernandes, Josh Triplett, Boqun Feng, Uladzislau Rezki,
Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan, Zqiang, rcu,
bpf
On Tue, Nov 24, 2026 at 08:01 PM Sechang Lim <rhkrqnwk98@gmail.com> wrote:
> BTF_ID(func, __rcu_read_lock)
> BTF_ID(func, __rcu_read_unlock)
> +BTF_ID(func, rcu_read_unlock_special)
This will break gcc builds with KASAN and WERROR.
It was my suggestion, sorry.
The other entries are global functions. This one is static and has
one caller, so gcc inlines it in KASAN builds.
The splat in commit 684c68d92e2e has no such frame:
rcu_preempt_deferred_qs_irqrestore+0x74/0xed0
__rcu_read_unlock+0x290/0x3b0
On x86 __rcu_read_unlock() is 0x2f0 bytes in commit caf3ef7468f7
and 0x120 bytes in your log.
Without a symbol there is no FUNC in BTF, and id_patch() prints:
WARN: resolve_btfids: unresolved symbol rcu_read_unlock_special
WERROR makes it fatal. Sasha fixed such breaks last month:
https://lore.kernel.org/bpf/20261019211006.2574350-1-sashal@kernel.org/
rcu_unlock_needs_exp_handling() also runs with .s set and no guard.
fentry on an out-of-line copy recurses the same way.
It's normally inlined, so it cannot go into btf_id_deny.
Plain inline is not enough. Song's series drops notrace from it:
https://lore.kernel.org/bpf/20261023011049.1164625-1-song@kernel.org/
Two attributes in tree_plugin.h on top of your patch cover both.
clang builds tree.o with them. I didn't try gcc, the BTF step or a boot.
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index ae5d21b..5f2f56c 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -689,7 +689,7 @@ static void rcu_preempt_deferred_qs_handler(struct irq_work *iwp)
*
* Returns true if expedited processing of the rcu_read_unlock() is needed.
*/
-static bool rcu_unlock_needs_exp_handling(struct task_struct *t,
+static __always_inline bool rcu_unlock_needs_exp_handling(struct task_struct *t,
struct rcu_data *rdp,
struct rcu_node *rnp,
bool irqs_were_disabled)
@@ -745,8 +745,10 @@ static bool rcu_unlock_needs_exp_handling(struct task_struct *t,
* Handle special cases during rcu_read_unlock(), such as needing to
* notify RCU core processing or task having blocked during the RCU
* read-side critical section.
+ *
+ * noinline: btf_id_deny in kernel/bpf/verifier.c needs it in BTF.
*/
-static void rcu_read_unlock_special(struct task_struct *t)
+static noinline void rcu_read_unlock_special(struct task_struct *t)
{
unsigned long flags;
bool irqs_were_disabled;
Pls fold it in and build with gcc and KASAN.
Please cc Paul and rcu folks on a respin.
pw-bot: cr
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-25 4:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 4:01 [PATCH bpf-next v2] bpf: Add rcu_read_unlock_special() into btf id deny list Sechang Lim
2026-11-25 4:23 ` sashiko-bot
2026-11-25 4:44 ` Alexei Starovoitov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox