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 v3 11/15] bpf, arm64: Move kfunc arguments into the arm64 calling convention
Date: Fri, 11 Sep 2026 16:19:32 +0000	[thread overview]
Message-ID: <20260911161933.01B9B1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260911155010.2011265-1-yonghong.song@linux.dev>

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

Pre-existing issues:
- [High] The ARM64 BPF trampoline incorrectly saves and restores 16-byte aligned arguments, violating AAPCS64 alignment rules.
--

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

bpf, arm64: Move kfunc arguments into the arm64 calling convention

Do the proper move from the BPF calling convention to the arm64 calling
convention to satisfy the native requirement. AAPCS64 only ever moves an
argument to a higher slot, so the moves need one scratch register to carry
an eightbyte from one stack slot to another, and never the one a
convention moving an argument down would need.

> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
> index 3aa3ea0bc30bb..bbde7c0836ae5 100644
> --- a/arch/arm64/net/bpf_jit_comp.c
> +++ b/arch/arm64/net/bpf_jit_comp.c

[ ... ]

> @@ -2534,7 +2598,13 @@ struct arg_aux {
>  static int calc_arg_aux(const struct btf_func_model *m,
>  			 struct arg_aux *a)
>  {
> -	int stack_slots, nregs, slots, i;
> +	int stack_slots, nregs, slots, i, total;
> +
> +	/* arm64 supports up to MAX_BPF_FUNC_ARGS argument slots */
> +	for (i = 0, total = 0; i < m->nr_args; i++)
> +		total += (m->arg_size[i] + 7) / 8;
> +	if (total > MAX_BPF_FUNC_ARGS)
> +		return -ENOTSUPP;
>  
>  	/* verifier ensures m->nr_args <= MAX_BPF_FUNC_ARGS */
>  	for (i = 0, nregs = 0; i < m->nr_args; i++) {

[Severity: High]
This isn't a bug introduced by this patch, but since the series introduces
support for by-value 16-byte arguments, this previously dormant ABI violation
in the BPF trampoline appears to now be actively reachable.

Does calc_arg_aux() fail to account for skipped registers due to alignment
requirements?

If a user attaches a BPF program to a kernel function (or struct_ops
callback) that takes a 16-byte aligned argument (e.g., __int128 or
by-value struct) preceded by an odd number of register-sized arguments,
the native AAPCS64 caller places the 16-byte argument in an even/odd
register pair (like x2 and x3, skipping x1).

However, the nregs calculation here simply increments by slots without
checking for skipped odd registers:

arch/arm64/net/bpf_jit_comp.c:calc_arg_aux() {
    ...
    for (i = 0, nregs = 0; i < m->nr_args; i++) {
        slots = (m->arg_size[i] + 7) / 8;
        if (nregs + slots <= 8) /* passed through register ? */
            nregs += slots;
    ...
}

This strictly sequential register handling seems to propagate to both
save_args() and restore_args() in the trampoline, where arguments are
read and written sequentially without skipping odd registers:

arch/arm64/net/bpf_jit_comp.c:save_args() {
    ...
    slots = (m->arg_size[i] + 7) / 8;
    while (slots-- > 0) {
        ...
        emit(A64_STR64I(reg, A64_SP, bargs_off), ctx);
        reg++;
        bargs_off += 8;
    }
    ...
}

arch/arm64/net/bpf_jit_comp.c:restore_args() {
    ...
    for (reg = 0; reg < nregs; reg++) {
        emit(A64_LDR64I(reg, A64_SP, bargs_off), ctx);
        bargs_off += 8;
    }
    ...
}

Could this cause data corruption for arguments passed to BPF programs
attached via fentry, fexit, or struct_ops when 16-byte arguments are
involved?

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

  reply	other threads:[~2026-09-11 16:19 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11 15:49 [PATCH bpf-next v3 00/15] bpf: Support by-value struct and __int128 arguments Yonghong Song
2026-09-11 15:49 ` [PATCH bpf-next v3 01/15] bpf: Read a kfunc's __sz argument only when it is in a register Yonghong Song
2026-09-11 15:49 ` [PATCH bpf-next v3 02/15] selftests/bpf: Add a test for an __int128 by-value argument Yonghong Song
2026-09-11 16:47   ` bot+bpf-ci
2026-09-12 17:07     ` Yonghong Song
2026-09-11 15:49 ` [PATCH bpf-next v3 03/15] bpf: Rename bpf_subprog_info::arg_cnt to arg_slot_cnt Yonghong Song
2026-09-11 15:49 ` [PATCH bpf-next v3 04/15] bpf: Index global function arguments by argument slot Yonghong Song
2026-09-11 15:49 ` [PATCH bpf-next v3 05/15] bpf: Support by-value struct arguments up to 16 bytes Yonghong Song
2026-09-11 15:49 ` [PATCH bpf-next v3 06/15] bpf: Support __int128 as a by-value function argument Yonghong Song
2026-09-11 15:49 ` [PATCH bpf-next v3 07/15] bpf: Rename bpf_call_summary::num_params to arg_slot_cnt Yonghong Song
2026-09-11 15:49 ` [PATCH bpf-next v3 08/15] bpf: Recognize by-value struct and __int128 kfunc arguments Yonghong Song
2026-09-11 16:47   ` bot+bpf-ci
2026-09-12 17:13     ` Yonghong Song
2026-09-11 15:50 ` [PATCH bpf-next v3 09/15] bpf: Prepare kfunc arguments for the JIT from an ABI description Yonghong Song
2026-09-11 15:50 ` [PATCH bpf-next v3 10/15] bpf, x86: Move kfunc arguments into the x86-64 calling convention Yonghong Song
2026-09-11 16:47   ` bot+bpf-ci
2026-09-12 17:14     ` Yonghong Song
2026-09-11 15:50 ` [PATCH bpf-next v3 11/15] bpf, arm64: Move kfunc arguments into the arm64 " Yonghong Song
2026-09-11 16:19   ` sashiko-bot [this message]
2026-09-12 17:16     ` Yonghong Song
2026-09-11 16:47   ` bot+bpf-ci
2026-09-12 17:19     ` Yonghong Song
2026-09-11 15:50 ` [PATCH bpf-next v3 12/15] selftests/bpf: Add C tests for by-value arguments up to 16 bytes Yonghong Song
2026-09-11 15:50 ` [PATCH bpf-next v3 13/15] selftests/bpf: Add inline-asm tests for by-value arguments Yonghong Song
2026-09-11 16:06   ` sashiko-bot
2026-09-11 15:50 ` [PATCH bpf-next v3 14/15] selftests/bpf: Add tests for by-value kfunc arguments Yonghong Song
2026-09-11 16:47   ` bot+bpf-ci
2026-09-12 17:24     ` Yonghong Song
2026-09-11 15:50 ` [PATCH bpf-next v3 15/15] selftests/bpf: Temporary hack to disable register mismatch in arm64 Yonghong Song
2026-09-11 16:47   ` bot+bpf-ci
2026-09-12  3:57   ` Alexei Starovoitov
2026-09-12 17:30     ` 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=20260911161933.01B9B1F000FF@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