bpf: fix integer overflows
authorAlexei Starovoitov <ast@kernel.org>
Tue, 19 Dec 2017 04:12:00 +0000 (20:12 -0800)
committerPeter Michael Green <plugwash@raspbian.org>
Wed, 7 Feb 2018 23:32:32 +0000 (23:32 +0000)
commit7d443c6ae74a84a0797a722a8d7f6c447ea392bf
treef3cc6d34bd4a3da5a11e6f4e45cc9007fcea2644
parentfcb5243db9b83f23b0cb3b6a298d7b63173bf93d
bpf: fix integer overflows

There were various issues related to the limited size of integers used in
the verifier:
 - `off + size` overflow in __check_map_access()
 - `off + reg->off` overflow in check_mem_access()
 - `off + reg->var_off.value` overflow or 32-bit truncation of
   `reg->var_off.value` in check_mem_access()
 - 32-bit truncation in check_stack_boundary()

Make sure that any integer math cannot overflow by not allowing
pointer math with large values.

Also reduce the scope of "scalar op scalar" tracking.

Fixes: f1174f77b50c ("bpf/verifier: rework value tracking")
Reported-by: Jann Horn <jannh@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
[carnil:
 - adjust context, we previously change verbose() signature
 - drop changes to include/linux/bpf_verifier.h already set
]

Gbp-Pq: Topic bugfix/all
Gbp-Pq: Name bpf-fix-integer-overflows.patch
kernel/bpf/verifier.c