[NET] NETNS: Omit sock->sk_net without CONFIG_NET_NS.
[firefly-linux-kernel-4.4.55.git] / net / unix / af_unix.c
index a0aa6d3c2c084ad713979da5dd3778a233d63a64..cb9d0cb5f2707f351dc29bc4749cd69b337a30ce 100644 (file)
 #include <net/checksum.h>
 #include <linux/security.h>
 
-int sysctl_unix_max_dgram_qlen __read_mostly = 10;
-
 static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
 static DEFINE_SPINLOCK(unix_table_lock);
 static atomic_t unix_nr_socks = ATOMIC_INIT(0);
@@ -254,7 +252,7 @@ static struct sock *__unix_find_socket_byname(struct net *net,
        sk_for_each(s, node, &unix_socket_table[hash ^ type]) {
                struct unix_sock *u = unix_sk(s);
 
-               if (s->sk_net != net)
+               if (sock_net(s) != net)
                        continue;
 
                if (u->addr->len == len &&
@@ -291,7 +289,7 @@ static struct sock *unix_find_socket_byinode(struct net *net, struct inode *i)
                    &unix_socket_table[i->i_ino & (UNIX_HASH_SIZE - 1)]) {
                struct dentry *dentry = unix_sk(s)->dentry;
 
-               if (s->sk_net != net)
+               if (sock_net(s) != net)
                        continue;
 
                if(dentry && dentry->d_inode == i)
@@ -594,7 +592,7 @@ static struct sock * unix_create1(struct net *net, struct socket *sock)
                                &af_unix_sk_receive_queue_lock_key);
 
        sk->sk_write_space      = unix_write_space;
-       sk->sk_max_ack_backlog  = sysctl_unix_max_dgram_qlen;
+       sk->sk_max_ack_backlog  = net->unx.sysctl_max_dgram_qlen;
        sk->sk_destruct         = unix_sock_destructor;
        u         = unix_sk(sk);
        u->dentry = NULL;
@@ -656,7 +654,7 @@ static int unix_release(struct socket *sock)
 static int unix_autobind(struct socket *sock)
 {
        struct sock *sk = sock->sk;
-       struct net *net = sk->sk_net;
+       struct net *net = sock_net(sk);
        struct unix_sock *u = unix_sk(sk);
        static u32 ordernum = 1;
        struct unix_address * addr;
@@ -720,16 +718,16 @@ static struct sock *unix_find_other(struct net *net,
                        goto put_fail;
 
                err = -ECONNREFUSED;
-               if (!S_ISSOCK(nd.dentry->d_inode->i_mode))
+               if (!S_ISSOCK(nd.path.dentry->d_inode->i_mode))
                        goto put_fail;
-               u=unix_find_socket_byinode(net, nd.dentry->d_inode);
+               u = unix_find_socket_byinode(net, nd.path.dentry->d_inode);
                if (!u)
                        goto put_fail;
 
                if (u->sk_type == type)
-                       touch_atime(nd.mnt, nd.dentry);
+                       touch_atime(nd.path.mnt, nd.path.dentry);
 
-               path_release(&nd);
+               path_put(&nd.path);
 
                err=-EPROTOTYPE;
                if (u->sk_type != type) {
@@ -750,7 +748,7 @@ static struct sock *unix_find_other(struct net *net,
        return u;
 
 put_fail:
-       path_release(&nd);
+       path_put(&nd.path);
 fail:
        *error=err;
        return NULL;
@@ -760,7 +758,7 @@ fail:
 static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 {
        struct sock *sk = sock->sk;
-       struct net *net = sk->sk_net;
+       struct net *net = sock_net(sk);
        struct unix_sock *u = unix_sk(sk);
        struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr;
        struct dentry * dentry = NULL;
@@ -821,12 +819,12 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
                 */
                mode = S_IFSOCK |
                       (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
-               err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
+               err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
                if (err)
                        goto out_mknod_dput;
-               mutex_unlock(&nd.dentry->d_inode->i_mutex);
-               dput(nd.dentry);
-               nd.dentry = dentry;
+               mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
+               dput(nd.path.dentry);
+               nd.path.dentry = dentry;
 
                addr->hash = UNIX_HASH_SIZE;
        }
@@ -844,8 +842,8 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
                list = &unix_socket_table[addr->hash];
        } else {
                list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
-               u->dentry = nd.dentry;
-               u->mnt    = nd.mnt;
+               u->dentry = nd.path.dentry;
+               u->mnt    = nd.path.mnt;
        }
 
        err = 0;
@@ -863,8 +861,8 @@ out:
 out_mknod_dput:
        dput(dentry);
 out_mknod_unlock:
-       mutex_unlock(&nd.dentry->d_inode->i_mutex);
-       path_release(&nd);
+       mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
+       path_put(&nd.path);
 out_mknod_parent:
        if (err==-EEXIST)
                err=-EADDRINUSE;
@@ -901,7 +899,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
                              int alen, int flags)
 {
        struct sock *sk = sock->sk;
-       struct net *net = sk->sk_net;
+       struct net *net = sock_net(sk);
        struct sockaddr_un *sunaddr=(struct sockaddr_un*)addr;
        struct sock *other;
        unsigned hash;
@@ -998,7 +996,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
 {
        struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr;
        struct sock *sk = sock->sk;
-       struct net *net = sk->sk_net;
+       struct net *net = sock_net(sk);
        struct unix_sock *u = unix_sk(sk), *newu, *otheru;
        struct sock *newsk = NULL;
        struct sock *other = NULL;
@@ -1027,7 +1025,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
        err = -ENOMEM;
 
        /* create new sock for complete connection */
-       newsk = unix_create1(sk->sk_net, NULL);
+       newsk = unix_create1(sock_net(sk), NULL);
        if (newsk == NULL)
                goto out;
 
@@ -1314,7 +1312,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
 {
        struct sock_iocb *siocb = kiocb_to_siocb(kiocb);
        struct sock *sk = sock->sk;
-       struct net *net = sk->sk_net;
+       struct net *net = sock_net(sk);
        struct unix_sock *u = unix_sk(sk);
        struct sockaddr_un *sunaddr=msg->msg_name;
        struct sock *other = NULL;
@@ -2024,7 +2022,7 @@ static struct sock *unix_seq_idx(struct unix_iter_state *iter, loff_t pos)
        struct sock *s;
 
        for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
-               if (s->sk_net != iter->p.net)
+               if (sock_net(s) != iter->p.net)
                        continue;
                if (off == pos)
                        return s;
@@ -2035,6 +2033,7 @@ static struct sock *unix_seq_idx(struct unix_iter_state *iter, loff_t pos)
 
 
 static void *unix_seq_start(struct seq_file *seq, loff_t *pos)
+       __acquires(unix_table_lock)
 {
        struct unix_iter_state *iter = seq->private;
        spin_lock(&unix_table_lock);
@@ -2051,12 +2050,13 @@ static void *unix_seq_next(struct seq_file *seq, void *v, loff_t *pos)
                sk = first_unix_socket(&iter->i);
        else
                sk = next_unix_socket(&iter->i, sk);
-       while (sk && (sk->sk_net != iter->p.net))
+       while (sk && (sock_net(sk) != iter->p.net))
                sk = next_unix_socket(&iter->i, sk);
        return sk;
 }
 
 static void unix_seq_stop(struct seq_file *seq, void *v)
+       __releases(unix_table_lock)
 {
        spin_unlock(&unix_table_lock);
 }
@@ -2140,9 +2140,15 @@ static int unix_net_init(struct net *net)
 {
        int error = -ENOMEM;
 
+       net->unx.sysctl_max_dgram_qlen = 10;
+       if (unix_sysctl_register(net))
+               goto out;
+
 #ifdef CONFIG_PROC_FS
-       if (!proc_net_fops_create(net, "unix", 0, &unix_seq_fops))
+       if (!proc_net_fops_create(net, "unix", 0, &unix_seq_fops)) {
+               unix_sysctl_unregister(net);
                goto out;
+       }
 #endif
        error = 0;
 out:
@@ -2151,6 +2157,7 @@ out:
 
 static void unix_net_exit(struct net *net)
 {
+       unix_sysctl_unregister(net);
        proc_net_remove(net, "unix");
 }
 
@@ -2169,13 +2176,12 @@ static int __init af_unix_init(void)
        rc = proto_register(&unix_proto, 1);
        if (rc != 0) {
                printk(KERN_CRIT "%s: Cannot create unix_sock SLAB cache!\n",
-                      __FUNCTION__);
+                      __func__);
                goto out;
        }
 
        sock_register(&unix_family_ops);
        register_pernet_subsys(&unix_net_ops);
-       unix_sysctl_register(&init_net);
 out:
        return rc;
 }
@@ -2183,7 +2189,6 @@ out:
 static void __exit af_unix_exit(void)
 {
        sock_unregister(PF_UNIX);
-       unix_sysctl_unregister(&init_net);
        proto_unregister(&unix_proto);
        unregister_pernet_subsys(&unix_net_ops);
 }