Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bpf, lpm: Fix check prefixlen before walking trie

When looking up an element in LPM trie, the condition 'matchlen ==
trie->max_prefixlen' will never return true, if key->prefixlen is larger
than trie->max_prefixlen. Consequently all elements in the LPM trie will
be visited and no element is returned in the end.

To resolve this, check key->prefixlen first before walking the LPM trie.

Fixes: b95a5c4db09b ("bpf: add a longest prefix match trie map implementation")
Signed-off-by: Florian Lehner <dev@der-flo.net>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20231105085801.3742-1-dev@der-flo.net
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Florian Lehner and committed by
Alexei Starovoitov
9b75dbeb f2d2c7e1

+3
+3
kernel/bpf/lpm_trie.c
··· 231 231 struct lpm_trie_node *node, *found = NULL; 232 232 struct bpf_lpm_trie_key *key = _key; 233 233 234 + if (key->prefixlen > trie->max_prefixlen) 235 + return NULL; 236 + 234 237 /* Start walking the trie from the root node ... */ 235 238 236 239 for (node = rcu_dereference_check(trie->root, rcu_read_lock_bh_held());