From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Eduard Zingerman" <eddyz87@gmail.com>, <bpf@vger.kernel.org>
Cc: <andrii@kernel.org>, <daniel@iogearbox.net>, <kernel-team@fb.com>,
<yonghong.song@linux.dev>
Subject: Re: [PATCH bpf-next 1/9] bpf: static subprogram arguments liveness should use BTF type info
Date: Sun, 11 Oct 2026 13:29:34 +0000 [thread overview]
Message-ID: <DM21MY4LE3MC.RAS8LM9O12RE@gmail.com> (raw)
In-Reply-To: <20261010-scev-minimal-v3-followups-v1-1-6000e95ef993@gmail.com>
On Sat, Oct 10, 2026 at 11:21 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> @@ -8829,10 +8828,13 @@ int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog)
> return -EINVAL;
> }
>
> - err = btf_check_arg_slots(log, tname, is_global, slots_used, sub);
> + if (verifier_bug_if(slots_used != sub->arg_slot_cnt, env,
> + "func#%d argument slot count mismatch: %u != %u",
> + subprog, slots_used, sub->arg_slot_cnt))
> + return -EFAULT;
> + err = btf_check_arg_slots(log, tname, is_global, sub->arg_slot_cnt, sub);
> if (err)
> return err;
> - sub->arg_slot_cnt = slots_used;
[...]
> + /* BTF validation guarantees FUNC -> FUNC_PROTO. */
> + t = btf_type_by_id(aux->btf, aux->func_info[i].type_id);
> + t = btf_type_by_id(aux->btf, t->type);
> + env->subprog_info[i].arg_slot_cnt = min_t(u32, btf_proto_slots(aux->btf, t),
> + MAX_BPF_FUNC_ARGS);
Consider the following...
arg_slot_cnt is not only for liveness.
bpf_in_stack_arg_cnt() is derived from it and it has to be in sync
with sub->stack_arg_cnt, which is still set by btf_check_arg_slots() only.
For example:
struct with_ptr { void *p; u64 x; };
static u64 f(int a, int b, int c, int d, struct with_ptr s)
nargs == 5, so the first btf_check_arg_slots() does nothing.
Then btf_prepare_func_args() returns -EINVAL on 's' and
the second btf_check_arg_slots() is not reached.
Before this patch arg_slot_cnt was 5 and r11 + 8 load in f()
was rejected.
Now arg_slot_cnt == 6 and stack_arg_cnt == 0.
The load is accepted, bpf_jit_supports_stack_args() is not checked,
and bpf_out_stack_arg_cnt() returns (u16)(0 - 1).
x86 JIT emits 'sub rsp, 65520' in the prologue of f().
This scenario looks bad enough.
Also btf_arg_slots() returns (size + 7) / 8 for a struct of any size.
BTF has the source signature. The compiler passes 48 byte struct by
reference or promotes its fields, but here it's 6 slots, so
check_outgoing_stack_args() returns -EFAULT and the prog is rejected.
It was loading fine with this subprog marked as unreliable.
Why is this rewrite needed?
prepare_subprog_args() was calling btf_prepare_func_args() for static
subprogs already. When it succeeds arg_slot_cnt is exact.
When it fails the first call marks the subprog as unreliable
regardless of what is in the registers.
So the liveness.c hunk alone should be enough?
The other patches look good.
pw-bot: cr
next prev parent reply other threads:[~2026-10-11 13:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-11 6:21 [PATCH bpf-next 0/9] bpf: follow-up for scalar evolution series Eduard Zingerman
2026-10-11 6:21 ` [PATCH bpf-next 1/9] bpf: static subprogram arguments liveness should use BTF type info Eduard Zingerman
2026-10-11 6:38 ` sashiko-bot
2026-10-11 13:29 ` Alexei Starovoitov [this message]
2026-10-11 6:21 ` [PATCH bpf-next 2/9] bpf: more precise stack liveness effects for global func params Eduard Zingerman
2026-10-11 6:21 ` [PATCH bpf-next 3/9] bpf: avoid duplicate declaration for BPF_SCEV_REGS_NUM Eduard Zingerman
2026-10-11 6:55 ` bot+bpf-ci
2026-10-11 6:21 ` [PATCH bpf-next 4/9] bpf: reg_bounds_sync() comment fixup Eduard Zingerman
2026-10-11 6:21 ` [PATCH bpf-next 5/9] selftests/bpf: static subprogram argument side liveness tests Eduard Zingerman
2026-10-11 7:17 ` bot+bpf-ci
2026-10-11 6:21 ` [PATCH bpf-next 6/9] selftests/bpf: stack effects of scalar/dynptr global subprog params Eduard Zingerman
2026-10-11 6:21 ` [PATCH bpf-next 7/9] selftests/bpf: harden __msg pattern for global_callee_btf_arg Eduard Zingerman
2026-10-11 6:21 ` [PATCH bpf-next 8/9] selftests/bpf: harden __msg patterns for step_movsx_bounds_on_line Eduard Zingerman
2026-10-11 6:21 ` [PATCH bpf-next 9/9] selftests/bpf: BPF_F_ANY_ALIGNMENT for byte_array_size_spanning() Eduard Zingerman
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=DM21MY4LE3MC.RAS8LM9O12RE@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kernel-team@fb.com \
--cc=yonghong.song@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