From 9d8ead7a09143caff00bb669a27c81b01304ba49 Mon Sep 17 00:00:00 2001 From: Martynas Pumputis Date: Wed, 20 Dec 2023 13:46:24 +0100 Subject: [PATCH] Temporarily fix loading err on >= 6.6 kernels [1] changed the kprobe loading behavior in a way that if we try to attach a kprobe to a function with a duplicate name, then it will fail with EADDRNOTAVAIL [2]. As pwru loads kprobes by using function symbol names, we are prone to this behavior change. Fix the loading problem by ignoring EADDRNOTAVAIL w/ the kprobe backend. Also, instruct users when the kprobe.multi backend is used. The proper fix is to use function addrs instead of syms when loading. This is what Leon H. is working on. [1]: https://lore.kernel.org/all/20231020104250.9537-1-flaniel@linux.microsoft.com/. [2]: https://elixir.bootlin.com/linux/v6.6/source/kernel/trace/trace_kprobe.c#L884 Signed-off-by: Leon Hwang Signed-off-by: Martynas Pumputis --- main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 46eae8c3..19a86ef9 100644 --- a/main.go +++ b/main.go @@ -298,7 +298,7 @@ func main() { kp, err := link.Kprobe(name, fn, nil) bar.Increment() if err != nil { - if !errors.Is(err, os.ErrNotExist) { + if !errors.Is(err, os.ErrNotExist) && !errors.Is(err, syscall.EADDRNOTAVAIL) { log.Fatalf("Opening kprobe %s: %s\n", name, err) } else { ignored += 1 @@ -319,6 +319,10 @@ func main() { kp, err := link.KprobeMulti(fn, opts) bar.Add(len(fns)) if err != nil { + if errors.Is(err, syscall.EADDRNOTAVAIL) { + log.Fatalf("Found duplicate function name in the kernel (%s). Set --backend=kprobe to fix the loading error until https://github.com/cilium/pwru/issues/284 has been fixed", + err) + } log.Fatalf("Opening kprobe-multi for pos %d: %s\n", pos, err) } kprobes = append(kprobes, kp)