bpf: Check the helper function is valid in get_helper_proto
Subsystems (2)
PATCH 1/1 bpf: Check the helper function is valid in get_helper_proto
From: Jiri Olsa <[email protected]>
[ Upstream commit e4414b01c1cd9887bbde92f946c1ba94e40d6d64 ]
kernel test robot reported verifier bug [1] where the helper func pointer could be NULL due to disabled config option.
As Alexei suggested we could check on that in get_helper_proto directly. Marking tail_call helper func with BPF_PTR_POISON, because it is unused by design.
[1] https://lore.kernel.org/oe-lkp/[email protected]
[ Backport to 6.6.y: Apply the function-pointer validity check in
check_helper_call(), because this target has no get_helper_proto(). Refer to the target get_func_proto() callback in the tail-call comment. ]
---
Hi,
Please consider this backport of the fix for CVE-2025-39990 to 6.6.y.
The helper-validity check is applied in check_helper_call() and its comment names the target get_func_proto() callback. See the bracketed backport note above.
The complete fix is already present in 6.12.y, 6.18.y and 7.2.y.
Build-tested only as part of a cumulative 6.6.y series on x86_64 (allmodconfig, CONFIG_WERROR=y); no runtime testing.
Thanks,
Artem Dinaburg
kernel/bpf/core.c | 5 ++++- kernel/bpf/verifier.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-)
kernel/bpf/core.c +4 -1
@@ -2959,7 +2959,10 @@ EXPORT_SYMBOL_GPL(bpf_event_output);/* Always built-in helper functions. */ const struct bpf_func_proto bpf_tail_call_proto = { - .func =NULL , +/* func is unused for tail_call, we set it to pass the +* get_func_proto check +*/ + .func =BPF_PTR_POISON , .gpl_only = false, .ret_type =RET_VOID , .arg1_type =ARG_PTR_TO_CTX ,
kernel/bpf/verifier.c +1 -1
@@ -10091,7 +10091,7 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insnif (env->ops->get_func_proto) fn = env->ops->get_func_proto (func_id, env->prog); -if (!fn) { +if (!fn || !fn->func) {verbose (env,"unknown func %s#%d\n" ,func_id_name (func_id), func_id);return -EINVAL ;