From: Eduard Zingerman <eddyz87@gmail.com>
To: Yonghong Song <yonghong.song@linux.dev>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
kernel-team@fb.com
Subject: Re: [PATCH bpf-next v4 07/13] bpf: Add verifier support for 16-byte returns in R0:R2
Date: Fri, 14 Aug 2026 15:08:16 -0700 [thread overview]
Message-ID: <e1bf30cac04d54aa328fee5282de348a89494048.camel@gmail.com> (raw)
In-Reply-To: <cd43d82d-0f0b-48a9-9d81-eb214d96a3ad@linux.dev>
On Thu, 2026-08-13 at 11:20 -0700, Yonghong Song wrote:
...
> > > @@ -19366,6 +19452,22 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
> > > return -EOPNOTSUPP;
> > > }
> > >
> > > + /*
> > > + * An extension replaces the target outright, so it has to match
> > > + * the target's return convention. Its own return value is capped
> > > + * at 8 bytes (a >8 byte program return is rejected at BPF_EXIT),
> > > + * so it can never fill the R0:R2 pair the target's callers read.
> > > + * This cannot be left to btf_check_type_match() above, which
> > > + * compares return types by btf_type->info only: an int carries no
> > > + * vlen, so a 16-byte __int128 and an 8-byte long compare equal.
> > > + */
> > Should the btf_check_type_match() be fixed?
>
> The function btf_check_type_match() calls btf_check_func_type_match().
> In btf_check_func_type_match(), we have
>
>
> t1 = btf_type_skip_modifiers(btf1, t1->type, NULL);
> t2 = btf_type_skip_modifiers(btf2, t2->type, NULL);
> if (t1->info != t2->info) {
> bpf_log(log,
> "Return type %s of %s() doesn't match type %s of %s()\n",
> btf_type_str(t1), fn1,
> btf_type_str(t2), fn2);
> return -EINVAL;
> }
>
> for (i = 0; i < nargs1; i++) {
> ...
> }
>
> It only checked the t1->info vs. t2->info. For example t1->info and t2->info both
> have kind INT. But t1 and t2 may have different INT type (e.g. int vs. long)
> and this is allowed in btf_check_func_type_match().
> The same thing it also allows int vs. int128.
> The same for other kinds e.g. struct (some struct has smaller size and some struct
> has larger size).
>
> So I didn't use btf_check_type_match() and rather use tgt_info->fmodel.ret_size > 8
> where reject any prog returning more than 8 bytes.
Yes, I understand the mechanics. The question is whether
btf_check_type_match() needs adjustment. This function is used by a
single caller, bpf_check_attach_target():
if (prog_extension &&
btf_check_type_match(log, prog, btf, t))
return -EINVAL;
And just a few lines below this (and v5 of the series) adds:
+ if (prog_extension && tgt_info->fmodel.ret_size > 8) {
+ bpf_log(log,
+ "Cannot replace function %s with a >8 byte return value\n",
+ tname);
+ return -EOPNOTSUPP;
+ }
Given that the sole reason for btf_check_type_match() to exist is to
answer the question if an extension BPF subprogram is compatible with
the subprogram being extended, I thing this new check has to be moved
inside btf_check_type_match(). (E.g. by deeming that integers below
8-bytes are compatible between each other, but larger integers are not).
next prev parent reply other threads:[~2026-08-14 22:08 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 0:09 [PATCH bpf-next v4 00/13] bpf: Support aggregate return values up to 16 bytes Yonghong Song
2026-08-11 0:09 ` [PATCH bpf-next v4 01/13] bpf: Factor check_global_ret_scalar_reg() out of the global return check Yonghong Song
2026-08-11 0:09 ` [PATCH bpf-next v4 02/13] bpf: Add helpers to describe the R0:R2 return register pair Yonghong Song
2026-08-11 1:24 ` bot+bpf-ci
2026-08-12 19:31 ` Yonghong Song
2026-08-12 20:07 ` Eduard Zingerman
2026-08-13 18:02 ` Yonghong Song
2026-08-11 0:09 ` [PATCH bpf-next v4 03/13] bpf: Wire up JIT support for 16-byte kfunc returns Yonghong Song
2026-08-11 1:24 ` bot+bpf-ci
2026-08-12 19:48 ` Yonghong Song
2026-08-12 20:42 ` Eduard Zingerman
2026-08-11 0:09 ` [PATCH bpf-next v4 04/13] bpf: Track R2 of register-pair returns in precision backtracking Yonghong Song
2026-08-12 21:16 ` Eduard Zingerman
2026-08-13 18:04 ` Yonghong Song
2026-08-11 0:09 ` [PATCH bpf-next v4 05/13] bpf: Account R2 of register-pair returns in live register analysis Yonghong Song
2026-08-11 1:09 ` bot+bpf-ci
2026-08-12 19:55 ` Yonghong Song
2026-08-12 21:21 ` Eduard Zingerman
2026-08-13 18:05 ` Yonghong Song
2026-08-11 0:09 ` [PATCH bpf-next v4 06/13] bpf: Reject callbacks returning more than 8 bytes Yonghong Song
2026-08-12 21:41 ` Eduard Zingerman
2026-08-13 18:09 ` Yonghong Song
2026-08-11 0:09 ` [PATCH bpf-next v4 07/13] bpf: Add verifier support for 16-byte returns in R0:R2 Yonghong Song
2026-08-11 1:24 ` bot+bpf-ci
2026-08-12 20:12 ` Yonghong Song
2026-08-12 22:12 ` Eduard Zingerman
2026-08-13 18:20 ` Yonghong Song
2026-08-14 22:08 ` Eduard Zingerman [this message]
2026-08-11 0:09 ` [PATCH bpf-next v4 08/13] bpf: Reject register-pair returns when the subprog BTF is unreliable Yonghong Song
2026-08-11 1:24 ` bot+bpf-ci
2026-08-12 20:26 ` Yonghong Song
2026-08-12 22:24 ` Eduard Zingerman
2026-08-13 18:22 ` Yonghong Song
2026-08-11 0:09 ` [PATCH bpf-next v4 09/13] bpf: Enable aggregate return types up to 16 bytes Yonghong Song
2026-08-11 1:24 ` bot+bpf-ci
2026-08-12 20:29 ` Yonghong Song
2026-08-12 22:47 ` Eduard Zingerman
2026-08-13 18:23 ` Yonghong Song
2026-08-11 0:10 ` [PATCH bpf-next v4 10/13] selftests/bpf: Add C tests for 16-byte returns in R0:R2 Yonghong Song
2026-08-11 1:24 ` bot+bpf-ci
2026-08-12 20:49 ` Yonghong Song
2026-08-12 23:15 ` Eduard Zingerman
2026-08-13 18:24 ` Yonghong Song
2026-08-11 0:10 ` [PATCH bpf-next v4 11/13] selftests/bpf: Add inline-asm and subprog tests for R0:R2 returns Yonghong Song
2026-08-11 1:24 ` bot+bpf-ci
2026-08-12 21:08 ` Yonghong Song
2026-08-12 23:29 ` Eduard Zingerman
2026-08-13 18:25 ` Yonghong Song
2026-08-13 0:09 ` Eduard Zingerman
2026-08-11 0:10 ` [PATCH bpf-next v4 12/13] selftests/bpf: Add tests for callbacks returning more than 8 bytes Yonghong Song
2026-08-11 1:24 ` bot+bpf-ci
2026-08-12 21:22 ` Yonghong Song
2026-08-13 0:10 ` Eduard Zingerman
2026-08-13 18:27 ` Yonghong Song
2026-08-11 0:10 ` [PATCH bpf-next v4 13/13] 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=e1bf30cac04d54aa328fee5282de348a89494048.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--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