bpf: Preserve const register type on const OR alu ops
authorGianluca Borello <g.borello@gmail.com>
Sat, 3 Dec 2016 20:31:33 +0000 (12:31 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 5 Dec 2016 18:40:05 +0000 (13:40 -0500)
commit3c839744b33782b930c5c61df35511ede5e5a574
tree950a0b8dd43c23f87e636bacd3074a5076818d93
parentf0903ea371f56c4977d1c07c2f8d4a55846c2801
bpf: Preserve const register type on const OR alu ops

Occasionally, clang (e.g. version 3.8.1) translates a sum between two
constant operands using a BPF_OR instead of a BPF_ADD. The verifier is
currently not handling this scenario, and the destination register type
becomes UNKNOWN_VALUE even if it's still storing a constant. As a result,
the destination register cannot be used as argument to a helper function
expecting a ARG_CONST_STACK_*, limiting some use cases.

Modify the verifier to handle this case, and add a few tests to make sure
all combinations are supported, and stack boundaries are still verified
even with BPF_OR.

Signed-off-by: Gianluca Borello <g.borello@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
kernel/bpf/verifier.c
tools/testing/selftests/bpf/.gitignore
tools/testing/selftests/bpf/test_verifier.c