]> git.baikalelectronics.ru Git - kernel.git/commit
bpf, lpm: fix overflows in trie_alloc checks
authorDaniel Borkmann <daniel@iogearbox.net>
Wed, 8 Feb 2017 00:19:43 +0000 (01:19 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 8 Feb 2017 19:40:03 +0000 (14:40 -0500)
commit47d636c79d2d977635c27c0255a9d23f0c401306
tree603e482c1467bc7d156623c9b83df0cee514d6aa
parentb1d228a40b4c8faae910dd320be01efbf22554da
bpf, lpm: fix overflows in trie_alloc checks

Cap the maximum (total) value size and bail out if larger than KMALLOC_MAX_SIZE
as otherwise it doesn't make any sense to proceed further, since we're
guaranteed to fail to allocate elements anyway in lpm_trie_node_alloc();
likleyhood of failure is still high for large values, though, similarly
as with htab case in non-prealloc.

Next, make sure that cost vars are really u64 instead of size_t, so that we
don't overflow on 32 bit and charge only tiny map.pages against memlock while
allowing huge max_entries; cap also the max cost like we do with other map
types.

Fixes: 8e38812b7f9c ("bpf: add a longest prefix match trie map implementation")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
kernel/bpf/lpm_trie.c