Skip to contentSkip to conversation

bpf: Check the helper function is valid in get_helper_proto

PATCH Superseded Jiri Olsa 3 participants 3 messages Aug 12, 2025 – Aug 13, 2025

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 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]/

---
 kernel/bpf/verifier.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +8 -1
index c4f69a9e9af6..5e38489656e2 100644
@@ -11344,6 +11344,13 @@ static bool can_elide_value_nullness(enum bpf_map_type type)
 	}
 }
 
+static bool is_valid_proto(const struct bpf_func_proto *fn)
+{
+	if (fn == &bpf_tail_call_proto)
+		return true;
+	return fn && fn->func;
+}
+
 static int get_helper_proto(struct bpf_verifier_env *env, int func_id,
 			    const struct bpf_func_proto **ptr)
 {
@@ -11354,7 +11361,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 is_valid_proto(*ptr) ? 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 23 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]/

---
 kernel/bpf/verifier.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +0 -0
index c4f69a9e9af6..5e38489656e2 100644

kernel/bpf/verifier.c static bool can_elide_value_nullness(enum bpf_map_type type) · line 11350

Quoted 7 lines
kernel/bpf/verifier.c +4 -0
@@ -11344,6 +11344,13 @@ static bool can_elide_value_nullness(enum bpf_map_type type)
        }
 }
 
+static bool is_valid_proto(const struct bpf_func_proto *fn)
+{
+       if (fn == &bpf_tail_call_proto)
+               return true;

ugh... what if we set bpf_tail_call_proto's .func to (void *)0xDEADBAD or some such and avoid this special casing?

kernel/bpf/verifier.c static int get_helper_proto(struct bpf_verifier_env *env, int func_id, · line 11357

Quoted 11 lines
kernel/bpf/verifier.c +3 -1
+       return fn && fn->func;
+}
+
 static int get_helper_proto(struct bpf_verifier_env *env, int func_id,
                            const struct bpf_func_proto **ptr)
 {
@@ -11354,7 +11361,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;

so we explicitly do not want WARN/BUG/verifier_bug() if !is_valid_proto(), is that right?

Quoted 7 lines
kernel/bpf/verifier.c +1 -1
+       return is_valid_proto(*ptr) ? 0 : -EINVAL;
 }
 
 static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
--

2.50.1

#2 lore raw
Quoted 27 lines · Andrii Nakryiko
Quoted 26 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]/

---
 kernel/bpf/verifier.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +0 -0
index c4f69a9e9af6..5e38489656e2 100644
@@ -11344,6 +11344,13 @@ static bool can_elide_value_nullness(enum bpf_map_type type)
        }
 }
 
Quoted 7 lines

kernel/bpf/verifier.c static bool can_elide_value_nullness(enum bpf_map_type type) · line 11350

Quoted 4 lines
kernel/bpf/verifier.c +4 -0
+static bool is_valid_proto(const struct bpf_func_proto *fn)
+{
+       if (fn == &bpf_tail_call_proto)
+               return true;

ugh... what if we set bpf_tail_call_proto's .func to (void *)0xDEADBAD or some such and avoid this special casing?

right, that's an option, will change

Quoted 10 lines
Quoted 10 lines
kernel/bpf/verifier.c +3 -0
+       return fn && fn->func;
+}
+
 static int get_helper_proto(struct bpf_verifier_env *env, int func_id,
                            const struct bpf_func_proto **ptr)
 {
@@ -11354,7 +11361,7 @@ static int get_helper_proto(struct bpf_verifier_env *env, int func_id,
                return -EINVAL;
 
Quoted 5 lines

kernel/bpf/verifier.c static int get_helper_proto(struct bpf_verifier_env *env, int func_id, · line 11357

Quoted 2 lines
kernel/bpf/verifier.c +0 -1
        *ptr = env->ops->get_func_proto(func_id, env->prog);
-       return *ptr ? 0 : -EINVAL;

so we explicitly do not want WARN/BUG/verifier_bug() if !is_valid_proto(), is that right?

yes, I don't think it's verifier bug if option is missing, with this change we will fail earlier in check_helper_call->get_helper_proto

jirka

Quoted 8 lines
Quoted 8 lines
kernel/bpf/verifier.c +1 -1
+       return is_valid_proto(*ptr) ? 0 : -EINVAL;
 }
 
 static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
--

2.50.1