BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yonghong Song" <yonghong.song@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 04/12] bpf: Support __int128 as a by-value function argument
Date: Fri, 04 Sep 2026 05:32:40 +0000	[thread overview]
Message-ID: <20260904053241.532E61F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260904051018.3978585-1-yonghong.song@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Out-of-bounds array write in `btf_prepare_func_args()` when an argument takes multiple register slots (like a 16-byte struct or `__int128`) and pushes `slots_used` past `MAX_BPF_FUNC_ARGS`.
--

commit 6ab0b55d70f74022fd34563ec7b71f1a649ea690
Author: Yonghong Song <yonghong.song@linux.dev>

bpf: Support __int128 as a by-value function argument

This commit adds support for 128-bit integers as by-value function arguments
in BPF. It handles __int128 similarly to a 16-byte struct, consuming two
consecutive argument registers.

> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -8251,7 +8247,8 @@ int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog)
>  					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 (btf_type_is_struct(t) &&
> +			    !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",

[Severity: High]
This is a pre-existing issue, but this patch enables __int128 arguments which
trigger the same vulnerable path as 16-byte structs.

Can this loop overflow the sub->args array when an argument takes multiple
slots?

Looking at btf_prepare_func_args() just below this hunk:

			nslots = (t->size + BPF_REG_SIZE - 1) / BPF_REG_SIZE;
			while (nslots--)
				sub->args[slots_used++].arg_type = ARG_ANYTHING;

If a BPF program defines a subprogram with exactly 12 arguments, where the
last argument is a 16-byte struct or __int128, slots_used would be 11 when
processing the final argument.

The 16-byte argument yields nslots = 2. The loop then increments slots_used
twice without checking bounds mid-loop. Because sub->args is sized
MAX_BPF_FUNC_ARGS (12), this writes to sub->args[11] and then out of bounds
to sub->args[12].

Since sub->args sits at the end of struct bpf_subprog_info, immediately
followed by stack_arg_cnt, this out-of-bounds write corrupts stack_arg_cnt.

Later, sub->stack_arg_cnt is set to slots_used - MAX_BPF_FUNC_REG_ARGS,
which rewrites the corrupted enum value. Depending on endianness, this can
result in an invalid enum value triggering a verifier_bug(), or an incorrect
type expectation (like ARG_PTR_TO_CTX instead of a scalar).

Could we add a bounds check inside or before the nslots loop to prevent
slots_used from exceeding MAX_BPF_FUNC_ARGS?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260904050957.3976119-1-yonghong.song@linux.dev?part=4

  reply	other threads:[~2026-09-04  5:32 UTC|newest]

Thread overview: 27+ 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-04  6:09   ` bot+bpf-ci
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 [this message]
2026-09-04  6:09   ` bot+bpf-ci
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-04  6:24   ` bot+bpf-ci
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-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-04 23:58   ` 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-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-04  6:09   ` bot+bpf-ci
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-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=20260904053241.532E61F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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