Skip to contentSkip to conversation

netfilter: nft_rbtree: ignore inactive matching element with no descendants

PATCH In review Pablo Neira Ayuso 2 participants 2 messages Aug 1, 2016

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nft_rbtree: ignore inactive matching element with no descendants

If we find a matching element that is inactive with no descendants, we jump to the found label, then crash because of nul-dereference on the left branch.

Fix this by checking that the element is active and not an interval end and skipping the logic that only applies to the tree iteration.

---
Slightly larger than Florian's fix but we get rid of the goto here that gcc consider branches with gotos as unlikely.

 net/netfilter/nft_rbtree.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
net/netfilter/nft_rbtree.c +6 -4
index 6473936..ffe9ae0 100644
@@ -70,7 +70,6 @@ static bool nft_rbtree_lookup(const struct net *net, const struct nft_set *set,
 		} else if (d > 0)
 			parent = parent->rb_right;
 		else {
-found:
 			if (!nft_set_elem_active(&rbe->ext, genmask)) {
 				parent = parent->rb_left;
 				continue;
@@ -84,9 +83,12 @@ found:
 		}
 	}
 
-	if (set->flags & NFT_SET_INTERVAL && interval != NULL) {
-		rbe = interval;
-		goto found;
+	if (set->flags & NFT_SET_INTERVAL && interval != NULL &&
+	    nft_set_elem_active(&interval->ext, genmask) &&
+	    !nft_rbtree_interval_end(interval)) {
+		spin_unlock_bh(&nft_rbtree_lock);
+		*ext = &interval->ext;
+		return true;
 	}
 out:
 	spin_unlock_bh(&nft_rbtree_lock);
Signature · 1 line
2.1.4
Tested-by on v1 1/1
#1 lore raw
Quoted 10 lines · Pablo Neira Ayuso

If we find a matching element that is inactive with no descendants, we
jump to the found label, then crash because of nul-dereference on the left branch.

Fix this by checking that the element is active and not an interval end
and skipping the logic that only applies to the tree iteration.

I applied this on top of Linux 4.7 and verified that it solves the kernel BUGs, I previously ran into with nftables sets.

Thanks,
Anders K. Pedersen