ebpf: `multiple candidates for *btf.Func` error when loading bpf objects
Describe the bug
I got the following error when I tried to load BPF objects:
objs := bpfObjects{}
if err := loadBpfObjects(&objs, nil); err != nil {
log.Fatalf("loading objects: %v", err)
}
output:
2022/06/27 11:26:24 loading objects: field FentryDoSysMprotect: program fentry_do_sys_mprotect: attach Tracing/TraceFEntry: find target for fentry __x64_sys_mprotect: type __x64_sys_mprotect: multiple candidates for *btf.Func
I found multiple __x64_sys_mprotect entries in /sys/kernel/btf/vmlinux:
$ bpftool btf dump file /sys/kernel/btf/vmlinux format raw | grep __x64_sys_mprotect
[11698] FUNC '__x64_sys_mprotect' type_id=11464 linkage=static
[23528] FUNC '__x64_sys_mprotect' type_id=6062 linkage=static
However, one of them is named as __unused:
...
[2] INT 'long unsigned int' size=8 bits_offset=0 nr_bits=64 encoding=(none)
...
[175] STRUCT 'pt_regs' size=168 vlen=21
'r15' type_id=2 bits_offset=0
'r14' type_id=2 bits_offset=64
'r13' type_id=2 bits_offset=128
'r12' type_id=2 bits_offset=192
'bp' type_id=2 bits_offset=256
...
[4215] CONST '(anon)' type_id=175
...
[4220] PTR '(anon)' type_id=4215
...
[6062] FUNC_PROTO '(anon)' ret_type_id=36 vlen=1
'regs' type_id=4220
...
[11461] FWD 'pt_regs' fwd_kind=struct
[11462] CONST '(anon)' type_id=11461
[11463] PTR '(anon)' type_id=11462
[11464] FUNC_PROTO '(anon)' ret_type_id=36 vlen=1
'__unused' type_id=11463
...
[11698] FUNC '__x64_sys_mprotect' type_id=11464 linkage=static
...
[23528] FUNC '__x64_sys_mprotect' type_id=6062 linkage=static
...
I don’t know much about BTF, but I think this entry should be ignored when parsing to avoid this kind of error.
To Reproduce
$ go version
go version go1.18.3 linux/amd64
$ uname -a
Linux ip-10-5-0-115.ap-northeast-1.compute.internal 5.10.112-108.499.amzn2.x86_64 #1 SMP Wed Apr 27 23:39:40 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/issue
\S
Kernel \r on an \m
$ bpftool btf dump file /sys/kernel/btf/vmlinux format raw | grep __x64_sys_mprotect
[11698] FUNC '__x64_sys_mprotect' type_id=11464 linkage=static
[23528] FUNC '__x64_sys_mprotect' type_id=6062 linkage=static
Expected behavior
BTF entries named as __unused are simply ignored when parsing.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17
Commits related to this issue
- internal: include previous line on BPF context access error Add context if the last verifier log line indicates a context access error. See #723 — committed to lmb/ebpf by lmb 2 years ago
- internal: include previous line on BPF context access error Add context if the last verifier log line indicates a context access error. See #723 — committed to cilium/ebpf by lmb 2 years ago
This issue has been fixed in Linux 5.15.78.
@lmb Kernel developers are working on this issue now: