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. It is static with one caller and gcc inlines it, which leaves the entry unresolved and breaks the build with CONFIG_WERROR=y, so mark it noinline. rcu_unlock_needs_exp_handling() also runs with .s set. It is normally inlined, but an out-of-line copy would recurse the same way, so mark it __always_inline. Suggested-by: Alexei Starovoitov Signed-off-by: Sechang Lim --- v3: - Mark rcu_read_unlock_special() noinline for gcc (Alexei) - Mark rcu_unlock_needs_exp_handling() __always_inline (Alexei) - Drop Bradley's Reviewed-by, since the patch now changes RCU v2: https://lore.kernel.org/bpf/20261125040106.2200628-1-rhkrqnwk98@gmail.com/ v1: https://lore.kernel.org/rcu/20261124185659.1370644-1-rhkrqnwk98@gmail.com/ kernel/bpf/verifier.c | 1 + kernel/rcu/tree_plugin.h | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) 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) diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h index ae5d21bae7bc..40996dc29b28 100644 --- a/kernel/rcu/tree_plugin.h +++ b/kernel/rcu/tree_plugin.h @@ -689,10 +689,10 @@ 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, - struct rcu_data *rdp, - struct rcu_node *rnp, - bool irqs_were_disabled) +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) { /* * Check if this task is blocking an expedited grace period. If the @@ -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; -- 2.56.1