ebpf
ebpf copied to clipboard
`ProgramInfo`'s `MapIDs()` bool returns false negatives
Describe the bug
Currently, the (*ProgramInfo).MapIDs()'s bool return value is simply determined by pi.ids != nil, pi.ids being allocated when NrMapIds > 0. The NrMapIds field will always be zero on older kernels that don't yet support it, so it's currently impossible to tell if the prog actually references 0 maps, or whether the kernel is too old to populate the field.
Expected behavior
On kernels that do support the NrMapIds field (4.15 and up), always return true for the second argument so the caller can determine for sure that the program has no map references.
This would require implementing a probe that inserts a prog that references a map and checking if NrMapIds is populated.
Maybe nil slice can mean "not supported", while empty slice means no maps used?
Sure, but the bool's already there, so we can't remove it without breaking API, we might as well use it.
The problem is that currently, it's not possible to distinguish a prog on a new kernel that references 0 maps from a prog on an old kernel that doesn't support the mapIDs field. For forwards-compatibility reasons, older kernels will accept a newer version of the proginfo userspace struct, but won't populate the field.
I've updated the original description to reflect this.