netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: stable@vger.kernel.org
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH -stable] netfilter: nft_rbtree: fix locking
Date: Sat, 16 May 2015 20:50:51 +0200	[thread overview]
Message-ID: <1431802251-4781-7-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1431802251-4781-1-git-send-email-pablo@netfilter.org>

From: Patrick McHardy <kaber@trash.net>

[ upstream commit 16c45eda96038aae848b6cfd42e2bf4b5e80f365 ]

Fix a race condition and unnecessary locking:

* the root rb_node must only be accessed under the lock in nft_rbtree_lookup()
* the lock is not needed in lookup functions in netlink context

Cc: <stable@vger.kernel.org> # 3.18.x
Cc: <stable@vger.kernel.org> # 3.19.x
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nft_rbtree.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/net/netfilter/nft_rbtree.c b/net/netfilter/nft_rbtree.c
index 46214f2..2c75361 100644
--- a/net/netfilter/nft_rbtree.c
+++ b/net/netfilter/nft_rbtree.c
@@ -37,10 +37,11 @@ static bool nft_rbtree_lookup(const struct nft_set *set,
 {
 	const struct nft_rbtree *priv = nft_set_priv(set);
 	const struct nft_rbtree_elem *rbe, *interval = NULL;
-	const struct rb_node *parent = priv->root.rb_node;
+	const struct rb_node *parent;
 	int d;
 
 	spin_lock_bh(&nft_rbtree_lock);
+	parent = priv->root.rb_node;
 	while (parent != NULL) {
 		rbe = rb_entry(parent, struct nft_rbtree_elem, node);
 
@@ -158,7 +159,6 @@ static int nft_rbtree_get(const struct nft_set *set, struct nft_set_elem *elem)
 	struct nft_rbtree_elem *rbe;
 	int d;
 
-	spin_lock_bh(&nft_rbtree_lock);
 	while (parent != NULL) {
 		rbe = rb_entry(parent, struct nft_rbtree_elem, node);
 
@@ -173,11 +173,9 @@ static int nft_rbtree_get(const struct nft_set *set, struct nft_set_elem *elem)
 			    !(rbe->flags & NFT_SET_ELEM_INTERVAL_END))
 				nft_data_copy(&elem->data, rbe->data);
 			elem->flags = rbe->flags;
-			spin_unlock_bh(&nft_rbtree_lock);
 			return 0;
 		}
 	}
-	spin_unlock_bh(&nft_rbtree_lock);
 	return -ENOENT;
 }
 
-- 
1.7.10.4

  parent reply	other threads:[~2015-05-16 18:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-16 18:50 [PATCH -stable] netfilter: nf_tables: fix error handling of rule replacement Pablo Neira Ayuso
2015-05-16 18:50 ` [PATCH -stable] netfilter: Zero the tuple in nfnl_cthelper_parse_tuple() Pablo Neira Ayuso
2015-05-19 11:31   ` Jiri Slaby
2015-05-16 18:50 ` [PATCH -stable] netfilter: nf_tables: check for overflow of rule dlen field Pablo Neira Ayuso
2015-05-16 18:50 ` [PATCH -stable] netfilter: nft_compat: set IP6T_F_PROTO flag if protocol is set Pablo Neira Ayuso
2015-05-16 18:50 ` [PATCH -stable] netfilter: restore rule tracing via nfnetlink_log Pablo Neira Ayuso
2015-05-16 18:50 ` [PATCH -stable] netfilter: nf_tables: allow to change chain policy without hook if it exists Pablo Neira Ayuso
2015-05-16 18:50 ` Pablo Neira Ayuso [this message]
2015-06-29 23:00   ` [PATCH -stable] netfilter: nft_rbtree: fix locking Greg KH
2015-07-01 11:38     ` Pablo Neira Ayuso
2015-05-20 12:12 ` [PATCH -stable] netfilter: nf_tables: fix error handling of rule replacement Luis Henriques

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=1431802251-4781-7-git-send-email-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=stable@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).