bpf, lpm: Fix check prefixlen before walking trie
[linux-2.6-microblaze.git] / kernel / bpf / lpm_trie.c
index 17c7e77..b32be68 100644 (file)
@@ -231,6 +231,9 @@ static void *trie_lookup_elem(struct bpf_map *map, void *_key)
        struct lpm_trie_node *node, *found = NULL;
        struct bpf_lpm_trie_key *key = _key;
 
+       if (key->prefixlen > trie->max_prefixlen)
+               return NULL;
+
        /* Start walking the trie from the root node ... */
 
        for (node = rcu_dereference_check(trie->root, rcu_read_lock_bh_held());