BPF List
 help / color / mirror / Atom feed
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 2/2] selftests/bpf: Add test for >8 byte return value on fexit attach
Date: Fri, 10 Jul 2026 23:29:11 +0800	[thread overview]
Message-ID: <9401462c-ea70-4541-acb0-78cf2e6c34dc@linux.dev> (raw)
In-Reply-To: <20260710144409.2580215-1-yonghong.song@linux.dev>

On 2026/7/10 22:44, Yonghong Song wrote:
> The BPF trampoline preserves only 8 bytes of the target's return value
> (R0), so attaching an fexit/fmod_ret/fsession program to a function that
> returns a >8 byte value is now rejected by the verifier.
> 
> Add a bpf_testmod function returning __int128 and an fexit program that
> targets it. The program is expected to fail to load with the
> "with a >8 byte return value is not supported for this attach type"
> message.
> 
> __int128 is only available on 64-bit targets (where the compiler defines
> __SIZEOF_INT128__). Guard the testmod function and the test with
> __SIZEOF_INT128__ so a 32-bit build still compiles; on such builds
> the subtest is simply not run.
> 
> Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
> ---
>  .../selftests/bpf/prog_tests/tracing_failure.c      | 12 ++++++++++++
>  tools/testing/selftests/bpf/progs/tracing_failure.c |  6 ++++++
>  .../testing/selftests/bpf/test_kmods/bpf_testmod.c  | 13 +++++++++++++
>  3 files changed, 31 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_failure.c b/tools/testing/selftests/bpf/prog_tests/tracing_failure.c
> index f9f9e1cb87bf..6c199f5ff4db 100644
> --- a/tools/testing/selftests/bpf/prog_tests/tracing_failure.c
> +++ b/tools/testing/selftests/bpf/prog_tests/tracing_failure.c
> @@ -76,6 +76,14 @@ static void test_fexit_noreturns(void)
>  			       "Attaching fexit/fsession/fmod_ret to __noreturn function 'do_exit' is rejected.");
>  }
>  
> +#ifdef __SIZEOF_INT128__
> +static void test_fexit_int128_ret(void)
> +{
> +	test_tracing_fail_prog("fexit_int128_ret",
> +			       "with a >8 byte return value is not supported for this attach type");
> +}


Seems that this subtest can be simplified to

static void test_fexit_int128_ret(void)
{
#ifdef __SIZEOF_INT128__
	test_tracing_fail_prog("fexit_int128_ret",
			       "with a >8 byte return value is not supported for this attach
type");
#else
	test__skip();
#endif
}

Then, no '#ifdef' below.

Thanks,
Leon

> +#endif
> +
>  void test_tracing_failure(void)
>  {
>  	if (test__start_subtest("bpf_spin_lock"))
> @@ -86,4 +94,8 @@ void test_tracing_failure(void)
>  		test_tracing_deny();
>  	if (test__start_subtest("fexit_noreturns"))
>  		test_fexit_noreturns();
> +#ifdef __SIZEOF_INT128__
> +	if (test__start_subtest("fexit_int128_ret"))
> +		test_fexit_int128_ret();
> +#endif
>  }
> diff --git a/tools/testing/selftests/bpf/progs/tracing_failure.c b/tools/testing/selftests/bpf/progs/tracing_failure.c
> index 65e485c4468c..f7a095767679 100644
> --- a/tools/testing/selftests/bpf/progs/tracing_failure.c
> +++ b/tools/testing/selftests/bpf/progs/tracing_failure.c
> @@ -30,3 +30,9 @@ int BPF_PROG(fexit_noreturns)
>  {
>  	return 0;
>  }
> +
> +SEC("?fexit/bpf_testmod_test_int128_ret")
> +int BPF_PROG(fexit_int128_ret)
> +{
> +	return 0;
> +}
> diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
> index 30f1cd23093c..902dbf658250 100644
> --- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
> +++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
> @@ -161,6 +161,15 @@ bpf_testmod_test_arg_ptr_to_struct(struct bpf_testmod_struct_arg_1 *a) {
>  	return bpf_testmod_test_struct_arg_result;
>  }
>  
> +#ifdef __SIZEOF_INT128__
> +noinline __int128
> +bpf_testmod_test_int128_ret(int a)
> +{
> +	bpf_testmod_test_struct_arg_result = a;
> +	return (__int128)a;
> +}
> +#endif
> +
>  __weak noinline void bpf_testmod_looooooooooooooooooooooooooooooong_name(void)
>  {
>  }
> @@ -514,6 +523,10 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,
>  
>  	(void)bpf_testmod_test_arg_ptr_to_struct(&struct_arg1_2);
>  
> +#ifdef __SIZEOF_INT128__
> +	(void)bpf_testmod_test_int128_ret(i);
> +#endif
> +
>  	(void)trace_bpf_testmod_test_raw_tp_null_tp(NULL);
>  
>  	bpf_testmod_test_struct_ops3();


  reply	other threads:[~2026-07-10 15:29 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 [this message]
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
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=9401462c-ea70-4541-acb0-78cf2e6c34dc@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