mbox series

[v5,bpf-next,0/3] libbpf: Fix event name too long error and add tests

Message ID 20250417014848.59321-1-yangfeng59949@163.com (mailing list archive)
Headers show
Series libbpf: Fix event name too long error and add tests | expand

Message

Feng Yang April 17, 2025, 1:48 a.m. UTC
From: Feng Yang <yangfeng@kylinos.cn>

Hi everyone,

This series tries to fix event name too long error and add tests.

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.
---
Changes in v5:
- use strrchr instead of basename.
- kprobe_test add __weak. Thanks, Andrii Nakryiko!
- Link to v4: https://lore.kernel.org/all/20250415093907.280501-1-yangfeng59949@163.com/

Changes in v4:
- add changelog. 
- gen_uprobe_legacy_event_name and gen_kprobe_legacy_event_name are combined into a function
- kprobe_test use normal module function. Thanks, Jiri Olsa!
- Link to v3: https://lore.kernel.org/bpf/20250414093402.384872-1-yangfeng59949@163.com/

Changes in v3:
- add __sync_fetch_and_add(&index) and let snprintf() do the trimming. Thanks, Andrii Nakryiko!
- add selftests.
- Link to v2: https://lore.kernel.org/all/20250411080545.319865-1-yangfeng59949@163.com/

Changes in v2:
- Use basename() and %.32s to fix. Thanks, Hengqi Chen!
- Link to v1: https://lore.kernel.org/all/20250410052712.206785-1-yangfeng59949@163.com/

Feng Yang (3):
  libbpf: Fix event name too long error
  selftests/bpf: Add test for attaching uprobe with long event names
  selftests/bpf: Add test for attaching kprobe with long event names

 tools/lib/bpf/libbpf.c                        | 43 ++++------
 .../selftests/bpf/prog_tests/attach_probe.c   | 84 +++++++++++++++++++
 .../selftests/bpf/test_kmods/bpf_testmod.c    |  4 +
 3 files changed, 104 insertions(+), 27 deletions(-)

Comments

Jiri Olsa April 17, 2025, 11:16 a.m. UTC | #1
On Thu, Apr 17, 2025 at 09:48:45AM +0800, Feng Yang wrote:
> From: Feng Yang <yangfeng@kylinos.cn>
> 
> Hi everyone,
> 
> This series tries to fix event name too long error and add tests.
> 
> 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.
> ---
> Changes in v5:
> - use strrchr instead of basename.
> - kprobe_test add __weak. Thanks, Andrii Nakryiko!
> - Link to v4: https://lore.kernel.org/all/20250415093907.280501-1-yangfeng59949@163.com/

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka


> 
> Changes in v4:
> - add changelog. 
> - gen_uprobe_legacy_event_name and gen_kprobe_legacy_event_name are combined into a function
> - kprobe_test use normal module function. Thanks, Jiri Olsa!
> - Link to v3: https://lore.kernel.org/bpf/20250414093402.384872-1-yangfeng59949@163.com/
> 
> Changes in v3:
> - add __sync_fetch_and_add(&index) and let snprintf() do the trimming. Thanks, Andrii Nakryiko!
> - add selftests.
> - Link to v2: https://lore.kernel.org/all/20250411080545.319865-1-yangfeng59949@163.com/
> 
> Changes in v2:
> - Use basename() and %.32s to fix. Thanks, Hengqi Chen!
> - Link to v1: https://lore.kernel.org/all/20250410052712.206785-1-yangfeng59949@163.com/
> 
> Feng Yang (3):
>   libbpf: Fix event name too long error
>   selftests/bpf: Add test for attaching uprobe with long event names
>   selftests/bpf: Add test for attaching kprobe with long event names
> 
>  tools/lib/bpf/libbpf.c                        | 43 ++++------
>  .../selftests/bpf/prog_tests/attach_probe.c   | 84 +++++++++++++++++++
>  .../selftests/bpf/test_kmods/bpf_testmod.c    |  4 +
>  3 files changed, 104 insertions(+), 27 deletions(-)
> 
> -- 
> 2.43.0
>