BPF List
 help / color / mirror / Atom feed
From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: <sashiko-reviews@lists.linux.dev>
Cc: <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf v1 05/10] bpf: Reject resilient lock operations in rbtree callbacks
Date: Thu, 03 Sep 2026 17:36:40 +0200	[thread overview]
Message-ID: <DL5SJK7Q489U.1HFUM2S4I4G71@gmail.com> (raw)
In-Reply-To: <20260903153146.2C3A81F00A3A@smtp.kernel.org>

On Thu Sep 3, 2026 at 5:31 PM CEST, sashiko-bot wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] The restriction against calling lock operations inside rbtree callbacks can be bypassed by nesting callbacks or calling subprograms, because in_rbtree_lock_required_cb() only checks the immediate top frame.
> --
>
> commit c5914f67e15078bc12af13429620d2a2a4de2b11
> Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
>
> bpf: Reject resilient lock operations in rbtree callbacks
>
> This patch attempts to enforce the root's lock requirement for resilient
> locks in rbtree callbacks. It aims to prevent use-after-free conditions
> when nodes are removed and freed by other CPUs during the in-progress tree
> walk.
>
>> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
>> index f540279ff4abb..32d31fa67036b 100644
>> --- a/kernel/bpf/verifier.c
>> +++ b/kernel/bpf/verifier.c
>> @@ -13241,6 +13241,11 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_call_arg_me
>>  		{
>>  			int flags = PROCESS_RES_LOCK;
>>
>> +			if (in_rbtree_lock_required_cb(env)) {
>                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> [Severity: High]
> This isn't a bug introduced by this patch, but does
> in_rbtree_lock_required_cb() fully protect against this bypass?
>
> Looking at in_rbtree_lock_required_cb(), it only checks the immediate top
> frame:
>
> kernel/bpf/verifier.c:in_rbtree_lock_required_cb() {
>     ...
> 	callee = state->frame[state->curframe];
>
> 	if (!callee->in_callback_fn)
> 		return false;
>
> 	kfunc_btf_id = insn[callee->callsite].imm;
> 	return is_rbtree_lock_required_kfunc(kfunc_btf_id);
> }
>
> If a BPF program calls a custom rbtree comparison callback, and inside that
> callback it calls a static subprogram (or a nested callback like bpf_loop()),
> would state->curframe's in_callback_fn be false (or its kfunc_btf_id not
> match the rbtree add kfunc)?
>
> Could a program use this nested frame to successfully unlock the resilient
> lock via a global map value (BPF_PSEUDO_MAP_VALUE), temporarily dropping the
> lock and allowing another CPU to concurrently remove and free the nodes being
> traversed by bpf_rbtree_add(), leading to a Use-After-Free?
>

Separate bug, will be separate fix. Let's still add this one.

>> +				verbose(env, "can't res_spin_{lock,unlock} in rbtree cb\n");
>> +				return -EACCES;
>> +			}
>> +
>>  			if (reg->type != PTR_TO_MAP_VALUE && reg->type != (PTR_TO_BTF_ID | MEM_ALLOC)) {
>>  				verbose(env, "%s doesn't point to map value or allocated object\n",
>>  					reg_arg_name(env, argno));


  reply	other threads:[~2026-09-03 15:36 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03 14:44 [PATCH bpf v1 00/10] Misc bug fixes - part 1 Kumar Kartikeya Dwivedi
2026-09-03 14:44 ` [PATCH bpf v1 01/10] bpf: Mark signal tracepoint siginfo arguments as scalar Kumar Kartikeya Dwivedi
2026-09-03 15:52   ` bot+bpf-ci
2026-09-03 16:47     ` Alexei Starovoitov
2026-09-03 14:44 ` [PATCH bpf v1 02/10] selftests/bpf: Cover signal tracepoint siginfo sentinels Kumar Kartikeya Dwivedi
2026-09-03 15:52   ` bot+bpf-ci
2026-09-03 14:44 ` [PATCH bpf v1 03/10] bpf: Reject tail calls directly from callback frames Kumar Kartikeya Dwivedi
2026-09-03 15:21   ` sashiko-bot
2026-09-03 15:36     ` Kumar Kartikeya Dwivedi
2026-09-03 14:44 ` [PATCH bpf v1 04/10] selftests/bpf: Test direct tail calls from callbacks Kumar Kartikeya Dwivedi
2026-09-03 14:44 ` [PATCH bpf v1 05/10] bpf: Reject resilient lock operations in rbtree callbacks Kumar Kartikeya Dwivedi
2026-09-03 15:31   ` sashiko-bot
2026-09-03 15:36     ` Kumar Kartikeya Dwivedi [this message]
2026-09-03 14:44 ` [PATCH bpf v1 06/10] selftests/bpf: Reject resilient unlock in rbtree callback Kumar Kartikeya Dwivedi
2026-09-03 15:52   ` bot+bpf-ci
2026-09-03 14:44 ` [PATCH bpf v1 07/10] bpf: Mark sched_process_wait argument as nullable Kumar Kartikeya Dwivedi
2026-09-03 15:52   ` bot+bpf-ci
2026-09-03 14:44 ` [PATCH bpf v1 08/10] selftests/bpf: Test sched_process_wait nullable argument Kumar Kartikeya Dwivedi
2026-09-03 14:44 ` [PATCH bpf v1 09/10] bpf: Mark syscall helpers as sleepable Kumar Kartikeya Dwivedi
2026-09-03 15:51   ` sashiko-bot
2026-09-03 15:54     ` Kumar Kartikeya Dwivedi
2026-09-03 15:52   ` bot+bpf-ci
2026-09-03 14:44 ` [PATCH bpf v1 10/10] selftests/bpf: Check syscall helpers in timer callbacks Kumar Kartikeya Dwivedi
2026-09-03 16:50 ` [PATCH bpf v1 00/10] Misc bug fixes - part 1 patchwork-bot+netdevbpf

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=DL5SJK7Q489U.1HFUM2S4I4G71@gmail.com \
    --to=memxor@gmail.com \
    --cc=bpf@vger.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