netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BRIDGE]: Fix fdb RCU race
@ 2007-03-22 18:29 Patrick McHardy
  2007-03-22 18:31 ` Stephen Hemminger
  2007-03-22 19:25 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Patrick McHardy @ 2007-03-22 18:29 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Linux Netdev List

[-- Attachment #1: Type: text/plain, Size: 94 bytes --]

Fix what looks like a RCU race. Untested since this is only
used by ATM, which I don't have.


[-- Attachment #2: x --]
[-- Type: text/plain, Size: 1322 bytes --]

[BRIDGE]: Fix fdb RCU race

br_fdb_get use atomic_inc to increase the refcount of an element found
on a RCU protected list, which can lead to the following race:

CPU0					CPU1

					br_fdb_get:   rcu_read_lock
					__br_fdb_get: find element
fdb_delete:   hlist_del_rcu
	      br_fdb_put
br_fdb_put:   atomic_dec_and_test
	      call_rcu(fdb_rcu_free)	br_fdb_get:   atomic_inc
						      rcu_read_unlock
fdb_rcu_free: kmem_cache_free

Use atomic_inc_not_zero instead.

Signed-off-by: Patrick McHardy <kaber@trash.net>

---
commit 6965873e9db0cb3f9a8412bd541a5309dcfb6eb6
tree 152e90dc86fe96ca7cb8f0e280827920ddb62247
parent 8559840c4ca3f2fff73a882803bc8916078fac1f
author Patrick McHardy <kaber@trash.net> Thu, 22 Mar 2007 19:20:08 +0100
committer Patrick McHardy <kaber@trash.net> Thu, 22 Mar 2007 19:20:08 +0100

 net/bridge/br_fdb.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index def2e40..8d566c1 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -197,8 +197,8 @@ struct net_bridge_fdb_entry *br_fdb_get(struct net_bridge *br,
 
 	rcu_read_lock();
 	fdb = __br_fdb_get(br, addr);
-	if (fdb)
-		atomic_inc(&fdb->use_count);
+	if (fdb && !atomic_inc_not_zero(&fdb->use_count))
+		fdb = NULL;
 	rcu_read_unlock();
 	return fdb;
 }

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

* Re: [BRIDGE]: Fix fdb RCU race
  2007-03-22 18:29 [BRIDGE]: Fix fdb RCU race Patrick McHardy
@ 2007-03-22 18:31 ` Stephen Hemminger
  2007-03-22 19:25 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2007-03-22 18:31 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: Linux Netdev List

On Thu, 22 Mar 2007 19:29:09 +0100
Patrick McHardy <kaber@trash.net> wrote:

> Fix what looks like a RCU race. Untested since this is only
> used by ATM, which I don't have.
> 

That looks right, I wonder if the ATM hooks ever get used?

-- 
Stephen Hemminger <shemminger@linux-foundation.org>

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

* Re: [BRIDGE]: Fix fdb RCU race
  2007-03-22 18:29 [BRIDGE]: Fix fdb RCU race Patrick McHardy
  2007-03-22 18:31 ` Stephen Hemminger
@ 2007-03-22 19:25 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2007-03-22 19:25 UTC (permalink / raw)
  To: kaber; +Cc: shemminger, netdev

From: Patrick McHardy <kaber@trash.net>
Date: Thu, 22 Mar 2007 19:29:09 +0100

> Fix what looks like a RCU race. Untested since this is only
> used by ATM, which I don't have.

Also applied, thanks Patrick.


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

end of thread, other threads:[~2007-03-22 19:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-22 18:29 [BRIDGE]: Fix fdb RCU race Patrick McHardy
2007-03-22 18:31 ` Stephen Hemminger
2007-03-22 19:25 ` 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).