netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Inet-hashtable: Change the range of sk->hash lock to avoid the race condition.
@ 2013-09-12 16:32 Jun Chen
  2013-09-12 12:00 ` Eric Dumazet
  0 siblings, 1 reply; 6+ messages in thread
From: Jun Chen @ 2013-09-12 16:32 UTC (permalink / raw)
  To: edumazet; +Cc: davem, eric.dumazet, netdev, linux-kernel, Jun Chen


When try to add node to list in __inet_hash_nolisten function, first get the
list and then to lock for using, but in extremeness case, others can del this
node before locking it, then the node should be null.So this patch try to lock
firstly and then get the list for using to avoid this race condition.

Signed-off-by: Chen Jun <jun.d.chen@intel.com>
---
 net/ipv4/inet_hashtables.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 7bd8983..76e846e 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -407,12 +407,15 @@ int __inet_hash_nolisten(struct sock *sk, struct inet_timewait_sock *tw)
 	WARN_ON(!sk_unhashed(sk));
 
 	sk->sk_hash = inet_sk_ehashfn(sk);
-	head = inet_ehash_bucket(hashinfo, sk->sk_hash);
-	list = &head->chain;
 	lock = inet_ehash_lockp(hashinfo, sk->sk_hash);
 
 	spin_lock(lock);
-	__sk_nulls_add_node_rcu(sk, list);
+	if (sk_hashed(sk)) {
+		head = inet_ehash_bucket(hashinfo, sk->sk_hash);
+		list = &head->chain;
+		__sk_nulls_add_node_rcu(sk, list);
+	}
+
 	if (tw) {
 		WARN_ON(sk->sk_hash != tw->tw_hash);
 		twrefcnt = inet_twsk_unhash(tw);
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-09-13  9:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-12 16:32 [PATCH] Inet-hashtable: Change the range of sk->hash lock to avoid the race condition Jun Chen
2013-09-12 12:00 ` Eric Dumazet
2013-09-13  9:47   ` Jun Chen
2013-09-13  5:40     ` Eric Dumazet
2013-09-13 14:01       ` Jun Chen
2013-09-13  6:12         ` Eric Dumazet

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).