-
Notifications
You must be signed in to change notification settings - Fork 697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LoadPinned*
silently succeeds on objects of wrong type
#1566
Comments
Yep, we should build some guard rails into the Load* functions that sanity-check fdinfo. IIRC fdinfo hasn't always been available for bpffs nodes, but my memory's a little fuzzy since it's so long ago. I ran the same train of thought a while ago when considering bpffs garbage collection in Cilium, since on newer kernels it exclusively uses bpf_link for everything now (xdp, tcx, cgroups, netkit) and it would be nice to check for defunct links on startup. Let's consider the general use case of crawling a given bpffs path and dumping all objects. We should make it trivial to write code that can do this in a loop:
The caller can write a function that walks bpffs and inserts any successful objects into a slice or map of the respective return type (*Map, *Program, *Link). This can be done in a few lines of code. Regarding
I wouldn't go for a Happy to guide anyone willing to work on this, let me know. |
LoadPinned*
silently succeeds on objects of wrong type
Okay cool, I can try to write a patch to return an error on wrong-BPF-object using |
@mtardy FYI some things are moving in #1570. This patch now always consults fdinfo regardless if ObjInfo is supported on the kernel or not. We could include a call to |
So that this code is triggered via tests and doesn't fail silently if cilium/ebpf changes its behavior, like suggested in cilium/ebpf#1566. Signed-off-by: Mahe Tardy <[email protected]>
So that this code is triggered via tests and doesn't fail silently if cilium/ebpf changes its behavior, like suggested in cilium/ebpf#1566. Signed-off-by: Mahe Tardy <[email protected]>
So that this code is triggered via tests and doesn't fail silently if cilium/ebpf changes its behavior, like suggested in cilium/ebpf#1566. Signed-off-by: Mahe Tardy <[email protected]>
So that this code is triggered via tests and doesn't fail silently if cilium/ebpf changes its behavior, like suggested in cilium/ebpf#1566. Signed-off-by: Mahe Tardy <[email protected]>
So that this code is triggered via tests and doesn't fail silently if cilium/ebpf changes its behavior, like suggested in cilium/ebpf#1566. Signed-off-by: Mahe Tardy <[email protected]>
So that this code is triggered via tests and doesn't fail silently if cilium/ebpf changes its behavior, like suggested in cilium/ebpf#1566. Signed-off-by: Mahe Tardy <[email protected]>
So that this code is triggered via tests and doesn't fail silently if cilium/ebpf changes its behavior, like suggested in cilium/ebpf#1566. Signed-off-by: Mahe Tardy <[email protected]>
I was writing something to parse objects from a
/sys/fs/bpf
fs and was expecting to receive an error when usingebpf.LoadPinnedMap
on a prog andebpf.LoadPinnedProg
on a map. Instead, the function properly returns a struct but with garbage data in each "wrong" case.So I've looked into it, it seems that the kernel doesn't expose anything to know in advance, given a BPF pinned object file, if it's a map or a prog. When you
stat
such a file there's no way to know if it's going to be a BPF map or prog.However, when you open such a file and you end up with a file descriptor, if you
readlink
this fd, you retrieve something likeanon_inode:bpf-map
oranon_inode:bpf-prog
. See here for map fd for example. This, and reading/proc/self/fdinfo/<fd>
allows you to discriminate, since you'll bump into fields namedmap_<...>
for maps andprog_<...>
for progs.All of that to say that we could use the
readlink
tricks to return an error properly instead of bogus information fromLoadPinnedMap
orLoadPinnedProg
, @dylandreimerink suggested adding this to thenewProgramInfoFromFd
for example, we could also donewMapInfoFromFd
respectively:ebpf/info.go
Line 149 in 88736f4
ebpf/info.go
Line 54 in 88736f4
On another topic, I think it would be great to have an API to parse objects indifferently if they are a map or a prog. A bit of what we can do right now with a "hack": reading everything, map and prog, as prog for example, since it doesn't return an error and then read common fields like
memlock
in fdinfo. It could be something likeLoadPinned
that would be common between maps and progs, and thus we could retrievememlock
using this object, or cast it into a map or prog if we want to go further.I could elaborate on my use case and see if it makes sense but would love to know what people think :)!
The text was updated successfully, but these errors were encountered: