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 1/2] bpf: Reject >8 byte return values on return-reading trampoline paths
Date: Fri, 10 Jul 2026 14:58:45 +0000	[thread overview]
Message-ID: <20260710145845.883411F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260710144404.2579671-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 x86 BPF trampoline generation under-allocates stack space for 16-byte scalar arguments (e.g., __int128), leading to an out-of-bounds stack write that overwrites the saved RBP and return address.
--

--- Patch [1]: [PATCH bpf 1/2] bpf: Reject >8 byte return values on return-reading trampoline paths ---
commit 8947b8106804bc7e7328c045366441fc0d165459
Author: Yonghong Song <yonghong.song@linux.dev>

bpf: Reject >8 byte return values on return-reading trampoline paths

This patch rejects BPF trampoline attachments for types like fexit, fmod_ret,
and struct_ops if the target function has a return value larger than 8 bytes.
Previously, the trampoline accepted 16-byte return values (e.g., __int128) but
only saved and restored 8 bytes, which corrupted the return value seen by the
caller.

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 6515d4d3c0032..26d281b77a6e7 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c

[ ... ]

> @@ -19137,6 +19151,14 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
>  		if (ret < 0)
>  			return ret;
>  
> +		if (tgt_info->fmodel.ret_size > 8 &&
> +		    attach_uses_trampoline_retval(prog->expected_attach_type)) {
[Severity: High]
This is a pre-existing issue, but while this patch addresses >8 byte return
values, does the BPF trampoline also have a similar problem with >8 byte
arguments?

In kernel/bpf/btf.c:btf_distill_func_proto(), 16-byte arguments like __int128
are accepted, but __get_type_fmodel_flags() does not set BTF_FMODEL_STRUCT_ARG
for them because they are BTF_KIND_INT, not structs.

In arch/x86/net/bpf_jit_comp.c:__arch_prepare_bpf_trampoline(), the stack
size calculation relies on this flag:

		if (m->arg_flags[i] & BTF_FMODEL_STRUCT_ARG)
			nr_regs += (m->arg_size[i] + 7) / 8 - 1;

Because the flag isn't set for __int128, it is incorrectly counted as
1 register, under-allocating the stack space by 8 bytes per 16-byte
scalar argument.

Later during code generation, save_args() computes
arg_regs = (m->arg_size[i] + 7) / 8, which evaluates to 2. It performs
two 8-byte stack stores, which will underflow the allocated boundary and
overwrite the saved RBP and potentially the return address.

Could this lead to out-of-bounds stack writes for fentry/fexit programs
attached to functions with 16-byte scalar arguments?

> +			bpf_log(log,
> +				"Attach to function %s with a >8 byte return value is not supported for this attach type\n",
> +				tname);
> +			return -EOPNOTSUPP;
> +		}

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

  parent reply	other threads:[~2026-07-10 14:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10 14:44 [PATCH bpf 1/2] bpf: Reject >8 byte return values on return-reading trampoline paths Yonghong Song
2026-07-10 14:44 ` [PATCH bpf 2/2] selftests/bpf: Add test for >8 byte return value on fexit attach Yonghong Song
2026-07-10 15:29   ` Leon Hwang
2026-07-10 15:43     ` Yonghong Song
2026-07-10 14:58 ` sashiko-bot [this message]
2026-07-10 15:45   ` [PATCH bpf 1/2] bpf: Reject >8 byte return values on return-reading trampoline paths Yonghong Song
2026-07-10 15:45 ` bot+bpf-ci
2026-07-10 15:47   ` Yonghong Song
2026-07-10 16:37 ` Leon Hwang
2026-07-10 17:45   ` 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=20260710145845.883411F000E9@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