]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
bpf: fix overflow check in adjust_jmp_off()
authorShung-Hsi Yu <shung-hsi.yu@suse.com>
Fri, 12 Jul 2024 08:01:24 +0000 (16:01 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 12 Jul 2024 15:54:07 +0000 (08:54 -0700)
adjust_jmp_off() incorrectly used the insn->imm field for all overflow check,
which is incorrect as that should only be done or the BPF_JMP32 | BPF_JA case,
not the general jump instruction case. Fix it by using insn->off for overflow
check in the general case.

Fixes: 5337ac4c9b80 ("bpf: Fix the corner case with may_goto and jump to the 1st insn.")
Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
Link: https://lore.kernel.org/r/20240712080127.136608-2-shung-hsi.yu@suse.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c

index c0263fb5ca4b99270b6bcf43c8632e648b6fab27..cf2eb07ddf28cd2a6fbc0b191ac967580b725f60 100644 (file)
@@ -18852,7 +18852,7 @@ static int adjust_jmp_off(struct bpf_prog *prog, u32 tgt_idx, u32 delta)
                } else {
                        if (i + 1 + insn->off != tgt_idx)
                                continue;
-                       if (signed_add16_overflows(insn->imm, delta))
+                       if (signed_add16_overflows(insn->off, delta))
                                return -ERANGE;
                        insn->off += delta;
                }