From: Yonghong Song <yonghong.song@linux.dev>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 06/12] bpf: Add a JIT helper for the outgoing stack of kfunc calls
Date: Mon, 7 Sep 2026 21:26:43 -0700 [thread overview]
Message-ID: <2a145c4d-f665-402c-9929-9b2a0fefdad2@linux.dev> (raw)
In-Reply-To: <20260904052505.DF05D1F00AC4@smtp.kernel.org>
On 9/3/26 10:25 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] An out-of-bounds write occurs in `btf_prepare_func_args` when processing a BPF subprogram with arguments that consume 11 slots followed by a final 16-byte struct argument.
> --
>
> commit d1c6556d5925344f81e73a6b534000285b7cee65
> Author: Yonghong Song <yonghong.song@linux.dev>
>
> bpf: Support by-value struct arguments up to 16 bytes
>
> This commit adds support for global functions taking a struct or union by
> value up to 16 bytes. It handles structs passed in consecutive registers
> or split across registers and the stack, computing the necessary argument
> slots. The stack argument count is then recomputed based on the slots
> consumed to ensure proper JIT support checks.
>
>> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
>> index 22828b489b778..dbd64cee1b27a 100644
>> --- a/kernel/bpf/btf.c
>> +++ b/kernel/bpf/btf.c
>> @@ -8103,6 +8103,14 @@ int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog)
>> for (i = 0, slots_used = 0; i < nargs; i++) {
>> u32 tags = 0;
>>
>> + if (slots_used >= MAX_BPF_FUNC_ARGS) {
>> + if (!is_global)
>> + return -EINVAL;
>> + bpf_log(log, "Arguments of %s() need more than %d argument slots\n",
>> + tname, MAX_BPF_FUNC_ARGS);
>> + return -EINVAL;
>> + }
>> +
>> err = btf_scan_decl_tags(env, btf, fn_t, i, is_global, &tags);
>> if (err)
>> return err;
> [ ... ]
>
>> @@ -8231,6 +8239,31 @@ int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog)
>> sub->args[slots_used++].arg_type = ARG_ANYTHING;
>> continue;
>> }
>> + if (btf_type_is_struct(t)) {
>> + u32 nslots;
>> +
>> + if (!t->size || t->size > 2 * BPF_REG_SIZE) {
>> + if (!is_global)
>> + return -EINVAL;
>> + bpf_log(log,
>> + "Arg#%d type %s in %s() has size %u, only 1 to %d bytes "
>> + "can be passed by value\n",
>> + i, btf_type_str(t), tname, t->size, 2 * BPF_REG_SIZE);
>> + return -EINVAL;
>> + }
>> + if (!btf_struct_is_composed_of(env, btf, t, BTF_MEMBER_SCALAR)) {
>> + if (!is_global)
>> + return -EINVAL;
>> + bpf_log(log, "Arg#%d type %s in %s() is not composed of scalars\n",
>> + i, btf_type_str(t), tname);
>> + return -EINVAL;
>> + }
>> +
>> + nslots = (t->size + BPF_REG_SIZE - 1) / BPF_REG_SIZE;
>> + while (nslots--)
>> + sub->args[slots_used++].arg_type = ARG_ANYTHING;
> [Severity: High]
> Does this loop write beyond the end of the sub->args[] array?
>
> If a non-global BPF subprogram has arguments consuming exactly 11 slots,
> slots_used >= MAX_BPF_FUNC_ARGS evaluates to false (11 >= 12) at the start
> of the loop, allowing it to proceed.
>
> When a final 16-byte struct argument follows, nslots is set to 2. This
> while loop then writes to sub->args[11] and subsequently out-of-bounds to
> sub->args[12].
>
> Could this memory corruption overwrite the adjacent stack_arg_cnt and
> max_out_stack_arg_cnt fields in struct bpf_subprog_info?
The same issue similar to "bpf: Support by-value struct arguments up to 16 bytes"
and "bpf: Support __int128 as a by-value function argument". Will fix.
>
> On big-endian architectures, this might artificially inflate
> max_out_stack_arg_cnt to 9 (the value of ARG_ANYTHING), causing the
> verifier to subsequently reject valid BPF programs in
> check_outgoing_stack_args(). On little-endian architectures it would
> silently zero the field.
>
>> + continue;
>> + }
>> if (!is_global)
>> return -EINVAL;
next prev parent reply other threads:[~2026-09-08 4:26 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
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 [this message]
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=2a145c4d-f665-402c-9929-9b2a0fefdad2@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox