Skip to contentSkip to conversation

libbpf: Fix uretprobe.multi.s programs auto attachment

PATCH Applied Jiri Olsa 3 participants 3 messages Sep 10, 2024

Subsystems (2)
lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/1 libbpf: Fix uretprobe.multi.s programs auto attachment

As reported by Andrii we don't currently recognize uretprobe.multi.s programs as return probes due to using (wrong) strcmp function.

Using strncmp instead to match uretprobe.multi as prefix.

Tests are passing, because the return program was executed as entry program and all counts were incremented properly.

---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +1 -1
index 4f29e06c2641..08e110392516 100644
@@ -11688,7 +11688,7 @@ static int attach_uprobe_multi(const struct bpf_program *prog, long cookie, stru
 		ret = 0;
 		break;
 	case 3:
-		opts.retprobe = strcmp(probe_type, "uretprobe.multi") == 0;
+		opts.retprobe = strncmp(probe_type, "uretprobe.multi", sizeof("uretprobe.multi") - 1) == 0;
 		*link = bpf_program__attach_uprobe_multi(prog, -1, binary_path, func_name, &opts);
 		ret = libbpf_get_error(*link);
 		break;
Signature · 1 line
2.46.0
#1 lore raw
Quoted 21 lines · Jiri Olsa

As reported by Andrii we don't currently recognize uretprobe.multi.s programs as return probes due to using (wrong) strcmp function.

Using strncmp instead to match uretprobe.multi as prefix.

Tests are passing, because the return program was executed as entry program and all counts were incremented properly.

---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +0 -0
index 4f29e06c2641..08e110392516 100644

tools/lib/bpf/libbpf.c static int attach_uprobe_multi(const struct bpf_program *prog, long cookie, stru · line 11691

Quoted 5 lines
tools/lib/bpf/libbpf.c +1 -1
@@ -11688,7 +11688,7 @@ static int attach_uprobe_multi(const struct bpf_program *prog, long cookie, stru
                ret = 0;
                break;
        case 3:
-               opts.retprobe = strcmp(probe_type, "uretprobe.multi") == 0;
+               opts.retprobe = strncmp(probe_type, "uretprobe.multi", sizeof("uretprobe.multi") - 1) == 0;

I replaced this with opts.retprobe = str_has_pfx(probe_type, "uretprobe.multi");, less duplication

Quoted 6 lines
tools/lib/bpf/libbpf.c +0 -1
                *link = bpf_program__attach_uprobe_multi(prog, -1, binary_path, func_name, &opts);
                ret = libbpf_get_error(*link);
                break;
--

2.46.0

#2 lore raw
In reply to Jiri Olsa
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 9 lines · On Tue, 10 Sep 2024 14:53:36 +0200 you wrote:

As reported by Andrii we don't currently recognize uretprobe.multi.s programs as return probes due to using (wrong) strcmp function.

Using strncmp instead to match uretprobe.multi as prefix.

Tests are passing, because the return program was executed as entry program and all counts were incremented properly.

[...]

Here is the summary with links:
- [bpf-next] libbpf: Fix uretprobe.multi.s programs auto attachment

    https://git.kernel.org/bpf/bpf-next/c/8c8b47597403

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html