Patch "bpf: Fix exact match conditions in trie_get_next_key()" has been added to the 6.6-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: Fix exact match conditions in trie_get_next_key()

to the 6.6-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-fix-exact-match-conditions-in-trie_get_next_key.patch
and it can be found in the queue-6.6 subdirectory.

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



commit 105ee6d4eb228d8d06776317cd8a342f014307c3
Author: Hou Tao <houtao1@xxxxxxxxxx>
Date:   Fri Dec 6 19:06:18 2024 +0800

    bpf: Fix exact match conditions in trie_get_next_key()
    
    [ Upstream commit 27abc7b3fa2e09bbe41e2924d328121546865eda ]
    
    trie_get_next_key() uses node->prefixlen == key->prefixlen to identify
    an exact match, However, it is incorrect because when the target key
    doesn't fully match the found node (e.g., node->prefixlen != matchlen),
    these two nodes may also have the same prefixlen. It will return
    expected result when the passed key exist in the trie. However when a
    recently-deleted key or nonexistent key is passed to
    trie_get_next_key(), it may skip keys and return incorrect result.
    
    Fix it by using node->prefixlen == matchlen to identify exact matches.
    When the condition is true after the search, it also implies
    node->prefixlen equals key->prefixlen, otherwise, the search would
    return NULL instead.
    
    Fixes: b471f2f1de8b ("bpf: implement MAP_GET_NEXT_KEY command for LPM_TRIE map")
    Reviewed-by: Toke Høiland-Jørgensen <toke@xxxxxxxxxx>
    Signed-off-by: Hou Tao <houtao1@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20241206110622.1161752-6-houtao@xxxxxxxxxxxxxxx
    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 958f907cdaf0e..c4f1d465ae35c 100644
--- a/kernel/bpf/lpm_trie.c
+++ b/kernel/bpf/lpm_trie.c
@@ -638,7 +638,7 @@ static int trie_get_next_key(struct bpf_map *map, void *_key, void *_next_key)
 	struct lpm_trie_node **node_stack = NULL;
 	int err = 0, stack_ptr = -1;
 	unsigned int next_bit;
-	size_t matchlen;
+	size_t matchlen = 0;
 
 	/* The get_next_key follows postorder. For the 4 node example in
 	 * the top of this file, the trie_get_next_key() returns the following
@@ -677,7 +677,7 @@ static int trie_get_next_key(struct bpf_map *map, void *_key, void *_next_key)
 		next_bit = extract_bit(key->data, node->prefixlen);
 		node = rcu_dereference(node->child[next_bit]);
 	}
-	if (!node || node->prefixlen != key->prefixlen ||
+	if (!node || node->prefixlen != matchlen ||
 	    (node->flags & LPM_TREE_NODE_FLAG_IM))
 		goto find_leftmost;
 




[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