bpf: fix possible spectre-v1 in find_and_alloc_map()
authorMark Rutland <mark.rutland@arm.com>
Thu, 3 May 2018 16:04:59 +0000 (17:04 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 3 May 2018 23:16:11 +0000 (01:16 +0200)
commit9ef09e35e521bf0df5325cc9cffa726a8f5f3c1b
treeeb370cdca5ac43b3ed7e9ce1e0e8ab14a54a673b
parenta8d7aa17bbc970971ccdf71988ea19230ab368b1
bpf: fix possible spectre-v1 in find_and_alloc_map()

It's possible for userspace to control attr->map_type. Sanitize it when
using it as an array index to prevent an out-of-bounds value being used
under speculation.

Found by smatch.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: netdev@vger.kernel.org
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
kernel/bpf/syscall.c