Skip to content

Commit 9b2f6fe

Browse files
anakryikoborkmann
authored andcommitted
libbpf: Fix detection of BPF helper call instruction
BPF_CALL | BPF_JMP32 is explicitly not allowed by verifier for BPF helper calls, so don't detect it as a valid call. Also drop the check on func_id pointer, as it's currently always non-null. Fixes: 109cea5 ("libbpf: Sanitize BPF program code for bpf_probe_read_{kernel, user}[_str]") Reported-by: Yonghong Song <yhs@fb.com> Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/bpf/20200820061411.1755905-1-andriin@fb.com
1 parent 0bc23a1 commit 9b2f6fe

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5840,14 +5840,12 @@ static int bpf_object__collect_reloc(struct bpf_object *obj)
58405840

58415841
static bool insn_is_helper_call(struct bpf_insn *insn, enum bpf_func_id *func_id)
58425842
{
5843-
__u8 class = BPF_CLASS(insn->code);
5844-
5845-
if ((class == BPF_JMP || class == BPF_JMP32) &&
5843+
if (BPF_CLASS(insn->code) == BPF_JMP &&
58465844
BPF_OP(insn->code) == BPF_CALL &&
58475845
BPF_SRC(insn->code) == BPF_K &&
5848-
insn->src_reg == 0 && insn->dst_reg == 0) {
5849-
if (func_id)
5850-
*func_id = insn->imm;
5846+
insn->src_reg == 0 &&
5847+
insn->dst_reg == 0) {
5848+
*func_id = insn->imm;
58515849
return true;
58525850
}
58535851
return false;

0 commit comments

Comments
 (0)