bpf: devmap fix arithmetic overflow in bitmap_size calculation
authorJohn Fastabend <john.r.fastabend@gmail.com>
Thu, 19 Oct 2017 16:03:52 +0000 (09:03 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sat, 21 Oct 2017 23:54:09 +0000 (00:54 +0100)
An integer overflow is possible in dev_map_bitmap_size() when
calculating the BITS_TO_LONG logic which becomes, after macro
replacement,

(((n) + (d) - 1)/ (d))

where 'n' is a __u32 and 'd' is (8 * sizeof(long)). To avoid
overflow cast to u64 before arithmetic.

Reported-by: Richard Weinberger <richard@nod.at>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
kernel/bpf/devmap.c

index 52e0548ba548713b4e152b688f5597dcf91f2f88..e745d6a88224f5b5e9a8241dc7dee5d35e4832de 100644 (file)
@@ -69,7 +69,7 @@ static LIST_HEAD(dev_map_list);
 
 static u64 dev_map_bitmap_size(const union bpf_attr *attr)
 {
-       return BITS_TO_LONGS(attr->max_entries) * sizeof(unsigned long);
+       return BITS_TO_LONGS((u64) attr->max_entries) * sizeof(unsigned long);
 }
 
 static struct bpf_map *dev_map_alloc(union bpf_attr *attr)