]> www.infradead.org Git - users/jedix/linux-maple.git/commit
libbpf: Fix event name too long error
authorFeng Yang <yangfeng@kylinos.cn>
Thu, 17 Apr 2025 01:48:46 +0000 (09:48 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 23 Apr 2025 00:13:37 +0000 (17:13 -0700)
commit4dde20b1aa85d69c4281eaac9a7cfa7d2b62ecf0
tree01b9d29b6fc00a495f3765f6859a2258429e28e8
parentbe2fea9c07d40a0a897580166e3d43c53ef3b75b
libbpf: Fix event name too long error

When the binary path is excessively long, the generated probe_name in libbpf
exceeds the kernel's MAX_EVENT_NAME_LEN limit (64 bytes).
This causes legacy uprobe event attachment to fail with error code -22.

The fix reorders the fields to place the unique ID before the name.
This ensures that even if truncation occurs via snprintf, the unique ID
remains intact, preserving event name uniqueness. Additionally, explicit
checks with MAX_EVENT_NAME_LEN are added to enforce length constraints.

Before Fix:
./test_progs -t attach_probe/kprobe-long_name
......
libbpf: failed to add legacy kprobe event for 'bpf_testmod_looooooooooooooooooooooooooooooong_name+0x0': -EINVAL
libbpf: prog 'handle_kprobe': failed to create kprobe 'bpf_testmod_looooooooooooooooooooooooooooooong_name+0x0' perf event: -EINVAL
test_attach_kprobe_long_event_name:FAIL:attach_kprobe_long_event_name unexpected error: -22
test_attach_probe:PASS:uprobe_ref_ctr_cleanup 0 nsec
#13/11   attach_probe/kprobe-long_name:FAIL
#13      attach_probe:FAIL

./test_progs -t attach_probe/uprobe-long_name
......
libbpf: failed to add legacy uprobe event for /root/linux-bpf/bpf-next/tools/testing/selftests/bpf/test_progs:0x13efd9: -EINVAL
libbpf: prog 'handle_uprobe': failed to create uprobe '/root/linux-bpf/bpf-next/tools/testing/selftests/bpf/test_progs:0x13efd9' perf event: -EINVAL
test_attach_uprobe_long_event_name:FAIL:attach_uprobe_long_event_name unexpected error: -22
#13/10   attach_probe/uprobe-long_name:FAIL
#13      attach_probe:FAIL
After Fix:
./test_progs -t attach_probe/uprobe-long_name
#13/10   attach_probe/uprobe-long_name:OK
#13      attach_probe:OK
Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED

./test_progs -t attach_probe/kprobe-long_name
#13/11   attach_probe/kprobe-long_name:OK
#13      attach_probe:OK
Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED

Fixes: 46ed5fc33db9 ("libbpf: Refactor and simplify legacy kprobe code")
Fixes: cc10623c6810 ("libbpf: Add legacy uprobe attaching support")
Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250417014848.59321-2-yangfeng59949@163.com
tools/lib/bpf/libbpf.c