netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] inetpeer: fix a race in inetpeer_gc_worker()
@ 2012-06-05 13:00 Eric Dumazet
  2012-06-05 13:09 ` Steffen Klassert
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2012-06-05 13:00 UTC (permalink / raw)
  To: David Miller; +Cc: Steffen Klassert, netdev

From: Eric Dumazet <edumazet@google.com>

commit 5faa5df1fa2024 (inetpeer: Invalidate the inetpeer tree along with
the routing cache) added a race :

Before freeing an inetpeer, we must respect a RCU grace period, and make
sure no user will attempt to increase refcnt.

inetpeer_invalidate_tree() waits for a RCU grace period before inserting
inetpeer tree into gc_list and waking the worker. At that time, no
concurrent lookup can find a inetpeer in this tree.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Steffen Klassert <steffen.klassert@secunet.com>
---
v2: use a call_rcu() to let the worker running on entries that cannot be
found by concurrent lookups.

 include/net/inetpeer.h |    5 ++++-
 net/ipv4/inetpeer.c    |   16 ++++++++++++----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
index b94765e..2040bff 100644
--- a/include/net/inetpeer.h
+++ b/include/net/inetpeer.h
@@ -40,7 +40,10 @@ struct inet_peer {
 	u32			pmtu_orig;
 	u32			pmtu_learned;
 	struct inetpeer_addr_base redirect_learned;
-	struct list_head	gc_list;
+	union {
+		struct list_head	gc_list;
+		struct rcu_head     gc_rcu;
+	};
 	/*
 	 * Once inet_peer is queued for deletion (refcnt == -1), following fields
 	 * are not available: rid, ip_id_count, tcp_ts, tcp_ts_stamp
diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index d4d61b6..dfba343 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -560,6 +560,17 @@ bool inet_peer_xrlim_allow(struct inet_peer *peer, int timeout)
 }
 EXPORT_SYMBOL(inet_peer_xrlim_allow);
 
+static void inetpeer_inval_rcu(struct rcu_head *head)
+{
+	struct inet_peer *p = container_of(head, struct inet_peer, gc_rcu);
+
+	spin_lock_bh(&gc_lock);
+	list_add_tail(&p->gc_list, &gc_list);
+	spin_unlock_bh(&gc_lock);
+
+	schedule_delayed_work(&gc_work, gc_delay);
+}
+
 void inetpeer_invalidate_tree(int family)
 {
 	struct inet_peer *old, *new, *prev;
@@ -576,10 +587,7 @@ void inetpeer_invalidate_tree(int family)
 	prev = cmpxchg(&base->root, old, new);
 	if (prev == old) {
 		base->total = 0;
-		spin_lock(&gc_lock);
-		list_add_tail(&prev->gc_list, &gc_list);
-		spin_unlock(&gc_lock);
-		schedule_delayed_work(&gc_work, gc_delay);
+		call_rcu(&prev->gc_rcu, inetpeer_inval_rcu);
 	}
 
 out:

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

* Re: [PATCH v2] inetpeer: fix a race in inetpeer_gc_worker()
  2012-06-05 13:00 [PATCH v2] inetpeer: fix a race in inetpeer_gc_worker() Eric Dumazet
@ 2012-06-05 13:09 ` Steffen Klassert
  2012-06-06 17:45   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Steffen Klassert @ 2012-06-05 13:09 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: David Miller, netdev

On Tue, Jun 05, 2012 at 03:00:18PM +0200, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> commit 5faa5df1fa2024 (inetpeer: Invalidate the inetpeer tree along with
> the routing cache) added a race :
> 
> Before freeing an inetpeer, we must respect a RCU grace period, and make
> sure no user will attempt to increase refcnt.
> 
> inetpeer_invalidate_tree() waits for a RCU grace period before inserting
> inetpeer tree into gc_list and waking the worker. At that time, no
> concurrent lookup can find a inetpeer in this tree.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Steffen Klassert <steffen.klassert@secunet.com>

Acked-by: Steffen Klassert <steffen.klassert@secunet.com>

Thaks again!

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

* Re: [PATCH v2] inetpeer: fix a race in inetpeer_gc_worker()
  2012-06-05 13:09 ` Steffen Klassert
@ 2012-06-06 17:45   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2012-06-06 17:45 UTC (permalink / raw)
  To: steffen.klassert; +Cc: eric.dumazet, netdev

From: Steffen Klassert <steffen.klassert@secunet.com>
Date: Tue, 5 Jun 2012 15:09:54 +0200

> On Tue, Jun 05, 2012 at 03:00:18PM +0200, Eric Dumazet wrote:
>> From: Eric Dumazet <edumazet@google.com>
>> 
>> commit 5faa5df1fa2024 (inetpeer: Invalidate the inetpeer tree along with
>> the routing cache) added a race :
>> 
>> Before freeing an inetpeer, we must respect a RCU grace period, and make
>> sure no user will attempt to increase refcnt.
>> 
>> inetpeer_invalidate_tree() waits for a RCU grace period before inserting
>> inetpeer tree into gc_list and waking the worker. At that time, no
>> concurrent lookup can find a inetpeer in this tree.
>> 
>> Signed-off-by: Eric Dumazet <edumazet@google.com>
>> Cc: Steffen Klassert <steffen.klassert@secunet.com>
> 
> Acked-by: Steffen Klassert <steffen.klassert@secunet.com>

I'll apply this and queue it up for -stable, thanks.

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

end of thread, other threads:[~2012-06-06 17:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-05 13:00 [PATCH v2] inetpeer: fix a race in inetpeer_gc_worker() Eric Dumazet
2012-06-05 13:09 ` Steffen Klassert
2012-06-06 17:45   ` David Miller

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