]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: fix check_map_access smin_value test when pointer contains offset
authorDaniel Borkmann <daniel@iogearbox.net>
Wed, 2 Jan 2019 23:58:33 +0000 (00:58 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 3 Jan 2019 00:01:24 +0000 (16:01 -0800)
commitcebd98ba03bdd5c0734c76c4149dd0e23bd32a19
tree4005fca9ca55a25752eb774062aea14553fc0cba
parent0a73f66bd9a544581cc389de6332a1d5871a7d75
bpf: fix check_map_access smin_value test when pointer contains offset

In check_map_access() we probe actual bounds through __check_map_access()
with offset of reg->smin_value + off for lower bound and offset of
reg->umax_value + off for the upper bound. However, even though the
reg->smin_value could have a negative value, the final result of the
sum with off could be positive when pointer arithmetic with known and
unknown scalars is combined. In this case we reject the program with
an error such as "R<x> min value is negative, either use unsigned index
or do a if (index >=0) check." even though the access itself would be
fine. Therefore extend the check to probe whether the actual resulting
reg->smin_value + off is less than zero.

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