Skip to contentSkip to conversation

bpf: abort verification if env->cur_state->loop_entry != NULL

PATCH Applied Eduard Zingerman 3 participants 3 messages Feb 25, 2025 – Feb 26, 2025

Subsystems (2)
lore
Share & tools
lore

Eduard Zingerman

author maintainer
#0 lore raw

PATCH 1/1 bpf: abort verification if env->cur_state->loop_entry != NULL

In addition to warning abort verification with -EFAULT. If env->cur_state->loop_entry != NULL something is irrecoverably buggy.

Fixes bbbc02b7445e ("bpf: copy_verifier_state() should copy 'loop_entry' field")
---
 kernel/bpf/verifier.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +4 -2
index 5c9b7464ec2c..942c0d2df258 100644
@@ -19340,8 +19340,10 @@ static int do_check(struct bpf_verifier_env *env)
 						return err;
 					break;
 				} else {
-					if (WARN_ON_ONCE(env->cur_state->loop_entry))
-						env->cur_state->loop_entry = NULL;
+					if (WARN_ON_ONCE(env->cur_state->loop_entry)) {
+						verbose(env, "verifier bug: env->cur_state->loop_entry != NULL\n");
+						return -EFAULT;
+					}
 					do_print_state = true;
 					continue;
 				}
Signature · 1 line
2.48.1
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Eduard Zingerman

In addition to warning abort verification with -EFAULT. If env->cur_state->loop_entry != NULL something is irrecoverably buggy.

Quoted 7 lines
Fixes bbbc02b7445e ("bpf: copy_verifier_state() should copy 'loop_entry' field")
---
 kernel/bpf/verifier.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

that works as well, thanks

Quoted 20 lines
kernel/bpf/verifier.c +4 -3
index 5c9b7464ec2c..942c0d2df258 100644
@@ -19340,8 +19340,10 @@ static int do_check(struct bpf_verifier_env *env)
                                                return err;
                                        break;
                                } else {
-                                       if (WARN_ON_ONCE(env->cur_state->loop_entry))
-                                               env->cur_state->loop_entry = NULL;
+                                       if (WARN_ON_ONCE(env->cur_state->loop_entry)) {
+                                               verbose(env, "verifier bug: env->cur_state->loop_entry != NULL\n");
+                                               return -EFAULT;
+                                       }
                                        do_print_state = true;
                                        continue;
                                }
--

2.48.1

#2 lore raw
In reply to Eduard Zingerman
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 9 lines · On Mon, 24 Feb 2025 16:38:38 -0800 you wrote:

In addition to warning abort verification with -EFAULT. If env->cur_state->loop_entry != NULL something is irrecoverably buggy.

Fixes bbbc02b7445e ("bpf: copy_verifier_state() should copy 'loop_entry' field")

[...]

Here is the summary with links:
- [bpf-next,v1] bpf: abort verification if env->cur_state->loop_entry != NULL

    https://git.kernel.org/bpf/bpf-next/c/f3c2d243a36e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html