From: Leon Hwang <leon.hwang@linux.dev>
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>,
Eduard Zingerman <eddyz87@gmail.com>,
kernel-team@fb.com
Subject: Re: [PATCH bpf 1/2] bpf: Reject >8 byte return values on return-reading trampoline paths
Date: Sat, 11 Jul 2026 00:37:23 +0800 [thread overview]
Message-ID: <67bf1951-96be-4ccf-adc4-012c7e7f0055@linux.dev> (raw)
In-Reply-To: <20260710144404.2579671-1-yonghong.song@linux.dev>
On 2026/7/10 22:44, Yonghong Song wrote:
[...]
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 6515d4d3c003..26d281b77a6e 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -18873,6 +18873,20 @@ static int btf_id_allow_sleepable(u32 btf_id, unsigned long addr, const struct b
> return -EINVAL;
> }
>
> +static bool attach_uses_trampoline_retval(enum bpf_attach_type type)
> +{
> + switch (type) {
> + case BPF_MODIFY_RETURN:
> + case BPF_TRACE_FEXIT:
> + case BPF_TRACE_FEXIT_MULTI:
> + case BPF_TRACE_FSESSION:
> + case BPF_TRACE_FSESSION_MULTI:
> + return true;
> + default:
> + return false;
> + }
> +}
> +
> int bpf_check_attach_target(struct bpf_verifier_log *log,
> const struct bpf_prog *prog,
> const struct bpf_prog *tgt_prog,
> @@ -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)) {
> + bpf_log(log,
> + "Attach to function %s with a >8 byte return value is not supported for this attach type\n",
> + tname);
> + return -EOPNOTSUPP;
> + }
> +
> /*
> * *.multi programs don't need an address during program
> * verification, we just take the module ref if needed.
> @@ -19413,6 +19435,9 @@ int bpf_check_attach_btf_id_multi(struct btf *btf, struct bpf_prog *prog, u32 bt
> err = btf_distill_func_proto(NULL, btf, t, tname, &tgt_info->fmodel);
> if (err < 0)
> return err;
> + if (tgt_info->fmodel.ret_size > 8 &&
> + attach_uses_trampoline_retval(prog->expected_attach_type))
> + return -EOPNOTSUPP;
> if (btf_is_module(btf)) {
> /* The bpf program already holds reference to module. */
> if (WARN_ON_ONCE(!prog->aux->mod))
I think there's no need to introduce the helper
attach_uses_trampoline_retval().
See this untested diff:
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 03e2202cca13..899d5b129b54 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -19023,6 +19023,7 @@ int bpf_check_attach_target(struct
bpf_verifier_log *log,
const char prefix[] = "btf_trace_";
struct bpf_raw_event_map *btp;
int ret = 0, subprog = -1, i;
+ bool attach_retval = false;
const struct btf_type *t;
bool conservative = true;
const char *tname, *fname;
@@ -19232,19 +19233,21 @@ int bpf_check_attach_target(struct
bpf_verifier_log *log,
if (ret)
return ret;
break;
+ case BPF_MODIFY_RETURN:
+ case BPF_TRACE_FEXIT:
+ case BPF_TRACE_FEXIT_MULTI:
+ case BPF_TRACE_FSESSION:
+ case BPF_TRACE_FSESSION_MULTI:
+ attach_retval = true;
+ fallthrough;
default:
- if (!prog_extension)
+ if (!prog_extension && !attach_retval)
return -EINVAL;
fallthrough;
- case BPF_MODIFY_RETURN:
case BPF_LSM_MAC:
case BPF_LSM_CGROUP:
case BPF_TRACE_FENTRY:
- case BPF_TRACE_FEXIT:
- case BPF_TRACE_FSESSION:
- case BPF_TRACE_FSESSION_MULTI:
case BPF_TRACE_FENTRY_MULTI:
- case BPF_TRACE_FEXIT_MULTI:
if ((prog->expected_attach_type == BPF_TRACE_FSESSION ||
prog->expected_attach_type == BPF_TRACE_FSESSION_MULTI) &&
!bpf_jit_supports_fsession()) {
@@ -19275,6 +19278,13 @@ int bpf_check_attach_target(struct
bpf_verifier_log *log,
if (ret < 0)
return ret;
+ if (tgt_info->fmodel.ret_size > 8 && attach_retval) {
+ bpf_log(log,
+ "Attach to function %s with a >8 byte return value is not supported
for this attach type\n",
+ tname);
+ return -EOPNOTSUPP;
+ }
+
/*
* *.multi programs don't need an address during program
* verification, we just take the module ref if needed.
@@ -19551,6 +19561,13 @@ int bpf_check_attach_btf_id_multi(struct btf
*btf, struct bpf_prog *prog, u32 bt
err = btf_distill_func_proto(NULL, btf, t, tname, &tgt_info->fmodel);
if (err < 0)
return err;
+ switch (prog->expected_attach_type) {
+ case BPF_TRACE_FEXIT_MULTI:
+ case BPF_TRACE_FSESSION_MULTI:
+ if (tgt_info->fmodel.ret_size > 8)
+ return -EOPNOTSUPP;
+ break;
+ }
if (btf_is_module(btf)) {
/* The bpf program already holds reference to module. */
if (WARN_ON_ONCE(!prog->aux->mod))
WDYT?
Thanks,
Leon
next prev parent reply other threads:[~2026-07-10 16:37 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 ` [PATCH bpf 1/2] bpf: Reject >8 byte return values on return-reading trampoline paths sashiko-bot
2026-07-10 15:45 ` Yonghong Song
2026-07-10 15:45 ` bot+bpf-ci
2026-07-10 15:47 ` Yonghong Song
2026-07-10 16:37 ` Leon Hwang [this message]
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=67bf1951-96be-4ccf-adc4-012c7e7f0055@linux.dev \
--to=leon.hwang@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--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