Phonet: disable network namespace support
authorRémi Denis-Courmont <remi.denis-courmont@nokia.com>
Fri, 17 Sep 2010 22:36:46 +0000 (01:36 +0300)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 29 Oct 2010 04:44:17 +0000 (21:44 -0700)
[Solved differently upstream]

Network namespace in the Phonet socket stack causes an OOPS when a
namespace is destroyed. This occurs as the loopback exit_net handler is
called after the Phonet exit_net handler, and re-enters the Phonet
stack. I cannot think of any nice way to fix this in kernel <= 2.6.32.

For lack of a better solution, disable namespace support completely.
If you need that, upgrade to a newer kernel.

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Ben Hutchings <ben@decadent.org.uk>
Acked-by: David S. Miller <davem@davemloft.net>
net/phonet/af_phonet.c
net/phonet/pn_dev.c
net/phonet/pn_netlink.c

index f60c0c2aacba5f1a99fe4a2fe159f43a09b78f07..519ff9d46e40fb973a192a9cec779f29ae75a286 100644 (file)
@@ -67,6 +67,8 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
        struct phonet_protocol *pnp;
        int err;
 
+       if (!net_eq(net, &init_net))
+               return -EAFNOSUPPORT;
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
 
@@ -353,6 +355,8 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
        struct sockaddr_pn sa;
        u16 len;
 
+       if (!net_eq(net, &init_net))
+               goto out;
        /* check we have at least a full Phonet header */
        if (!pskb_pull(skb, sizeof(struct phonethdr)))
                goto out;
index 5f42f30dd1682bdc2427e7b387390fe231ab305e..5a2275c4ee79d8ad6b4432916af37e73982c92ea 100644 (file)
@@ -246,7 +246,11 @@ static struct notifier_block phonet_device_notifier = {
 /* Per-namespace Phonet devices handling */
 static int phonet_init_net(struct net *net)
 {
-       struct phonet_net *pnn = kmalloc(sizeof(*pnn), GFP_KERNEL);
+       struct phonet_net *pnn;
+
+       if (!net_eq(net, &init_net))
+               return 0;
+       pnn = kmalloc(sizeof(*pnn), GFP_KERNEL);
        if (!pnn)
                return -ENOMEM;
 
@@ -263,9 +267,13 @@ static int phonet_init_net(struct net *net)
 
 static void phonet_exit_net(struct net *net)
 {
-       struct phonet_net *pnn = net_generic(net, phonet_net_id);
+       struct phonet_net *pnn;
        struct net_device *dev;
 
+       if (!net_eq(net, &init_net))
+               return;
+       pnn = net_generic(net, phonet_net_id);
+
        rtnl_lock();
        for_each_netdev(net, dev)
                phonet_device_destroy(dev);
index d21fd357661022d7b451d26ad93f43301f12b2ac..7acab1ea4fc53ded176566ca91660151a8faddc8 100644 (file)
@@ -68,6 +68,8 @@ static int addr_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *attr)
        int err;
        u8 pnaddr;
 
+       if (!net_eq(net, &init_net))
+               return -EOPNOTSUPP;
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
 
@@ -124,12 +126,16 @@ nla_put_failure:
 
 static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
 {
+       struct net *net = sock_net(skb->sk);
        struct phonet_device_list *pndevs;
        struct phonet_device *pnd;
        int dev_idx = 0, dev_start_idx = cb->args[0];
        int addr_idx = 0, addr_start_idx = cb->args[1];
 
-       pndevs = phonet_device_list(sock_net(skb->sk));
+       if (!net_eq(net, &init_net))
+               goto skip;
+
+       pndevs = phonet_device_list(net);
        spin_lock_bh(&pndevs->lock);
        list_for_each_entry(pnd, &pndevs->list, list) {
                u8 addr;
@@ -154,6 +160,7 @@ static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
 
 out:
        spin_unlock_bh(&pndevs->lock);
+skip:
        cb->args[0] = dev_idx;
        cb->args[1] = addr_idx;