From: Yonghong Song <yonghong.song@linux.dev>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 07/12] bpf, x86: Place kfunc arguments per the SysV calling convention
Date: Mon, 7 Sep 2026 21:27:34 -0700 [thread overview]
Message-ID: <cd3251c3-b2f9-4254-8e33-42b80b4a9f49@linux.dev> (raw)
In-Reply-To: <20260904053658.335DE1F00A3F@smtp.kernel.org>
On 9/3/26 10:36 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] emit_kfunc_args() and bpf_jit_kfunc_stack_slots() silently ignore kfunc_arg_layout() errors for kfuncs requiring more than 12 argument eightbytes, leading to miscompiled BPF programs with incorrect argument placements.
> --
>
> commit f5201014b232baff8f1ba36c0b74d2c3e1e5ccf9
> Author: Yonghong Song <yonghong.song@linux.dev>
>
> bpf, x86: Place kfunc arguments per the SysV calling convention
>
> This commit updates the BPF JIT on x86 to conform to the SysV calling
> convention when placing kfunc arguments. It adjusts argument placements
> before a kfunc call to account for differing rules between BPF and SysV
> regarding stack and register usage. The outgoing argument area is sized
> to support both conventions.
>
>> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
>> --- a/arch/x86/net/bpf_jit_comp.c
>> +++ b/arch/x86/net/bpf_jit_comp.c
> [ ... ]
>> +static int emit_kfunc_args(const struct btf_func_model *fm, u8 **pprog,
>> + s32 stack_base)
>> +{
>> + u8 *prog = *pprog, *start = prog;
>> + bool done[MAX_BPF_FUNC_ARGS] = {};
>> + u8 pos[MAX_BPF_FUNC_ARGS];
>> + int i, j, n, todo = 0, parked = -1;
>> +
>> + n = kfunc_arg_layout(fm, pos, ARRAY_SIZE(pos));
>> + if (n < 0)
>> + return 0;
> [Severity: Medium]
> Will this silently ignore errors if a kfunc requires more than 12 argument
> eightbytes?
>
> While the verifier limits the argument count to 12 (MAX_BPF_FUNC_ARGS),
> arguments can take up to 2 slots, so the total slots could reach 24.
> If a BPF program calls a registered kfunc that requires more than 12
> eightbyte slots (such as 7 struct arguments of 16 bytes each),
> kfunc_arg_layout() will return -EINVAL because max is hardcoded to 12 here.
>
> Since emit_kfunc_args() returns 0 instead of propagating the error code,
> could this cause the BPF program to compile successfully but execute with
> missing argument shuffle instructions? It seems the kfunc might read garbage
> from the 6th slot onwards, potentially causing panics or data corruption.
>
> This same pattern of silently ignoring layout errors appears in
> bpf_jit_kfunc_stack_slots():
>
> kernel/bpf/core.c:bpf_jit_kfunc_stack_slots() {
> ...
> n = layout(fm, pos, ARRAY_SIZE(pos));
> if (n < 0)
> continue;
> ...
> }
>
> Does this also leave stack calculations undersized?
>
> Though the stack corruption is mathematically averted because BPF's calling
> convention stack requirements always equal or exceed SysV's (making
> outgoing_rsp naturally sufficient), the silent argument corruption remains.
> As there are currently no mainline kfuncs that take more than 12 slots,
> this appears to be a latent regression.
This patch will be removed. I will simplify the jit.
next prev parent reply other threads:[~2026-09-08 4:27 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
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 [this message]
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=cd3251c3-b2f9-4254-8e33-42b80b4a9f49@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.