Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <houtao1@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20231215100708.2265609-4-houtao@huaweicloud.com

authored by

Hou Tao and committed by
Daniel Borkmann
0d83786f d6d1e6c1

+31 -1
+31 -1
tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
··· 234 234 test_attach_api("/proc/self/exe", NULL, &opts); 235 235 } 236 236 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 + 237 265 static void __test_link_api(struct child *child) 238 266 { 239 267 int prog_fd, link1_fd = -1, link2_fd = -1, link3_fd = -1, link4_fd = -1; ··· 339 311 free(offsets); 340 312 } 341 313 342 - void test_link_api(void) 314 + static void test_link_api(void) 343 315 { 344 316 struct child *child; 345 317 ··· 440 412 test_bench_attach_uprobe(); 441 413 if (test__start_subtest("bench_usdt")) 442 414 test_bench_attach_usdt(); 415 + if (test__start_subtest("attach_api_fails")) 416 + test_attach_api_fails(); 443 417 }