Skip to content

Commit 0d83786

Browse files
Hou Taoborkmann
Hou Tao
authored andcommitted
selftests/bpf: Add test for abnormal cnt during multi-uprobe attachment
If an abnormally huge cnt is used for multi-uprobes attachment, the following warning will be reported: ------------[ cut here ]------------ WARNING: CPU: 7 PID: 406 at mm/util.c:632 kvmalloc_node+0xd9/0xe0 Modules linked in: bpf_testmod(O) CPU: 7 PID: 406 Comm: test_progs Tainted: G ...... 6.7.0-rc3+ #32 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) ...... RIP: 0010:kvmalloc_node+0xd9/0xe0 ...... Call Trace: <TASK> ? __warn+0x89/0x150 ? kvmalloc_node+0xd9/0xe0 bpf_uprobe_multi_link_attach+0x14a/0x480 __sys_bpf+0x14a9/0x2bc0 do_syscall_64+0x36/0xb0 entry_SYSCALL_64_after_hwframe+0x6e/0x76 ...... </TASK> ---[ end trace 0000000000000000 ]--- So add a test to ensure the warning is fixed. Signed-off-by: Hou Tao <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Jiri Olsa <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent d6d1e6c commit 0d83786

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,34 @@ static void test_attach_api_syms(void)
234234
test_attach_api("/proc/self/exe", NULL, &opts);
235235
}
236236

237+
static void test_attach_api_fails(void)
238+
{
239+
LIBBPF_OPTS(bpf_link_create_opts, opts);
240+
const char *path = "/proc/self/exe";
241+
struct uprobe_multi *skel = NULL;
242+
unsigned long offset = 0;
243+
int link_fd = -1;
244+
245+
skel = uprobe_multi__open_and_load();
246+
if (!ASSERT_OK_PTR(skel, "uprobe_multi__open_and_load"))
247+
goto cleanup;
248+
249+
/* abnormal cnt */
250+
opts.uprobe_multi.path = path;
251+
opts.uprobe_multi.offsets = &offset;
252+
opts.uprobe_multi.cnt = INT_MAX;
253+
link_fd = bpf_link_create(bpf_program__fd(skel->progs.uprobe), 0,
254+
BPF_TRACE_UPROBE_MULTI, &opts);
255+
if (!ASSERT_ERR(link_fd, "link_fd"))
256+
goto cleanup;
257+
if (!ASSERT_EQ(link_fd, -E2BIG, "big cnt"))
258+
goto cleanup;
259+
cleanup:
260+
if (link_fd >= 0)
261+
close(link_fd);
262+
uprobe_multi__destroy(skel);
263+
}
264+
237265
static void __test_link_api(struct child *child)
238266
{
239267
int prog_fd, link1_fd = -1, link2_fd = -1, link3_fd = -1, link4_fd = -1;
@@ -311,7 +339,7 @@ static void __test_link_api(struct child *child)
311339
free(offsets);
312340
}
313341

314-
void test_link_api(void)
342+
static void test_link_api(void)
315343
{
316344
struct child *child;
317345

@@ -412,4 +440,6 @@ void test_uprobe_multi_test(void)
412440
test_bench_attach_uprobe();
413441
if (test__start_subtest("bench_usdt"))
414442
test_bench_attach_usdt();
443+
if (test__start_subtest("attach_api_fails"))
444+
test_attach_api_fails();
415445
}

0 commit comments

Comments
 (0)