[PATCH] pppoe: fix race at init time

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Eric Dumazet
Date: Tuesday, July 28, 2009 - 10:46 am

Eric Dumazet a écrit :

So Igor still has a panic... lets try a third patch then :)

[PATCH] pppoe: fix race at init time

I believe we have a race in ppoe_init() :

As soon as dev_add_pack(&pppoes_ptype); and/or dev_add_pack(&pppoed_ptype); 
are called, we can receive packets while nets not yet fully ready
(ie : pppoe_init_net() not yet called)

This means we should be prepared to get a NULL pointer
from net_generic(net, pppoe_net_id) call.

We miss this NULL check in get_item() and possibly crash if this nets 
has no struct pppoe_net attached yet. Other subroutines
are safe.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
diff --git a/drivers/net/pppoe.c b/drivers/net/pppoe.c
index f0031f1..e50af8c 100644
--- a/drivers/net/pppoe.c
+++ b/drivers/net/pppoe.c
@@ -237,14 +237,15 @@ static struct pppox_sock *__delete_item(struct pppoe_net *pn, __be16 sid,
 static inline struct pppox_sock *get_item(struct pppoe_net *pn, __be16 sid,
 					unsigned char *addr, int ifindex)
 {
-	struct pppox_sock *po;
-
-	read_lock_bh(&pn->hash_lock);
-	po = __get_item(pn, sid, addr, ifindex);
-	if (po)
-		sock_hold(sk_pppox(po));
-	read_unlock_bh(&pn->hash_lock);
-
+	struct pppox_sock *po = NULL;
+
+	if (pn) {
+		read_lock_bh(&pn->hash_lock);
+		po = __get_item(pn, sid, addr, ifindex);
+		if (po)
+			sock_hold(sk_pppox(po));
+		read_unlock_bh(&pn->hash_lock);
+	}
 	return po;
 }
 
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] net: net_assign_generic() fix , Eric Dumazet, (Tue Jul 28, 5:36 am)
Re: [PATCH] net: net_assign_generic() fix, Pavel Emelyanov, (Tue Jul 28, 6:03 am)
Re: [PATCH] net: net_assign_generic() fix, Eric Dumazet, (Tue Jul 28, 6:16 am)
Re: [PATCH] net: net_assign_generic() fix, Eric Dumazet, (Tue Jul 28, 6:22 am)
[PATCH] pppoe: fix race at init time, Eric Dumazet, (Tue Jul 28, 10:46 am)
Re: [PATCH] pppoe: fix race at init time, Cyrill Gorcunov, (Tue Jul 28, 11:48 am)
Re: [PATCH] pppoe: fix race at init time, Igor M Podlesny, (Tue Jul 28, 8:55 pm)
Re: [PATCH] pppoe: fix race at init time, Eric Dumazet, (Tue Jul 28, 9:33 pm)
[PATCH] pppoe: fix /proc/net/pppoe, Eric Dumazet, (Wed Jul 29, 2:43 am)
Re: [PATCH] pppoe: fix race at init time, Cyrill Gorcunov, (Wed Jul 29, 7:46 am)
Re: [PATCH] pppoe: fix /proc/net/pppoe, David Miller, (Thu Jul 30, 2:19 pm)
Re: [PATCH] net: net_assign_generic() fix, David Miller, (Sun Aug 2, 12:27 pm)
Re: [PATCH] pppoe: fix race at init time, David Miller, (Wed Aug 12, 4:40 pm)
Re: [PATCH] pppoe: fix race at init time, Cyrill Gorcunov, (Fri Aug 14, 9:42 am)