Patch "bpf, lpm: Fix check prefixlen before walking trie" has been added to the 4.19-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    bpf, lpm: Fix check prefixlen before walking trie

to the 4.19-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     bpf-lpm-fix-check-prefixlen-before-walking-trie.patch
and it can be found in the queue-4.19 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 6a740518d24afc198ca65d22632deea277ca60a3
Author: Florian Lehner <dev@xxxxxxxxxxx>
Date:   Sun Nov 5 09:58:01 2023 +0100

    bpf, lpm: Fix check prefixlen before walking trie
    
    [ Upstream commit 9b75dbeb36fcd9fc7ed51d370310d0518a387769 ]
    
    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@xxxxxxxxxxx>
    Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
    Link: https://lore.kernel.org/bpf/20231105085801.3742-1-dev@xxxxxxxxxxx
    Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/kernel/bpf/lpm_trie.c b/kernel/bpf/lpm_trie.c
index 1a8b208f6c55..fcd3a15add41 100644
--- a/kernel/bpf/lpm_trie.c
+++ b/kernel/bpf/lpm_trie.c
@@ -194,6 +194,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(trie->root); node;) {




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux