-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add support for static callback functions (used by bpf_for_each_map_elem, bpf_user_ringbuf_drain, bpf_timer_set_callback) #797
Comments
I think we need to
What do you think? |
It's a little bit trickier as the callback_fn is defined as: So, we would need to validate helper function based on it's call site (i.e. we don't know the expected map key and value size until we know its caller). |
Thinking about this more, one approach would be to verify this as if it where just a local call to the callback function. Then we wouldn't need to know the type for the helper function (anymore than we need to know the types for local calls) |
Looks like we know the map because the verifier should make sure was initialized by bpf_timer_init(). There are requirements that are not easy to find, and some information may pass from the verifier to the runtime. |
The specifications for each function must be encoded in its signature. I don't want to end up with spec scattered all over the place. This is the reason why we have signatures and assertion extraction. |
One challenge is that its signature is not well defined, but is rather defined by the call site. I.e. without knowing what map it is, we can't know the size of key and value, but we don't know the map until it's used. |
This specific challenge can be solved by analyzing the possible map size. I don't think it's difficult, but I'm not sure we want to enter the rabbit hole of inferring function signature, though when possible it's better than inlining, performance-wise. |
Maybe if we require that callbacks are strongly typed we can use the BTF data. I.e. don't allow: And instead require: Then when the callback is used we can check that sizeof(key_type) == size of key in map etc. This will mean that we will disallow reusing the same function with different map types (something that could technically be legal). |
Linux supports passing BPF functions to helpers so that the runtime can then later invoke the static function.
How would we support this in the verifier.
The text was updated successfully, but these errors were encountered: