All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Hwang <leon.hwang@linux.dev>
To: bot+bpf-ci@kernel.org, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com,
	andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
	martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
	jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev,
	qmo@kernel.org, shuah@kernel.org, yatsenko@meta.com,
	avinash.duduskar@gmail.com, a.s.protopopov@gmail.com,
	ameryhung@gmail.com, jordan@jrife.io, rongtao@cestc.cn,
	eyal.birger@gmail.com, pulehui@huawei.com, tanjingguo@huawei.com,
	malin89@huawei.com, linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, martin.lau@kernel.org,
	clm@meta.com
Subject: Re: [PATCH bpf-next 10/13] selftests/bpf: Add tracing_multi bpf prog cookie test
Date: Wed, 12 Aug 2026 12:06:39 +0800	[thread overview]
Message-ID: <90e79390-569b-4ff9-8828-f7eb839cef6f@linux.dev> (raw)
In-Reply-To: <64e207da37d7fd430e941082680bc7d32ee40ef7098bc40c5bf2c9d318c37e5c@mail.kernel.org>

On 10/8/26 00:20, bot+bpf-ci@kernel.org wrote:
>> diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
>> index 5cf11707eaf89..070266a864d4f 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
>> @@ -304,9 +304,12 @@ static int run_bpf_target(struct bpf_program *prog, __u32 retval, const char *na
>>  	return 0;
>>  }
>>
>> -static void test_link_api_bpf_prog(void)
>> +static void __test_link_api_bpf_prog(bool test_cookies)
>>  {
>>  	const char *funcs[] = { "target_1", "target_2" };
>> +	__u64 fentry_cookies[] = { 0xfeed01, 0xfeed01 };
>> +	__u64 fexit_cookies[] = { 0xfeed02, 0xfeed02 };
>> +	__u64 fsession_cookies[] = { 0xfeed03, 0xfeed03 };
> 
> A subsystem pattern flags this as potentially concerning: every per-target
> cookie array holds the same value twice. The test on the BPF side compares
> against a single scalar global set from element [0]:
> 
>   skel->bss->fentry_cookie = fentry_cookies[0];
> 
> and in progs/tracing_multi_bpf.c:
> 
>   if (!test_cookies || bpf_get_attach_cookie(ctx) == fentry_cookie)
>           test_result_fentry++;
> 
> Since cookie[0] == cookie[1] for all three arrays, the test cannot
> distinguish a correct cookie-to-target mapping from a permuted one. The
> assertions (test_result_fentry == 2, etc.) succeed as long as some
> correct-looking cookie value is delivered on both invocations, but swapping
> the cookies of target_1 and target_2 in the kernel is invisible.
> 
> That matters because the kernel path this commit exercises is exactly a
> permutation: bpf_tracing_multi_attach() calls check_dup_keys() which calls
> keys_swap_r() in kernel/trace/bpf_trace.c to reorder the cookies, ids, and
> progs arrays to follow the sorted trampoline keys:
> 
>   id_a    = ids + (key_a - keys);
>   if (data->progs) { ... swap(*prog_a, *prog_b); }
>   if (cookies) { cookie_a = cookies + (id_a - ids); ... swap(*cookie_a, *cookie_b); }
> 
> An indexing mistake in that swap could desynchronise cookies from progs/ids,
> yet the test would still pass. Since fds[]/ids[] come from BPF prog FDs, the
> sort order is not the array order the caller supplied.
> 
> The neighbouring test for kernel-function targets in this same file already
> does this correctly: bpf_fentry_test_cookies[] uses ten distinct values
> deliberately out of order (8, 9, 7, 5, 4, 2, 3, 1, 10, 6) and
> progs/tracing_multi_check.c checks the cookie per-IP with something like:
> 
>   err |= test_cookies ? cookie != 8 : 0;
> 
> under `ip == &bpf_fentry_test1`.
> 
> Can the test use distinct cookies and a bpf_get_func_ip()-based per-target
> expectation so it is sensitive to cookie mis-association?
> 

Will update the cookies with different values.

>>  	LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
>>  	struct tracing_multi_bpf *skel = NULL;
>>  	int fds[ARRAY_SIZE(funcs)];
> 
> [ ... ]
> 
>> @@ -356,6 +367,16 @@ static void test_link_api_bpf_prog(void)
>>  	tracing_multi_bpf__destroy(skel);
>>  }
>>
>> +static void test_link_api_bpf_prog(void)
>> +{
>> +	__test_link_api_bpf_prog(false);
>> +}
>> +
>> +static void test_cookies_bpf_prog(void)
>> +{
>> +	__test_link_api_bpf_prog(true);
>> +}
> 
> This isn't a bug, but would calling __test_link_api_bpf_prog(false) and
> __test_link_api_bpf_prog(true) straight from the two subtest arms read more
> consistently? The neighbouring test_link_api_ids() is dispatched directly as
> test_link_api_ids(false) and test_link_api_ids(true) just a dozen lines
> down, without wrapper functions.
> 

Okay, will drop these two wrappers.

Thanks,
Leon

> [ ... ]
> 
> 
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
> 
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/31320427087


  reply	other threads:[~2026-08-12  4:07 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-09 15:00 [PATCH bpf-next 00/13] bpf: Add tracing_multi link support for bpf progs Leon Hwang
2026-08-09 15:00 ` [PATCH bpf-next 01/13] bpf: Initialize ftrace_managed in bpf_trampoline_get Leon Hwang
2026-08-09 15:01 ` [PATCH bpf-next 02/13] bpf: Factor out update_fentry_multi helper Leon Hwang
2026-08-09 15:14   ` sashiko-bot
2026-08-12  4:02     ` Leon Hwang
2026-08-09 15:01 ` [PATCH bpf-next 03/13] bpf: Drop unnecessary ftrace_location() in update_fentry_multi() Leon Hwang
2026-08-09 15:01 ` [PATCH bpf-next 04/13] bpf: Add tracing_multi link support for bpf progs Leon Hwang
2026-08-09 15:33   ` sashiko-bot
2026-08-12  4:03     ` Leon Hwang
2026-08-10 13:13   ` Jiri Olsa
2026-08-11  6:12     ` Leon Hwang
2026-08-09 15:01 ` [PATCH bpf-next 05/13] libbpf: " Leon Hwang
2026-08-09 15:21   ` sashiko-bot
2026-08-12  4:03     ` Leon Hwang
2026-08-09 15:01 ` [PATCH bpf-next 06/13] bpf: Add tracing_multi link fdinfo " Leon Hwang
2026-08-09 16:20   ` bot+bpf-ci
2026-08-12  4:04     ` Leon Hwang
2026-08-09 15:01 ` [PATCH bpf-next 07/13] bpf: Add tracing_multi link info " Leon Hwang
2026-08-09 15:17   ` sashiko-bot
2026-08-12  4:05     ` Leon Hwang
2026-08-09 15:01 ` [PATCH bpf-next 08/13] selftests/bpf: Add tracing_multi bpf prog attach test Leon Hwang
2026-08-09 15:01 ` [PATCH bpf-next 09/13] selftests/bpf: Add tracing_multi bpf prog attach failure tests Leon Hwang
2026-08-09 15:17   ` sashiko-bot
2026-08-12  4:06     ` Leon Hwang
2026-08-09 15:01 ` [PATCH bpf-next 10/13] selftests/bpf: Add tracing_multi bpf prog cookie test Leon Hwang
2026-08-09 16:20   ` bot+bpf-ci
2026-08-12  4:06     ` Leon Hwang [this message]
2026-08-09 15:01 ` [PATCH bpf-next 11/13] selftests/bpf: Add tracing_multi bpf prog rollback test Leon Hwang
2026-08-09 15:21   ` sashiko-bot
2026-08-12  4:07     ` Leon Hwang
2026-08-09 15:01 ` [PATCH bpf-next 12/13] selftests/bpf: Add tracing_multi bpf prog link info test Leon Hwang
2026-08-09 15:29   ` sashiko-bot
2026-08-12  4:08     ` Leon Hwang
2026-08-09 15:01 ` [PATCH bpf-next 13/13] selftests/bpf: Test tailcall with fentry.multi Leon Hwang

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=90e79390-569b-4ff9-8828-f7eb839cef6f@linux.dev \
    --to=leon.hwang@linux.dev \
    --cc=a.s.protopopov@gmail.com \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=avinash.duduskar@gmail.com \
    --cc=bot+bpf-ci@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=clm@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=eyal.birger@gmail.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=jordan@jrife.io \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=malin89@huawei.com \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=pulehui@huawei.com \
    --cc=qmo@kernel.org \
    --cc=rongtao@cestc.cn \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=tanjingguo@huawei.com \
    --cc=yatsenko@meta.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.