All of lore.kernel.org
 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 03/10] bpf: Reject tail calls directly from callback frames
Date: Thu, 03 Sep 2026 17:36:54 +0200	[thread overview]
Message-ID: <DL5SJQEFQ56S.26JAOHTQ8JXPY@gmail.com> (raw)
In-Reply-To: <20260903152147.C0E241F00A3A@smtp.kernel.org>

On Thu Sep 3, 2026 at 5:21 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 patch prevents bpf_tail_call within a callback to fix the 'callback unexpected regs' verifier bug, but misses that BPF_LD_ABS and BPF_LD_IND trigger the exact same bug via the same prepare_func_exit() path.
> --
>
> commit a25ccc5cdb72d9330414949c17ecac5156595510
> Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
>
>     bpf: Reject tail calls directly from callback frames
>
>     A tail call from a non-zero frame is modeled as a return from that frame,
>     synthesizing R0 and calling prepare_func_exit() for the taken branch.
>     When the current frame is a synchronous callback, prepare_func_exit()
>     enforces the callback return-value contract and marks R0 precise, triggering
>     the "callback unexpected regs" verifier warning during precision backtracking.
>     This patch rejects a tail call made directly by a callback before
>     constructing the inconsistent return state.
>
>> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
>> index 7d8ddb1bee00c..f540279ff4abb 100644
>> --- a/kernel/bpf/verifier.c
>> +++ b/kernel/bpf/verifier.c
>> @@ -11228,6 +11228,17 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
>>  		if (env->cur_state->curframe) {
>>  			struct bpf_verifier_state *branch;
>>
>> +			/*
>> +			 * A taken tail call is modeled as a return from the current
>> +			 * frame. A callback frame cannot be left that way because
>> +			 * prepare_func_exit() would apply its return contract to the
>> +			 * unknown R0 synthesized below. Stack-depth validation rejects
>> +			 * this construct anyway.
>> +			 */
>> +			if (cur_func(env)->in_callback_fn) {
>> +				verbose(env, "cannot tail call within callback\n");
>> +				return -EINVAL;
>> +			}
>
> [Severity: High]
> This isn't a bug introduced by this patch, but doesn't BPF_LD_ABS inside a
> subprog trigger the exact same bug via the same prepare_func_exit() path?
>
> Looking at check_ld_abs() in kernel/bpf/verifier.c:
>
>     if (env->cur_state->curframe) {
>         struct bpf_verifier_state *branch;
>
>         mark_reg_scratched(env, BPF_REG_0);
>         branch = push_stack(env, env->insn_idx + 1, env->insn_idx, false);
>         if (IS_ERR(branch))
>             return PTR_ERR(branch);
>         mark_reg_known_zero(env, regs, BPF_REG_0);
>         err = prepare_func_exit(env, &env->insn_idx);
>         if (err)
>             return err;
>         env->insn_idx--;
>     }
>
> If a CAP_BPF user loads a SCHED_CLS program (where BPF_LD_ABS is allowed),
> invokes bpf_loop(), passes PTR_TO_CTX through the stack to the callback_ctx
> argument, loads the context into R6 inside the callback, and executes
> BPF_LD_ABS, it appears check_ld_abs() will synthesize R0 and call
> prepare_func_exit().
>
> Since the callback frame lacks instruction history for R0, won't precision
> backtracking fail and hit the exact same "callback unexpected regs" verifier
> warning? Does check_ld_abs() need a similar rejection for callbacks?
>

Has to be fixed separately.

>>  			mark_reg_scratched(env, BPF_REG_0);
>>  			branch = push_stack(env, env->insn_idx + 1, env->insn_idx, false);
>>  			if (IS_ERR(branch))


  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 [this message]
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
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=DL5SJQEFQ56S.26JAOHTQ8JXPY@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 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.