public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Leon Hwang <leon.hwang@linux.dev>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Shuah Khan <shuah@kernel.org>, Feng Yang <yangfeng@kylinos.cn>,
	Toke Hoiland-Jorgensen <toke@redhat.com>,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	kernel-patches-bot@fb.com
Subject: Re: [PATCH bpf-next v2 2/2] selftests/bpf: Add test to verify the fix of kprobe_write_ctx abuse
Date: Mon, 30 Mar 2026 11:28:57 +0200	[thread overview]
Message-ID: <acpCWX6h-1IJtorN@krava> (raw)
In-Reply-To: <20260326141718.17731-3-leon.hwang@linux.dev>

On Thu, Mar 26, 2026 at 10:17:18PM +0800, Leon Hwang wrote:

SNIP

> +	prog_fd = bpf_program__fd(skel_kprobe->progs.kprobe_write_ctx);
> +	bpf_program__set_attach_target(prog_ext, prog_fd, "kprobe_write_ctx");
> +
> +	err = kprobe_write_ctx__load(skel_ext);
> +	if (!ASSERT_OK(err, "kprobe_write_ctx__load ext"))
> +		goto out;
> +
> +	prog_fd = bpf_program__fd(prog_kprobe);
> +	link_ext = bpf_program__attach_freplace(prog_ext, prog_fd, "kprobe_dummy");
> +	ASSERT_ERR_PTR(link_ext, "bpf_program__attach_freplace link");
> +	ASSERT_EQ(errno, EINVAL, "bpf_program__attach_freplace errno");

nit, I prefer libbpf_get_error call instead, because it's not obvious
that ASSERT_ERR_PTR sets errno, smth like:

        if (!ASSERT_EQ(libbpf_get_error(link_ext), -EINVAL, ..

anyway lgtm

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka


> +
> +	link_kprobe = bpf_program__attach_kprobe_opts(prog_kprobe, "bpf_fentry_test1",
> +						      &kprobe_opts);
> +	if (!ASSERT_OK_PTR(link_kprobe, "bpf_program__attach_kprobe_opts"))
> +		goto out;
> +
> +	err = bpf_prog_test_run_opts(bpf_program__fd(prog_fentry), &topts);
> +	ASSERT_OK(err, "bpf_prog_test_run_opts");
> +
> +out:
> +	bpf_link__destroy(link_ext);
> +	bpf_link__destroy(link_kprobe);
> +	kprobe_write_ctx__destroy(skel_ext);
> +	kprobe_write_ctx__destroy(skel_kprobe);
> +}
>  #else
>  static void test_attach_kprobe_write_ctx(void)
>  {
>  	test__skip();
>  }
> +
> +static void test_freplace_kprobe_write_ctx(void)
> +{
> +	test__skip();
> +}
>  #endif
>  
>  static void test_attach_probe_auto(struct test_attach_probe *skel)
> @@ -434,6 +496,8 @@ void test_attach_probe(void)
>  		test_attach_kprobe_long_event_name();
>  	if (test__start_subtest("kprobe-write-ctx"))
>  		test_attach_kprobe_write_ctx();
> +	if (test__start_subtest("freplace-kprobe-write-ctx"))
> +		test_freplace_kprobe_write_ctx();
>  
>  cleanup:
>  	test_attach_probe__destroy(skel);
> diff --git a/tools/testing/selftests/bpf/progs/kprobe_write_ctx.c b/tools/testing/selftests/bpf/progs/kprobe_write_ctx.c
> index f77aef0474d3..adbf52afe490 100644
> --- a/tools/testing/selftests/bpf/progs/kprobe_write_ctx.c
> +++ b/tools/testing/selftests/bpf/progs/kprobe_write_ctx.c
> @@ -19,4 +19,23 @@ int kprobe_multi_write_ctx(struct pt_regs *ctx)
>  	ctx->ax = 0;
>  	return 0;
>  }
> +
> +SEC("?kprobe")
> +int kprobe_dummy(struct pt_regs *regs)
> +{
> +	return 0;
> +}
> +
> +SEC("?freplace")
> +int freplace_kprobe(struct pt_regs *regs)
> +{
> +	regs->di = 0;
> +	return 0;
> +}
> +
> +SEC("?fentry/bpf_fentry_test1")
> +int BPF_PROG(fentry)
> +{
> +	return 0;
> +}
>  #endif
> -- 
> 2.53.0
> 

      reply	other threads:[~2026-03-30  9:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-26 14:17 [PATCH bpf-next v2 0/2] bpf: Fix abuse of kprobe_write_ctx via freplace Leon Hwang
2026-03-26 14:17 ` [PATCH bpf-next v2 1/2] " Leon Hwang
2026-03-27 21:39   ` Song Liu
2026-03-30  5:38     ` Leon Hwang
2026-03-30  9:28   ` Jiri Olsa
2026-03-26 14:17 ` [PATCH bpf-next v2 2/2] selftests/bpf: Add test to verify the fix of kprobe_write_ctx abuse Leon Hwang
2026-03-30  9:28   ` Jiri Olsa [this message]

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=acpCWX6h-1IJtorN@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=john.fastabend@gmail.com \
    --cc=kernel-patches-bot@fb.com \
    --cc=leon.hwang@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=toke@redhat.com \
    --cc=yangfeng@kylinos.cn \
    --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