Skip to contentSkip to conversation

bpf: Check the helper function is valid in get_helper_proto

PATCH New Artem Dinaburg 2 participants 2 messages Oct 16

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 9fa984ee076bccbf5e90eb6a194cec68f2351200..bec8876f12375bbbe00d8cbe5ee7d410e48ecd88 100644
@@ -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
index 778a68bfb91dd4e765252cfb1bacb4b658d1381b..a72e1561464cb94942afa723e57c76f032d30dc0 100644
@@ -10091,7 +10091,7 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
 
 	if (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;
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] bpf: multi-line comment style violation in bpf_tail_call_proto --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] bpf: multi-line comment style violation in bpf_tail_call_proto
--

commit f05c559892f9e9f36efa93c44d19d9d526404f49
Author: Jiri Olsa <[email protected]>

bpf: Check the helper function is valid in get_helper_proto

This commit adds a check in check_helper_call() to ensure the helper function pointer is not NULL, preventing a verifier bug when config options are disabled. It also sets the unused tail_call helper function to BPF_PTR_POISON.

kernel/bpf/core.c EXPORT_SYMBOL_GPL(bpf_event_output); · line 2964

Quoted 12 lines
kernel/bpf/core.c +3 -1
index 9fa984ee076bc..bec8876f12375 100644
@@ -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
+	 */

[Severity: Low]
This isn't a bug, but does this multi-line comment follow the BPF subsystem's formatting rules? It seems the opening /* should be on its own line, with the comment text starting on the next line.

Quoted 4 lines
kernel/bpf/core.c +1 -0
+	.func		= BPF_PTR_POISON,
 	.gpl_only	= false,
 	.ret_type	= RET_VOID,
 	.arg1_type	= ARG_PTR_TO_CTX,
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1