From: Puranjay Mohan <puranjay@kernel.org>
To: Leon Hwang <hffilwlqm@gmail.com>, bpf@vger.kernel.org
Cc: kkd@meta.com, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
kernel-team@fb.com
Subject: Re: [PATCH bpf-next] bpf: support nested rcu critical sections
Date: Wed, 17 Sep 2025 14:03:27 +0000 [thread overview]
Message-ID: <mb61pa52tqiq8.fsf@kernel.org> (raw)
In-Reply-To: <c6e2c3c6-2ce5-4b52-8429-bcda39e452ab@gmail.com>
Leon Hwang <hffilwlqm@gmail.com> writes:
> On 16/9/25 19:36, Puranjay Mohan wrote:
>> Currently, nested rcu critical sections are rejected by the verifier and
>> rcu_lock state is managed by a boolean variable. Add support for nested
>> rcu critical sections by make active_rcu_locks a counter similar to
>> active_preempt_locks. bpf_rcu_read_lock() increments this counter and
>> bpf_rcu_read_unlock() decrements it, MEM_RCU -> PTR_UNTRUSTED transition
>> happens when active_rcu_locks drops to 0.
>>
>> Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
>> ---
>
> [...]
>
>> @@ -13863,7 +13863,7 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
>> preempt_disable = is_kfunc_bpf_preempt_disable(&meta);
>> preempt_enable = is_kfunc_bpf_preempt_enable(&meta);
>>
>> - if (env->cur_state->active_rcu_lock) {
>> + if (env->cur_state->active_rcu_locks) {
>> struct bpf_func_state *state;
>> struct bpf_reg_state *reg;
>> u32 clear_mask = (1 << STACK_SPILL) | (1 << STACK_ITER);
>> @@ -13874,22 +13874,22 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
>> }
>>
>> if (rcu_lock) {
>> - verbose(env, "nested rcu read lock (kernel function %s)\n", func_name);
>> - return -EINVAL;
>> + env->cur_state->active_rcu_locks++;
>
> Could we add a check for the maximum of 'active_rcu_locks'?
>
> From a cracker's perspective, this could potentially be abused to
> stall the kernel or trigger a deadlock. Underneath 'rcu_read_lock()',
> there are several RCU functions that tracing programs are able to
> attach to. If those functions are traced, a deadlock can be triggered.
>
IIUC what you are saying is that if I attach a BPF tracing program to
something under rcu_read_lock() and then call bpf_rcu_read_lock() in the
BPF program then there could recursion? Wouldn't that be triggered even
with a single call to bpf_rcu_read_lock() ?
Thanks,
Puranjay
next prev parent reply other threads:[~2025-09-17 14:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-16 11:36 [PATCH bpf-next] bpf: support nested rcu critical sections Puranjay Mohan
2025-09-16 20:34 ` Alexei Starovoitov
2025-09-17 13:43 ` Puranjay Mohan
2025-09-16 23:26 ` Eduard Zingerman
2025-09-17 13:44 ` Puranjay Mohan
2025-09-17 0:59 ` Kumar Kartikeya Dwivedi
2025-09-17 4:51 ` Leon Hwang
2025-09-17 14:03 ` Puranjay Mohan [this message]
2025-09-18 2:25 ` Leon Hwang
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=mb61pa52tqiq8.fsf@kernel.org \
--to=puranjay@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=hffilwlqm@gmail.com \
--cc=kernel-team@fb.com \
--cc=kkd@meta.com \
--cc=martin.lau@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.