summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAndrii Nakryiko <andriin@fb.com>2020-08-19 23:14:08 -0700
committerDaniel Borkmann <daniel@iogearbox.net>2020-08-20 16:45:09 +0200
commit9b2f6fecf3b77d2457a13f77a563c07304f15775 (patch)
treeafc42c68923d9e671ccd9384ef1a0d52ecbf2d2b /tools
parent0bc23a1d1c8a1b4a5e4b973a7a80a6d067bd3eef (diff)
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
Diffstat (limited to 'tools')
-rw-r--r--tools/lib/bpf/libbpf.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 829d62a3ad5f..0bc1fd813408 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/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)
{
- __u8 class = BPF_CLASS(insn->code);
-
- if ((class == BPF_JMP || class == BPF_JMP32) &&
+ if (BPF_CLASS(insn->code) == BPF_JMP &&
BPF_OP(insn->code) == BPF_CALL &&
BPF_SRC(insn->code) == BPF_K &&
- insn->src_reg == 0 && insn->dst_reg == 0) {
- if (func_id)
- *func_id = insn->imm;
+ insn->src_reg == 0 &&
+ insn->dst_reg == 0) {
+ *func_id = insn->imm;
return true;
}
return false;