From: Yonghong Song <yonghong.song@linux.dev>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 05/12] bpf: Support by-value struct and __int128 kfunc arguments
Date: Mon, 7 Sep 2026 21:22:06 -0700 [thread overview]
Message-ID: <5172948e-b5f8-4e17-88e5-55828795c75c@linux.dev> (raw)
In-Reply-To: <20260904061833.EF9751F00A3E@smtp.kernel.org>
On 9/3/26 11:18 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
> - [High] Incorrect buffer register resolution for memory bounds check in check_kfunc_args() due to confusion between BTF argument index and register slot index.
> - [High] bpf_kfunc_stack_access_bytes() incorrectly uses register slot indices to index BTF arguments, breaking stack liveness tracking.
> - [High] bpf_get_call_summary() incorrectly uses the number of BTF arguments instead of the number of argument slots for kfuncs, breaking register liveness tracking.
> --
>
> commit 225a338e077323b335756911c91748fab0c8ec13
> Author: Yonghong Song <yonghong.song@linux.dev>
>
> bpf: Support by-value struct and __int128 kfunc arguments
>
> A kfunc taking a struct or union by value is rejected today, and one
> taking an __int128 is accepted but mis-counted:
>
> Unrecognized R2 type STRUCT
>
> Give the kfunc argument walk the same slot count a BPF-to-BPF call now
> uses: one argument register per eightbyte, so a 16-byte value takes two.
> The outgoing stack argument count at the call site follows the slots for
> the same reason. Similar to BPF-to-BPF aggregate handling, a kfunc
> aggregate argument only supports tbe composed of scalars.
>
> Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
>
>> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
>> index 17e576c7b7572..030fb37c22ef1 100644
>> --- a/kernel/bpf/verifier.c
>> +++ b/kernel/bpf/verifier.c
> [ ... ]
>> @@ -12792,29 +12904,34 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_call_arg_me
> [ ... ]
>> /* Check that BTF function arguments match actual types that the
>> * verifier sees.
>> */
>> - for (i = 0; i < nargs; i++) {
>> - struct bpf_reg_state *reg = get_func_arg_reg(caller, regs, i);
>> + for (i = 0, slots_used = 0; i < nargs; i++, slots_used += nslots) {
>> + struct bpf_reg_state *reg = get_func_arg_reg(caller, regs, slots_used);
>> const struct btf_type *t, *ref_t, *resolve_ret;
>> enum bpf_arg_type arg_type = ARG_DONTCARE;
>> - argno_t argno = argno_from_arg(i + 1);
>> + argno_t argno = argno_from_arg(slots_used + 1);
> [Severity: High]
> This change separates the BTF argument index (i) from the register slot
> index (slots_used), but does it leave other parts of the loop using i
> incorrectly?
>
> For instance, further down in this loop, case KF_ARG_MEM_SIZE uses i - 1
> instead of slots_used - 1 to find the buffer pointer:
>
> case KF_ARG_MEM_SIZE:
> {
> struct bpf_reg_state *buff_reg = get_func_arg_reg(caller, regs, i - 1);
> struct bpf_reg_state *size_reg = reg;
>
> Could this cause a kfunc memory bounds check to validate the size argument
> against the memory bounds of the wrong pointer register if a preceding
> argument consumed multiple slots?
Yes, this is a problem. Will fix.
>
> [ ... ]
>> @@ -14308,11 +14444,11 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
>> if (bpf_is_kfunc_pkt_changing(&meta))
>> clear_all_pkt_pointers(env);
>>
>> - nargs = btf_type_vlen(meta.func_proto);
>> - if (nargs > MAX_BPF_FUNC_REG_ARGS) {
>> + proto_slots = kfunc_proto_slots(desc_btf, meta.func_proto);
>> + if (proto_slots > MAX_BPF_FUNC_REG_ARGS) {
> [Severity: High]
> This patch introduces multi-slot kfunc arguments, but were all places
> that map register slots to BTF arguments updated?
>
> For example, in bpf_kfunc_stack_access_bytes(), the register slot index
> (arg) is still directly used to index the BTF argument array:
>
> args = btf_params(meta.func_proto);
> nargs = btf_type_vlen(meta.func_proto);
> if (arg >= nargs)
> return 0;
>
> t = btf_type_skip_modifiers(btf, args[arg].type, NULL);
>
> Could this result in looking up the wrong parameter or going out of bounds
> when querying stack accesses for kfuncs with multi-slot arguments?
>
> [Severity: High]
> And similarly, does bpf_get_call_summary() also need to be updated?
>
> bool bpf_get_call_summary(...) {
> ...
> if (bpf_pseudo_kfunc_call(call)) {
> ...
> cs->num_params = btf_type_vlen(meta.func_proto);
>
> Since liveness tracking uses cs->num_params to determine the number of live
> registers, could using the BTF argument count instead of the number of
> register slots cause the verifier to treat upper registers of multi-slot
> arguments as dead?
The same here. Will fix.
next prev parent reply other threads:[~2026-09-08 4:22 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 5:09 [PATCH bpf-next 00/12] bpf: Support by-value struct and __int128 arguments Yonghong Song
2026-09-04 5:10 ` [PATCH bpf-next 01/12] selftests/bpf: Add a test for an __int128 by-value argument Yonghong Song
2026-09-04 5:10 ` [PATCH bpf-next 02/12] bpf: Index global function arguments by argument slot Yonghong Song
2026-09-04 5:10 ` [PATCH bpf-next 03/12] bpf: Support by-value struct arguments up to 16 bytes Yonghong Song
2026-09-04 5:23 ` sashiko-bot
2026-09-08 4:17 ` Yonghong Song
2026-09-04 6:09 ` bot+bpf-ci
2026-09-08 4:19 ` Yonghong Song
2026-09-04 5:10 ` [PATCH bpf-next 04/12] bpf: Support __int128 as a by-value function argument Yonghong Song
2026-09-04 5:32 ` sashiko-bot
2026-09-08 4:20 ` Yonghong Song
2026-09-04 6:09 ` bot+bpf-ci
2026-09-08 4:21 ` Yonghong Song
2026-09-04 5:10 ` [PATCH bpf-next 05/12] bpf: Support by-value struct and __int128 kfunc arguments Yonghong Song
2026-09-04 6:18 ` sashiko-bot
2026-09-08 4:22 ` Yonghong Song [this message]
2026-09-04 6:24 ` bot+bpf-ci
2026-09-08 4:23 ` Yonghong Song
2026-09-04 5:10 ` [PATCH bpf-next 06/12] bpf: Add a JIT helper for the outgoing stack of kfunc calls Yonghong Song
2026-09-04 5:25 ` sashiko-bot
2026-09-08 4:26 ` Yonghong Song
2026-09-04 5:10 ` [PATCH bpf-next 07/12] bpf, x86: Place kfunc arguments per the SysV calling convention Yonghong Song
2026-09-04 5:36 ` sashiko-bot
2026-09-08 4:27 ` Yonghong Song
2026-09-04 23:58 ` Alexei Starovoitov
2026-09-06 20:15 ` Yonghong Song
2026-09-08 4:33 ` Alexei Starovoitov
2026-09-08 5:02 ` Yonghong Song
2026-09-08 5:10 ` Yonghong Song
2026-09-08 15:24 ` Alexei Starovoitov
2026-09-08 18:43 ` Yonghong Song
2026-09-09 1:59 ` Alexei Starovoitov
2026-09-04 5:10 ` [PATCH bpf-next 08/12] bpf: Record a 16-byte argument alignment in the function model Yonghong Song
2026-09-04 6:09 ` bot+bpf-ci
2026-09-08 4:28 ` Yonghong Song
2026-09-04 5:10 ` [PATCH bpf-next 09/12] bpf, arm64: Place kfunc arguments per AAPCS64 Yonghong Song
2026-09-04 6:09 ` bot+bpf-ci
2026-09-04 5:10 ` [PATCH bpf-next 10/12] selftests/bpf: Add C tests for by-value arguments up to 16 bytes Yonghong Song
2026-09-04 5:19 ` sashiko-bot
2026-09-08 4:33 ` Yonghong Song
2026-09-04 6:09 ` bot+bpf-ci
2026-09-08 4:34 ` Yonghong Song
2026-09-04 5:10 ` [PATCH bpf-next 11/12] selftests/bpf: Add inline-asm tests for by-value arguments Yonghong Song
2026-09-04 6:09 ` bot+bpf-ci
2026-09-08 4:35 ` Yonghong Song
2026-09-04 5:11 ` [PATCH bpf-next 12/12] selftests/bpf: Add tests for by-value kfunc arguments Yonghong Song
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=5172948e-b5f8-4e17-88e5-55828795c75c@linux.dev \
--to=yonghong.song@linux.dev \
--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.