Subject: [PATCH 1/2] netns: fix NULL-dereference in dev_net()

From: Brian Haley <[email-masked]>
Date: Thu, 14 Aug 2008 15:27:25 -0400

Change dev_net() to handle a NULL argument - return &init_net instead.

-Brian

Signed-off-by: Brian Haley <[email-masked]>
---

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 488c56e..baf6517 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -781,10 +781,10 @@ static inline
 struct net *dev_net(const struct net_device *dev)
 {
 #ifdef CONFIG_NET_NS
-	return dev->nd_net;
-#else
-	return &init_net;
+	if (dev)
+		return dev->nd_net;
 #endif
+	return &init_net;
 }
 
 static inline