netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][NEIGH] Fix race between neigh_parms_release and neightbl_fill_parms
@ 2008-01-10 10:56 Pavel Emelyanov
  2008-01-10 11:50 ` David Miller
  2008-01-19 14:15 ` Andrey Rahmatullin
  0 siblings, 2 replies; 3+ messages in thread
From: Pavel Emelyanov @ 2008-01-10 10:56 UTC (permalink / raw)
  To: David Miller; +Cc: Linux Netdev List, devel

The neightbl_fill_parms() is called under the write-locked
tbl->lock and accesses the parms->dev. The negh_parm_release()
calls the dev_put(parms->dev) without this lock. This 
creates a tiny race window on which the parms contains
potentially stale dev pointer.

To fix this race it's enough to move the dev_put() upper
under the tbl->lock, but note, that the parms are held by
neighbors and thus can live after the neigh_parms_release()
is called, so we still can have a parm with bad dev pointer.

I didn't find where the neigh->parms->dev is accessed, but 
still think that putting the dev is to be done in a place,
where the parms are really freed. Am I right with that?

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>

---

diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 29b8ee4..cc8a2f1 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1316,8 +1316,6 @@ void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms)
 			*p = parms->next;
 			parms->dead = 1;
 			write_unlock_bh(&tbl->lock);
-			if (parms->dev)
-				dev_put(parms->dev);
 			call_rcu(&parms->rcu_head, neigh_rcu_free_parms);
 			return;
 		}
@@ -1328,6 +1326,8 @@ void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms)
 
 void neigh_parms_destroy(struct neigh_parms *parms)
 {
+	if (parms->dev)
+		dev_put(parms->dev);
 	kfree(parms);
 }
 

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

* Re: [PATCH][NEIGH] Fix race between neigh_parms_release and neightbl_fill_parms
  2008-01-10 10:56 [PATCH][NEIGH] Fix race between neigh_parms_release and neightbl_fill_parms Pavel Emelyanov
@ 2008-01-10 11:50 ` David Miller
  2008-01-19 14:15 ` Andrey Rahmatullin
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2008-01-10 11:50 UTC (permalink / raw)
  To: xemul; +Cc: netdev, devel

From: Pavel Emelyanov <xemul@openvz.org>
Date: Thu, 10 Jan 2008 13:56:53 +0300

> The neightbl_fill_parms() is called under the write-locked
> tbl->lock and accesses the parms->dev. The negh_parm_release()
> calls the dev_put(parms->dev) without this lock. This 
> creates a tiny race window on which the parms contains
> potentially stale dev pointer.
> 
> To fix this race it's enough to move the dev_put() upper
> under the tbl->lock, but note, that the parms are held by
> neighbors and thus can live after the neigh_parms_release()
> is called, so we still can have a parm with bad dev pointer.
> 
> I didn't find where the neigh->parms->dev is accessed, but 
> still think that putting the dev is to be done in a place,
> where the parms are really freed. Am I right with that?
> 
> Signed-off-by: Pavel Emelyanov <xemul@openvz.org>

It is accessed in lookup_neigh_parms(), neightbl_fill_parms(), and
neightbl_fill_info() (hmmm, that BUG_ON(tbl->parms.dev) is cute).

You fix looks correct, patch applied, thanks!

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

* Re: [PATCH][NEIGH] Fix race between neigh_parms_release and neightbl_fill_parms
  2008-01-10 10:56 [PATCH][NEIGH] Fix race between neigh_parms_release and neightbl_fill_parms Pavel Emelyanov
  2008-01-10 11:50 ` David Miller
@ 2008-01-19 14:15 ` Andrey Rahmatullin
  1 sibling, 0 replies; 3+ messages in thread
From: Andrey Rahmatullin @ 2008-01-19 14:15 UTC (permalink / raw)
  To: netdev

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

This patch causes messages like 'unregister_netdevice: waiting for ppp0 to
become free. Usage count = 1' when I try 'ifdown ppp0'. This happens in all
kernel versions containing this commit and doesn't happen in 2.6.24-rc8
with this commit reverted.

-- 
WBR, wRAR (ALT Linux Team)

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

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

end of thread, other threads:[~2008-01-19 14:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-10 10:56 [PATCH][NEIGH] Fix race between neigh_parms_release and neightbl_fill_parms Pavel Emelyanov
2008-01-10 11:50 ` David Miller
2008-01-19 14:15 ` Andrey Rahmatullin

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