[Help] Same eBPF program output wrong values when loading from Go (compared to libbpf with C++) #1490
-
Hello everyone, I am developing an eBPF application and having a very strange issue. I hope you could give me some clues to fix it. My usespace application is writing in Go (using cilium/ebpf package). I use the eBPF program from below example: I only use one hook point as SEC("kretprobe/inet_csk_accept") to get socket information of a new TCP accept event. I got weird value of IP address and port (no proglem with C++ userspace app). After several days try to clear any differences in environment, I still cannot find the root cause. Below is my settings to compare between Go and C++
As suggested from ChatGPT, I also dump the loaded eBPF program (bpftool prog dump xlated ID) and compare the outputs, they are same. I am thinking to get pointer address of returned socket, but logically it seems the hook function is called one, then two eBPF programs are called, at the same time, for the same event but the output (from printk) are different. I have no idea what is the next debug approach. Any suggestions or directions are appreciate. Thank you everyone. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
It's possible that something is going wrong with the CO-RE relocation. Can you provide the output of |
Beta Was this translation helpful? Give feedback.
-
Compare these file, only few lines are different due to map id I print base pointer, instruction pointer of pt_regs struct (I am not sure the way I print is corrected, but there is different in instruction pointer)
I cannot upload full code but the load ELF like the guideline:
I also realize that the eBPF program that is loaded by Go always print the same values of socket ( AF family, sport, dport) regardless of connections (sport, dport should be varied) |
Beta Was this translation helpful? Give feedback.
-
Yes, I am using latest version of this package. Below is how I attach the program.
I used bpftool to check the program was load successfully, then I got the log as my post. I also use bpftool to load the ELF file (.o) manually and it work well (corrected logs). I guess the difference here is the loader (but at the end, the byte code still are the same). |
Beta Was this translation helpful? Give feedback.
Could it be that you are attaching the kretprobe via
Kprobe
instead of https://pkg.go.dev/github.com/cilium/ebpf/link#Kretprobe?