Skip to content

Commit

Permalink
libbpf: Fix off-by-one bug in bpf_core_apply_relo()
Browse files Browse the repository at this point in the history
Fix instruction index validity check which has off-by-one error.

Fixes: 3ee4f53 ("libbpf: Split bpf_core_apply_relo() into bpf_program independent helper.")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211025224531.1088894-2-andrii@kernel.org
  • Loading branch information
Andrii Nakryiko authored and Alexei Starovoitov committed Oct 26, 2021
1 parent 9327acd commit de5d0dc
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/lib/bpf/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -5405,7 +5405,7 @@ static int bpf_core_apply_relo(struct bpf_program *prog,
* relocated, so it's enough to just subtract in-section offset
*/
insn_idx = insn_idx - prog->sec_insn_off;
if (insn_idx > prog->insns_cnt)
if (insn_idx >= prog->insns_cnt)
return -EINVAL;
insn = &prog->insns[insn_idx];

Expand Down

0 comments on commit de5d0dc

Please sign in to comment.