netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: [PATCH 3/9] netfilter: nft_rbtree: ignore inactive matching element with no descendants
Date: Wed, 10 Aug 2016 21:16:39 +0200	[thread overview]
Message-ID: <1470856605-7903-4-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1470856605-7903-1-git-send-email-pablo@netfilter.org>

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.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Tested-by: Anders K. Pedersen <akp@akp.dk>
---
 net/netfilter/nft_rbtree.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/net/netfilter/nft_rbtree.c b/net/netfilter/nft_rbtree.c
index 6473936..ffe9ae0 100644
--- a/net/netfilter/nft_rbtree.c
+++ b/net/netfilter/nft_rbtree.c
@@ -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);
-- 
2.1.4

  parent reply	other threads:[~2016-08-10 19:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-10 19:16 [PATCH 0/9] Netfilter fixes for net Pablo Neira Ayuso
2016-08-10 19:16 ` [PATCH 1/9] netfilter: nf_ct_h323: do not re-activate already expired timer Pablo Neira Ayuso
2016-08-10 19:16 ` [PATCH 2/9] netfilter: nf_tables: s/MFT_REG32_01/NFT_REG32_01 Pablo Neira Ayuso
2016-08-10 19:16 ` Pablo Neira Ayuso [this message]
2016-08-10 19:16 ` [PATCH 4/9] netfilter: nf_conntrack_sip: CSeq 0 is a valid CSeq Pablo Neira Ayuso
2016-08-10 19:16 ` [PATCH 5/9] netfilter: nf_ct_expect: remove the redundant slash when policy name is empty Pablo Neira Ayuso
2016-08-10 19:16 ` [PATCH 6/9] netfilter: nfnetlink_queue: fix memory leak when attach expectation successfully Pablo Neira Ayuso
2016-08-10 19:16 ` [PATCH 7/9] netfilter: nfnetlink_queue: reject verdict request from different portid Pablo Neira Ayuso
2016-08-10 19:16 ` [PATCH 8/9] netfilter: ctnetlink: reject new conntrack request with different l4proto Pablo Neira Ayuso
2016-08-10 19:16 ` [PATCH 9/9] netfilter: nft_exthdr: Add size check on u8 nft_exthdr attributes Pablo Neira Ayuso
  -- strict thread matches above, loose matches on Subject: below --
2016-08-10 18:56 [PATCH 0/9] Netfilter fixes for net Pablo Neira Ayuso
2016-08-10 18:56 ` [PATCH 3/9] netfilter: nft_rbtree: ignore inactive matching element with no descendants Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1470856605-7903-4-git-send-email-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).