From: sashiko-bot@kernel.org
To: "Yonghong Song" <yonghong.song@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v7 07/10] bpf: Enable aggregate return types up to 16 bytes
Date: Wed, 19 Aug 2026 06:13:23 +0000 [thread overview]
Message-ID: <20260819061323.66C1A1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260819055314.3298664-1-yonghong.song@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] BPF extension programs (BPF_PROG_TYPE_EXT) bypass return value verification for BPF_REG_2 when replacing a function that returns a 16-byte struct, allowing uninitialized memory or kernel pointers to leak.
--
--- Patch [7]: [PATCH bpf-next v7 07/10] bpf: Enable aggregate return types up to 16 bytes ---
commit 19d85b11c1fe37fb0f420056e54cf29ffa04a0bb
Author: Yonghong Song <yonghong.song@linux.dev>
bpf: Enable aggregate return types up to 16 bytes
Relax btf_distill_func_proto() to accept a by-value struct or union that
the R0:R2 convention added in earlier patches can carry.
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 5e9f6a4875244..58b81c6f5288c 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
[ ... ]
> @@ -7993,6 +7993,19 @@ static int btf_validate_return_type(struct bpf_verifier_env *env, struct btf *bt
> if (btf_type_is_void(t) || btf_type_is_int(t) || btf_is_any_enum(t))
> return 0;
>
> + if (btf_type_is_struct(t) && t->size <= 16) {
> + /*
> + * A global function's caller models the return as an opaque
> + * scalar pair, so it may only return scalars by value. A local
> + * function is verified inline, so a pointer field stays tracked
> + * and needs no such restriction.
> + */
> + bool local_func = subprog && !is_global;
> +
> + if (local_func || btf_type_is_scalar_struct(env, btf, t, 0))
> + return 0;
> + }
> +
> return -EOPNOTSUPP;
> }
[Severity: High]
Does this allow BPF_PROG_TYPE_EXT extension programs to bypass return value
verification for BPF_REG_2?
Since this patch enables global functions to return structs up to 16 bytes, a
BPF_PROG_TYPE_EXT program can now replace such a function. This is allowed by
bpf_check_attach_target() because attach_uses_trampoline_retval() is false for
extension programs.
However, during verification of the extension program,
bpf_compute_subprog_ret_regs() explicitly skips subprog 0 (the extension
program itself), which leaves ret_reg_pair as false:
kernel/bpf/verifier.c:bpf_compute_subprog_ret_regs() {
/*
* Skip the main program: its return value is the program's exit code,
* read out of R0, so it never uses the register pair. An extension does
* have a real prototype for subprog 0, but bpf_check_attach_target()
* refuses to replace a function returning more than 8 bytes.
*/
for (subprog = 1; subprog < env->subprog_cnt; subprog++) {
...
}
Because ret_reg_pair is false, process_bpf_exit_full() later invokes
check_return_code(..., BPF_REG_0) for subprog 0 instead of checking the full
register pair. Could this fail to validate R2 on exit, potentially allowing an
uninitialized or sensitive kernel pointer to leak to the caller?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260819055239.3293449-1-yonghong.song@linux.dev?part=7
next prev parent reply other threads:[~2026-08-19 6:13 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 5:52 [PATCH bpf-next v7 00/10] bpf: Support aggregate return values up to 16 bytes Yonghong Song
2026-08-19 5:52 ` [PATCH bpf-next v7 01/10] bpf: Factor check_global_ret_scalar_reg() out of the global return check Yonghong Song
2026-08-19 5:52 ` [PATCH bpf-next v7 02/10] bpf: Add helpers to describe the R0:R2 return register pair Yonghong Song
2026-08-19 6:17 ` sashiko-bot
2026-08-19 5:52 ` [PATCH bpf-next v7 03/10] bpf: Wire up JIT support for 16-byte kfunc returns Yonghong Song
2026-08-19 6:49 ` bot+bpf-ci
2026-08-19 5:52 ` [PATCH bpf-next v7 04/10] bpf: Handle R2 as a return register in precision backtracking Yonghong Song
2026-08-19 6:03 ` sashiko-bot
2026-08-19 5:53 ` [PATCH bpf-next v7 05/10] bpf: Account R2 of register-pair returns in live register analysis Yonghong Song
2026-08-19 6:20 ` sashiko-bot
2026-08-19 6:32 ` bot+bpf-ci
2026-08-19 5:53 ` [PATCH bpf-next v7 06/10] bpf: Add verifier support for 16-byte returns in R0:R2 Yonghong Song
2026-08-19 6:14 ` sashiko-bot
2026-08-19 5:53 ` [PATCH bpf-next v7 07/10] bpf: Enable aggregate return types up to 16 bytes Yonghong Song
2026-08-19 6:13 ` sashiko-bot [this message]
2026-08-19 6:50 ` bot+bpf-ci
2026-08-19 5:53 ` [PATCH bpf-next v7 08/10] selftests/bpf: Add C tests for 16-byte returns in R0:R2 Yonghong Song
2026-08-19 6:49 ` bot+bpf-ci
2026-08-19 5:53 ` [PATCH bpf-next v7 09/10] selftests/bpf: Add inline-asm and subprog tests for R0:R2 returns Yonghong Song
2026-08-19 5:53 ` [PATCH bpf-next v7 10/10] Documentation/bpf: Document up to 16-byte kfunc return values in R0:R2 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=20260819061323.66C1A1F000E9@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