Skip to content

Commit 9b72f3e

Browse files
kknjhanakryiko
authored andcommitted
selftests/bpf: Add test for attaching kprobe with long event names
This test verifies that attaching kprobe/kretprobe with long event names does not trigger EINVAL errors. Signed-off-by: Feng Yang <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent e1be7c4 commit 9b72f3e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tools/testing/selftests/bpf/prog_tests/attach_probe.c

+35
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,39 @@ static void test_attach_uprobe_long_event_name(void)
168168
test_attach_probe_manual__destroy(skel);
169169
}
170170

171+
/* attach kprobe/kretprobe long event name testings */
172+
static void test_attach_kprobe_long_event_name(void)
173+
{
174+
DECLARE_LIBBPF_OPTS(bpf_kprobe_opts, kprobe_opts);
175+
struct bpf_link *kprobe_link, *kretprobe_link;
176+
struct test_attach_probe_manual *skel;
177+
178+
skel = test_attach_probe_manual__open_and_load();
179+
if (!ASSERT_OK_PTR(skel, "skel_kprobe_manual_open_and_load"))
180+
return;
181+
182+
/* manual-attach kprobe/kretprobe */
183+
kprobe_opts.attach_mode = PROBE_ATTACH_MODE_LEGACY;
184+
kprobe_opts.retprobe = false;
185+
kprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kprobe,
186+
"bpf_testmod_looooooooooooooooooooooooooooooong_name",
187+
&kprobe_opts);
188+
if (!ASSERT_OK_PTR(kprobe_link, "attach_kprobe_long_event_name"))
189+
goto cleanup;
190+
skel->links.handle_kprobe = kprobe_link;
191+
192+
kprobe_opts.retprobe = true;
193+
kretprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kretprobe,
194+
"bpf_testmod_looooooooooooooooooooooooooooooong_name",
195+
&kprobe_opts);
196+
if (!ASSERT_OK_PTR(kretprobe_link, "attach_kretprobe_long_event_name"))
197+
goto cleanup;
198+
skel->links.handle_kretprobe = kretprobe_link;
199+
200+
cleanup:
201+
test_attach_probe_manual__destroy(skel);
202+
}
203+
171204
static void test_attach_probe_auto(struct test_attach_probe *skel)
172205
{
173206
struct bpf_link *uprobe_err_link;
@@ -371,6 +404,8 @@ void test_attach_probe(void)
371404

372405
if (test__start_subtest("uprobe-long_name"))
373406
test_attach_uprobe_long_event_name();
407+
if (test__start_subtest("kprobe-long_name"))
408+
test_attach_kprobe_long_event_name();
374409

375410
cleanup:
376411
test_attach_probe__destroy(skel);

tools/testing/selftests/bpf/test_kmods/bpf_testmod.c

+4
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ bpf_testmod_test_arg_ptr_to_struct(struct bpf_testmod_struct_arg_1 *a) {
134134
return bpf_testmod_test_struct_arg_result;
135135
}
136136

137+
__weak noinline void bpf_testmod_looooooooooooooooooooooooooooooong_name(void)
138+
{
139+
}
140+
137141
__bpf_kfunc void
138142
bpf_testmod_test_mod_kfunc(int i)
139143
{

0 commit comments

Comments
 (0)