mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-09 18:19:06 +08:00
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: 109cea5a594f ("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
This commit is contained in:
committed by
Andrii Nakryiko
parent
475843fbf4
commit
a8a3089b5e
10
src/libbpf.c
10
src/libbpf.c
@@ -5840,14 +5840,12 @@ static int bpf_object__collect_reloc(struct bpf_object *obj)
|
|||||||
|
|
||||||
static bool insn_is_helper_call(struct bpf_insn *insn, enum bpf_func_id *func_id)
|
static bool insn_is_helper_call(struct bpf_insn *insn, enum bpf_func_id *func_id)
|
||||||
{
|
{
|
||||||
__u8 class = BPF_CLASS(insn->code);
|
if (BPF_CLASS(insn->code) == BPF_JMP &&
|
||||||
|
|
||||||
if ((class == BPF_JMP || class == BPF_JMP32) &&
|
|
||||||
BPF_OP(insn->code) == BPF_CALL &&
|
BPF_OP(insn->code) == BPF_CALL &&
|
||||||
BPF_SRC(insn->code) == BPF_K &&
|
BPF_SRC(insn->code) == BPF_K &&
|
||||||
insn->src_reg == 0 && insn->dst_reg == 0) {
|
insn->src_reg == 0 &&
|
||||||
if (func_id)
|
insn->dst_reg == 0) {
|
||||||
*func_id = insn->imm;
|
*func_id = insn->imm;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user