diff options
| author | Daniel Wade <danjwade95@gmail.com> | 2026-03-14 13:15:20 +1100 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2026-04-02 13:09:26 +0200 |
| commit | 342aa1ee995ef5bbf876096dc3a5e51218d76fa4 (patch) | |
| tree | 7494e4cda9519c92a6e446851ddae449dd8a9fd0 /kernel/bpf | |
| parent | 9ab1227765c446942f290c83382f0b19887c55cf (diff) | |
| download | linux-342aa1ee995ef5bbf876096dc3a5e51218d76fa4.tar.gz linux-342aa1ee995ef5bbf876096dc3a5e51218d76fa4.tar.bz2 linux-342aa1ee995ef5bbf876096dc3a5e51218d76fa4.zip | |
bpf: Fix unsound scalar forking in maybe_fork_scalars() for BPF_OR
[ Upstream commit c845894ebd6fb43226b3118d6b017942550910c5 ]
maybe_fork_scalars() is called for both BPF_AND and BPF_OR when the
source operand is a constant. When dst has signed range [-1, 0], it
forks the verifier state: the pushed path gets dst = 0, the current
path gets dst = -1.
For BPF_AND this is correct: 0 & K == 0.
For BPF_OR this is wrong: 0 | K == K, not 0.
The pushed path therefore tracks dst as 0 when the runtime value is K,
producing an exploitable verifier/runtime divergence that allows
out-of-bounds map access.
Fix this by passing env->insn_idx (instead of env->insn_idx + 1) to
push_stack(), so the pushed path re-executes the ALU instruction with
dst = 0 and naturally computes the correct result for any opcode.
Fixes: bffacdb80b93 ("bpf: Recognize special arithmetic shift in the verifier")
Signed-off-by: Daniel Wade <danjwade95@gmail.com>
Reviewed-by: Amery Hung <ameryhung@gmail.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20260314021521.128361-2-danjwade95@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'kernel/bpf')
| -rw-r--r-- | kernel/bpf/verifier.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index a9e2380327b4..68fa30852051 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -14206,7 +14206,7 @@ static int maybe_fork_scalars(struct bpf_verifier_env *env, struct bpf_insn *ins else return 0; - branch = push_stack(env, env->insn_idx + 1, env->insn_idx, false); + branch = push_stack(env, env->insn_idx, env->insn_idx, false); if (IS_ERR(branch)) return PTR_ERR(branch); |
