Commit 4a04b4f0 authored by Shung-Hsi Yu's avatar Shung-Hsi Yu Committed by Alexei Starovoitov

bpf: fix overflow check in adjust_jmp_off()

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: 5337ac4c ("bpf: Fix the corner case with may_goto and jump to the 1st insn.")
Signed-off-by: default avatarShung-Hsi Yu <shung-hsi.yu@suse.com>
Link: https://lore.kernel.org/r/20240712080127.136608-2-shung-hsi.yu@suse.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 2454075f
...@@ -18852,7 +18852,7 @@ static int adjust_jmp_off(struct bpf_prog *prog, u32 tgt_idx, u32 delta) ...@@ -18852,7 +18852,7 @@ static int adjust_jmp_off(struct bpf_prog *prog, u32 tgt_idx, u32 delta)
} else { } else {
if (i + 1 + insn->off != tgt_idx) if (i + 1 + insn->off != tgt_idx)
continue; continue;
if (signed_add16_overflows(insn->imm, delta)) if (signed_add16_overflows(insn->off, delta))
return -ERANGE; return -ERANGE;
insn->off += delta; insn->off += delta;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment