]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: make unknown opcode handling more robust
authorDaniel Borkmann <daniel@iogearbox.net>
Fri, 26 Jan 2018 22:33:38 +0000 (23:33 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 27 Jan 2018 00:42:05 +0000 (16:42 -0800)
commit5710ae1262ba4c38382826b228d39ca89c9bcae1
tree534845527ccef6977576db77a02f96956f329b7f
parent3e8c23d4a5bb209c4051d811b7d26be37c58cb9a
bpf: make unknown opcode handling more robust

Recent findings by syzcaller fixed in 1eb29807c87e ("bpf: arsh is
not supported in 32 bit alu thus reject it") triggered a warning
in the interpreter due to unknown opcode not being rejected by
the verifier. The 'return 0' for an unknown opcode is really not
optimal, since with BPF to BPF calls, this would go untracked by
the verifier.

Do two things here to improve the situation: i) perform basic insn
sanity check early on in the verification phase and reject every
non-uapi insn right there. The bpf_opcode_in_insntable() table
reuses the same mapping as the jumptable in ___bpf_prog_run() sans
the non-public mappings. And ii) in ___bpf_prog_run() we do need
to BUG in the case where the verifier would ever create an unknown
opcode due to some rewrites.

Note that JITs do not have such issues since they would punt to
interpreter in these situations. Moreover, the BPF_JIT_ALWAYS_ON
would also help to avoid such unknown opcodes in the first place.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/filter.h
kernel/bpf/core.c
kernel/bpf/verifier.c