Skip to contentSkip to conversation

bpf: Check the helper function is valid in get_helper_proto

PATCH Superseded Jiri Olsa 4 participants 5 messages Aug 13, 2025 – Aug 14, 2025

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH v2 1/1 bpf: Check the helper function is valid in get_helper_proto

From: Jiri Olsa <[email protected]>

syzbot reported an 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. Excluding tail_call helper from the check, because it is NULL by design and valid in all configs.

[1] https://lore.kernel.org/bpf/[email protected]/

---
v2 changes:
- set bpf_tail_call_proto.func to -1 so we can skip the extra check [Andrii]

 kernel/bpf/core.c     | 5 ++++-
 kernel/bpf/verifier.c | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)
kernel/bpf/core.c +4 -1
index 5d1650af899d..0f6e9a3d9960 100644
@@ -3024,7 +3024,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_helper_proto check
+	 */
+	.func		= (void *) 1,
 	.gpl_only	= false,
 	.ret_type	= RET_VOID,
 	.arg1_type	= ARG_PTR_TO_CTX,
kernel/bpf/verifier.c +1 -1
index c4f69a9e9af6..c89e2b1bc644 100644
@@ -11354,7 +11354,7 @@ static int get_helper_proto(struct bpf_verifier_env *env, int func_id,
 		return -EINVAL;
 
 	*ptr = env->ops->get_func_proto(func_id, env->prog);
-	return *ptr ? 0 : -EINVAL;
+	return *ptr && (*ptr)->func ? 0 : -EINVAL;
 }
 
 static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
Signature · 1 line
2.50.1
#1 lore raw
Quoted 27 lines · Jiri Olsa

From: Jiri Olsa <[email protected]>

syzbot reported an 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. Excluding tail_call helper from the check, because it is NULL by design and valid in all configs.

[1] https://lore.kernel.org/bpf/[email protected]/

---
v2 changes:
- set bpf_tail_call_proto.func to -1 so we can skip the extra check [Andrii]

 kernel/bpf/core.c     | 5 ++++-
 kernel/bpf/verifier.c | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)
kernel/bpf/core.c +0 -0
index 5d1650af899d..0f6e9a3d9960 100644

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

Quoted 8 lines
kernel/bpf/core.c +4 -1
@@ -3024,7 +3024,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_helper_proto check
+        */
+       .func           = (void *) 1,

we seem to have BPF_PTR_POISON in include/linux/poison.h, let's use that instead of 1?

pw-bot: cr

Quoted 19 lines
kernel/bpf/core.c +0 -0
        .gpl_only       = false,
        .ret_type       = RET_VOID,
        .arg1_type      = ARG_PTR_TO_CTX,
kernel/bpf/verifier.c +1 -2
index c4f69a9e9af6..c89e2b1bc644 100644
@@ -11354,7 +11354,7 @@ static int get_helper_proto(struct bpf_verifier_env *env, int func_id,
                return -EINVAL;
 
        *ptr = env->ops->get_func_proto(func_id, env->prog);
-       return *ptr ? 0 : -EINVAL;
+       return *ptr && (*ptr)->func ? 0 : -EINVAL;
 }
 
 static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
--

2.50.1

#2 lore raw
Quoted 29 lines · Andrii Nakryiko
Quoted 28 lines · Jiri Olsa

From: Jiri Olsa <[email protected]>

syzbot reported an 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. Excluding tail_call helper from the check, because it is NULL by design and valid in all configs.

[1] https://lore.kernel.org/bpf/[email protected]/

---
v2 changes:
- set bpf_tail_call_proto.func to -1 so we can skip the extra check [Andrii]

 kernel/bpf/core.c     | 5 ++++-
 kernel/bpf/verifier.c | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)
kernel/bpf/core.c +0 -0
index 5d1650af899d..0f6e9a3d9960 100644
@@ -3024,7 +3024,10 @@ EXPORT_SYMBOL_GPL(bpf_event_output);
 
Quoted 10 lines

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

Quoted 7 lines
kernel/bpf/core.c +4 -1
 /* 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_helper_proto check
+        */
+       .func           = (void *) 1,

we seem to have BPF_PTR_POISON in include/linux/poison.h, let's use that instead of 1?

ah I did not know about this macro, thanks

jirka

Quoted 23 lines

pw-bot: cr

Quoted 19 lines
kernel/bpf/core.c +0 -0
        .gpl_only       = false,
        .ret_type       = RET_VOID,
        .arg1_type      = ARG_PTR_TO_CTX,
kernel/bpf/verifier.c +1 -2
index c4f69a9e9af6..c89e2b1bc644 100644
@@ -11354,7 +11354,7 @@ static int get_helper_proto(struct bpf_verifier_env *env, int func_id,
                return -EINVAL;
 
        *ptr = env->ops->get_func_proto(func_id, env->prog);
-       return *ptr ? 0 : -EINVAL;
+       return *ptr && (*ptr)->func ? 0 : -EINVAL;
 }
 
 static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
--

2.50.1

Acked-by on v2 1/1
#3 lore raw
In reply to Jiri Olsa
Quoted 11 lines · Jiri Olsa

From: Jiri Olsa <[email protected]>

syzbot reported an 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. Excluding tail_call helper from the check, because it is NULL by design and valid in all configs.

[1] https://lore.kernel.org/bpf/[email protected]/

Reported-by [email protected]

The same bug was reported before by the kernel test robot at
https://lore.kernel.org/oe-lkp/[email protected], so I guess we'll need:

With that,

[...]

#4 lore raw
Quoted 17 lines · Paul Chaignon
Quoted 11 lines · Jiri Olsa

From: Jiri Olsa <[email protected]>

syzbot reported an 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. Excluding tail_call helper from the check, because it is NULL by design and valid in all configs.

[1] https://lore.kernel.org/bpf/[email protected]/

Reported-by [email protected]

The same bug was reported before by the kernel test robot at
https://lore.kernel.org/oe-lkp/[email protected], so I guess we'll need:

Quoted 6 lines

With that,

thanks, will fix

jirka