Repository navigation
helper-functions: add newer bpf_base_func_proto helpers to base - #301
Conversation
The base group was missing helpers that bpf_base_func_proto() has
handed out to every program type for a while:
- bpf_strtol, bpf_strtoul since v6.1 (commit 8a67f2de9b1d, "bpf: expose
bpf_strtol and bpf_strtoul to all program types")
- bpf_perf_event_read_value since v6.15 (commit ae0a457f5d33)
- bpf_get_current_uid_gid, bpf_current_task_under_cgroup,
bpf_get_cgroup_classid, bpf_task_storage_{get,delete},
bpf_get_current_comm, bpf_perf_event_read, bpf_send_signal{,_thread},
bpf_get_task_stack, bpf_get_branch_snapshot and bpf_find_vma since
v6.16 (commit ee971630f20f, "bpf: Allow some trace helpers for all
prog types")
Capabilities and kconfig follow the sections of bpf_base_func_proto()
they sit in. bpf_copy_from_user and bpf_copy_from_user_task were moved
to the base set by the same v6.16 commit but are left out: they are
might_sleep helpers and the verifier rejects them in non-sleepable
programs. Of the program types that use the base group, only struct_ops
can be sleepable, so listing them in base would mostly document helpers
that can't be called. bpftool feature probe does list them for XDP, TC
and friends, because its heuristic treats "helper call might sleep in a
non-sleepable prog" as supported.
Program type and helper pages regenerated with tools/helper-ref-gen.
Signed-off-by: YoungjuKim <[email protected]>
dylandreimerink
left a comment
There was a problem hiding this comment.
Thank you! Changes look good to me.
I left out bpf_copy_from_user and bpf_copy_from_user_task. The same v6.16 commit added them to the base set, but they are might_sleep helpers, and the verifier rejects them in non-sleepable programs ("helper call might sleep in a non-sleepable prog"). Of the program types that use the base group, only struct_ops can be sleepable. I can add them for BPF_PROG_TYPE_STRUCT_OPS only if you prefer.
I think this is good for now. We still need to update the tooling to account for sleepable helpers and kfuncs, some way to annotate it and make sure they are only added to program references if program contexts can be sleepable.
I will make a GH issue for that to track that, including the helpers we left out.
The
basegroup indata/helpers-functions.yamlmirrorsbpf_base_func_proto(), but it is missing helpers that the kernel has handed to every program type for a while. For example, thebpf_get_current_commpage lists only tracing, LSM, syscall and cgroup sock types, while XDP and TC programs can call it since v6.16.Added to
base, withsinceset to the commit that moved each helper intobpf_base_func_proto():bpf_strtol,bpf_strtoul: v6.1, 8a67f2de9b1d ("bpf: expose bpf_strtol and bpf_strtoul to all program types")bpf_perf_event_read_value: v6.15, ae0a457f5d33bpf_get_current_uid_gid,bpf_current_task_under_cgroup,bpf_get_cgroup_classid,bpf_task_storage_get,bpf_task_storage_delete,bpf_get_current_comm,bpf_perf_event_read,bpf_send_signal,bpf_send_signal_thread,bpf_get_task_stack,bpf_get_branch_snapshot,bpf_find_vma: v6.16, ee971630f20f ("bpf: Allow some trace helpers for all prog types")capandkconfigfollow the section ofbpf_base_func_proto()each helper is in (no capability,CAP_BPF, orCAP_BPF+CAP_PERFMON;CONFIG_CGROUPS/CONFIG_CGROUP_NET_CLASSID). Program types that already list one of these helpers keep their own entry, because the generator lets a parent definition override the base one.I left out
bpf_copy_from_userandbpf_copy_from_user_task. The same v6.16 commit added them to the base set, but they aremight_sleephelpers, and the verifier rejects them in non-sleepable programs ("helper call might sleep in a non-sleepable prog"). Of the program types that use the base group, only struct_ops can be sleepable. I can add them forBPF_PROG_TYPE_STRUCT_OPSonly if you prefer.The program type and helper pages were regenerated with
tools/helper-ref-gen(built from this repo). No other generated files changed.How I checked it:
bpftool feature probe(bpftool v7.7.0 / libbpf 1.7) on Ubuntu 25.04 (6.14.0-37-generic) and Ubuntu 26.04 (7.0.0-38-generic). On 7.0, the v6.15/v6.16 helpers above show up for socket_filter, sched_cls, sched_act, xdp, cgroup_skb, lwt_*, sock_ops, sk_skb, sk_msg, flow_dissector, sk_reuseport, sk_lookup and netfilter (where the type didn't already have them). On 6.14 they don't.bpf_strtol/bpf_strtoulshow up on both kernels.bpf_copy_from_userfor XDP etc. on 7.0. That is because its heuristic treats any verifier error other than "unknown func" / "cannot use helper" as supported.This change was drafted with AI assistance and reviewed by me.
🤖 Generated with Claude Code