From 194dbff33762ec4f6497496aab387c9018dfc9f3 Mon Sep 17 00:00:00 2001 From: Leon Hwang Date: Tue, 12 Nov 2024 22:02:59 +0800 Subject: [PATCH] Fix a panic when stop pwru early Fix this panic: $ sudo ./pwru --output-tuple 'dst host 1.0.0.1 and port 8080' 2024/11/12 13:58:41 Attaching kprobes (via kprobe)... 102 / 1255 [---------->_________________________________________________________________________________________________________________________] 8.13% 96 p/s 231 / 1255 [----------------------->__________________________________________________________________________________________________________] 18.41% 120 p/s 2024/11/12 13:58:43 Listening for events.. SKB CPU PROCESS NETNS MARK/x IFACE PROTO MTU LEN TUPLE FUNC 2024/11/12 13:58:43 Received signal, exiting program.. 2024/11/12 13:58:43 Detaching kprobes... panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x6675d8] goroutine 1 [running]: github.com/cilium/pwru/internal/pwru.(*kprober).DetachKprobes(0x0) /root/Projects/leonhwang/pwru/internal/pwru/kprobe.go:130 +0xb8 main.main() /root/Projects/leonhwang/pwru/main.go:322 +0x2013 Signed-off-by: Leon Hwang --- internal/pwru/kprobe.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pwru/kprobe.go b/internal/pwru/kprobe.go index 8dc926bf..3fbc2a54 100644 --- a/internal/pwru/kprobe.go +++ b/internal/pwru/kprobe.go @@ -239,7 +239,7 @@ func NewKprober(ctx context.Context, funcs Funcs, coll *ebpf.Collection, a2n Add bar.Finish() select { case <-ctx.Done(): - return nil + return &k default: } log.Printf("Attached (ignored %d)\n", ignored)