]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: fix branch pruning logic
authorAlexei Starovoitov <ast@fb.com>
Thu, 23 Nov 2017 00:42:05 +0000 (16:42 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 23 Nov 2017 09:56:35 +0000 (10:56 +0100)
commita92f01e27db6ee3d4070b86d94c6d51b6b37155a
tree27ca3840001ee21e75f21cd8ecfe3de4568a359f
parent526d37f55043fcf847c318205b023b954c647523
bpf: fix branch pruning logic

when the verifier detects that register contains a runtime constant
and it's compared with another constant it will prune exploration
of the branch that is guaranteed not to be taken at runtime.
This is all correct, but malicious program may be constructed
in such a way that it always has a constant comparison and
the other branch is never taken under any conditions.
In this case such path through the program will not be explored
by the verifier. It won't be taken at run-time either, but since
all instructions are JITed the malicious program may cause JITs
to complain about using reserved fields, etc.
To fix the issue we have to track the instructions explored by
the verifier and sanitize instructions that are dead at run time
with NOPs. We cannot reject such dead code, since llvm generates
it for valid C code, since it doesn't do as much data flow
analysis as the verifier does.

Fixes: 41e3263fc6b1 ("bpf: verifier (add verifier core)")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
include/linux/bpf_verifier.h
kernel/bpf/verifier.c