ebpf icon indicating copy to clipboard operation
ebpf copied to clipboard

`ProgramInfo`'s `MapIDs()` bool returns false negatives

Open ti-mo opened this issue 3 years ago • 2 comments

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.

ti-mo avatar Dec 27 '21 13:12 ti-mo

Maybe nil slice can mean "not supported", while empty slice means no maps used?

lmb avatar Jan 14 '22 15:01 lmb

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.

ti-mo avatar Jan 17 '22 13:01 ti-mo