diff options
Diffstat (limited to 'net/unix/af_unix.c')
-rw-r--r-- | net/unix/af_unix.c | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index b8788fd5e3c..e18cd3628db 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c | |||
@@ -252,7 +252,7 @@ static struct sock *__unix_find_socket_byname(struct net *net, | |||
252 | sk_for_each(s, node, &unix_socket_table[hash ^ type]) { | 252 | sk_for_each(s, node, &unix_socket_table[hash ^ type]) { |
253 | struct unix_sock *u = unix_sk(s); | 253 | struct unix_sock *u = unix_sk(s); |
254 | 254 | ||
255 | if (s->sk_net != net) | 255 | if (!net_eq(sock_net(s), net)) |
256 | continue; | 256 | continue; |
257 | 257 | ||
258 | if (u->addr->len == len && | 258 | if (u->addr->len == len && |
@@ -289,7 +289,7 @@ static struct sock *unix_find_socket_byinode(struct net *net, struct inode *i) | |||
289 | &unix_socket_table[i->i_ino & (UNIX_HASH_SIZE - 1)]) { | 289 | &unix_socket_table[i->i_ino & (UNIX_HASH_SIZE - 1)]) { |
290 | struct dentry *dentry = unix_sk(s)->dentry; | 290 | struct dentry *dentry = unix_sk(s)->dentry; |
291 | 291 | ||
292 | if (s->sk_net != net) | 292 | if (!net_eq(sock_net(s), net)) |
293 | continue; | 293 | continue; |
294 | 294 | ||
295 | if(dentry && dentry->d_inode == i) | 295 | if(dentry && dentry->d_inode == i) |
@@ -654,7 +654,7 @@ static int unix_release(struct socket *sock) | |||
654 | static int unix_autobind(struct socket *sock) | 654 | static int unix_autobind(struct socket *sock) |
655 | { | 655 | { |
656 | struct sock *sk = sock->sk; | 656 | struct sock *sk = sock->sk; |
657 | struct net *net = sk->sk_net; | 657 | struct net *net = sock_net(sk); |
658 | struct unix_sock *u = unix_sk(sk); | 658 | struct unix_sock *u = unix_sk(sk); |
659 | static u32 ordernum = 1; | 659 | static u32 ordernum = 1; |
660 | struct unix_address * addr; | 660 | struct unix_address * addr; |
@@ -758,7 +758,7 @@ fail: | |||
758 | static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) | 758 | static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) |
759 | { | 759 | { |
760 | struct sock *sk = sock->sk; | 760 | struct sock *sk = sock->sk; |
761 | struct net *net = sk->sk_net; | 761 | struct net *net = sock_net(sk); |
762 | struct unix_sock *u = unix_sk(sk); | 762 | struct unix_sock *u = unix_sk(sk); |
763 | struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; | 763 | struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; |
764 | struct dentry * dentry = NULL; | 764 | struct dentry * dentry = NULL; |
@@ -819,7 +819,11 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) | |||
819 | */ | 819 | */ |
820 | mode = S_IFSOCK | | 820 | mode = S_IFSOCK | |
821 | (SOCK_INODE(sock)->i_mode & ~current->fs->umask); | 821 | (SOCK_INODE(sock)->i_mode & ~current->fs->umask); |
822 | err = mnt_want_write(nd.path.mnt); | ||
823 | if (err) | ||
824 | goto out_mknod_dput; | ||
822 | err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0); | 825 | err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0); |
826 | mnt_drop_write(nd.path.mnt); | ||
823 | if (err) | 827 | if (err) |
824 | goto out_mknod_dput; | 828 | goto out_mknod_dput; |
825 | mutex_unlock(&nd.path.dentry->d_inode->i_mutex); | 829 | mutex_unlock(&nd.path.dentry->d_inode->i_mutex); |
@@ -899,7 +903,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr, | |||
899 | int alen, int flags) | 903 | int alen, int flags) |
900 | { | 904 | { |
901 | struct sock *sk = sock->sk; | 905 | struct sock *sk = sock->sk; |
902 | struct net *net = sk->sk_net; | 906 | struct net *net = sock_net(sk); |
903 | struct sockaddr_un *sunaddr=(struct sockaddr_un*)addr; | 907 | struct sockaddr_un *sunaddr=(struct sockaddr_un*)addr; |
904 | struct sock *other; | 908 | struct sock *other; |
905 | unsigned hash; | 909 | unsigned hash; |
@@ -996,7 +1000,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, | |||
996 | { | 1000 | { |
997 | struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; | 1001 | struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; |
998 | struct sock *sk = sock->sk; | 1002 | struct sock *sk = sock->sk; |
999 | struct net *net = sk->sk_net; | 1003 | struct net *net = sock_net(sk); |
1000 | struct unix_sock *u = unix_sk(sk), *newu, *otheru; | 1004 | struct unix_sock *u = unix_sk(sk), *newu, *otheru; |
1001 | struct sock *newsk = NULL; | 1005 | struct sock *newsk = NULL; |
1002 | struct sock *other = NULL; | 1006 | struct sock *other = NULL; |
@@ -1025,7 +1029,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, | |||
1025 | err = -ENOMEM; | 1029 | err = -ENOMEM; |
1026 | 1030 | ||
1027 | /* create new sock for complete connection */ | 1031 | /* create new sock for complete connection */ |
1028 | newsk = unix_create1(sk->sk_net, NULL); | 1032 | newsk = unix_create1(sock_net(sk), NULL); |
1029 | if (newsk == NULL) | 1033 | if (newsk == NULL) |
1030 | goto out; | 1034 | goto out; |
1031 | 1035 | ||
@@ -1312,7 +1316,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock, | |||
1312 | { | 1316 | { |
1313 | struct sock_iocb *siocb = kiocb_to_siocb(kiocb); | 1317 | struct sock_iocb *siocb = kiocb_to_siocb(kiocb); |
1314 | struct sock *sk = sock->sk; | 1318 | struct sock *sk = sock->sk; |
1315 | struct net *net = sk->sk_net; | 1319 | struct net *net = sock_net(sk); |
1316 | struct unix_sock *u = unix_sk(sk); | 1320 | struct unix_sock *u = unix_sk(sk); |
1317 | struct sockaddr_un *sunaddr=msg->msg_name; | 1321 | struct sockaddr_un *sunaddr=msg->msg_name; |
1318 | struct sock *other = NULL; | 1322 | struct sock *other = NULL; |
@@ -2016,13 +2020,14 @@ struct unix_iter_state { | |||
2016 | struct seq_net_private p; | 2020 | struct seq_net_private p; |
2017 | int i; | 2021 | int i; |
2018 | }; | 2022 | }; |
2019 | static struct sock *unix_seq_idx(struct unix_iter_state *iter, loff_t pos) | 2023 | static struct sock *unix_seq_idx(struct seq_file *seq, loff_t pos) |
2020 | { | 2024 | { |
2025 | struct unix_iter_state *iter = seq->private; | ||
2021 | loff_t off = 0; | 2026 | loff_t off = 0; |
2022 | struct sock *s; | 2027 | struct sock *s; |
2023 | 2028 | ||
2024 | for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) { | 2029 | for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) { |
2025 | if (s->sk_net != iter->p.net) | 2030 | if (sock_net(s) != seq_file_net(seq)) |
2026 | continue; | 2031 | continue; |
2027 | if (off == pos) | 2032 | if (off == pos) |
2028 | return s; | 2033 | return s; |
@@ -2035,9 +2040,8 @@ static struct sock *unix_seq_idx(struct unix_iter_state *iter, loff_t pos) | |||
2035 | static void *unix_seq_start(struct seq_file *seq, loff_t *pos) | 2040 | static void *unix_seq_start(struct seq_file *seq, loff_t *pos) |
2036 | __acquires(unix_table_lock) | 2041 | __acquires(unix_table_lock) |
2037 | { | 2042 | { |
2038 | struct unix_iter_state *iter = seq->private; | ||
2039 | spin_lock(&unix_table_lock); | 2043 | spin_lock(&unix_table_lock); |
2040 | return *pos ? unix_seq_idx(iter, *pos - 1) : ((void *) 1); | 2044 | return *pos ? unix_seq_idx(seq, *pos - 1) : SEQ_START_TOKEN; |
2041 | } | 2045 | } |
2042 | 2046 | ||
2043 | static void *unix_seq_next(struct seq_file *seq, void *v, loff_t *pos) | 2047 | static void *unix_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
@@ -2046,11 +2050,11 @@ static void *unix_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |||
2046 | struct sock *sk = v; | 2050 | struct sock *sk = v; |
2047 | ++*pos; | 2051 | ++*pos; |
2048 | 2052 | ||
2049 | if (v == (void *)1) | 2053 | if (v == SEQ_START_TOKEN) |
2050 | sk = first_unix_socket(&iter->i); | 2054 | sk = first_unix_socket(&iter->i); |
2051 | else | 2055 | else |
2052 | sk = next_unix_socket(&iter->i, sk); | 2056 | sk = next_unix_socket(&iter->i, sk); |
2053 | while (sk && (sk->sk_net != iter->p.net)) | 2057 | while (sk && (sock_net(sk) != seq_file_net(seq))) |
2054 | sk = next_unix_socket(&iter->i, sk); | 2058 | sk = next_unix_socket(&iter->i, sk); |
2055 | return sk; | 2059 | return sk; |
2056 | } | 2060 | } |
@@ -2064,7 +2068,7 @@ static void unix_seq_stop(struct seq_file *seq, void *v) | |||
2064 | static int unix_seq_show(struct seq_file *seq, void *v) | 2068 | static int unix_seq_show(struct seq_file *seq, void *v) |
2065 | { | 2069 | { |
2066 | 2070 | ||
2067 | if (v == (void *)1) | 2071 | if (v == SEQ_START_TOKEN) |
2068 | seq_puts(seq, "Num RefCount Protocol Flags Type St " | 2072 | seq_puts(seq, "Num RefCount Protocol Flags Type St " |
2069 | "Inode Path\n"); | 2073 | "Inode Path\n"); |
2070 | else { | 2074 | else { |
@@ -2176,7 +2180,7 @@ static int __init af_unix_init(void) | |||
2176 | rc = proto_register(&unix_proto, 1); | 2180 | rc = proto_register(&unix_proto, 1); |
2177 | if (rc != 0) { | 2181 | if (rc != 0) { |
2178 | printk(KERN_CRIT "%s: Cannot create unix_sock SLAB cache!\n", | 2182 | printk(KERN_CRIT "%s: Cannot create unix_sock SLAB cache!\n", |
2179 | __FUNCTION__); | 2183 | __func__); |
2180 | goto out; | 2184 | goto out; |
2181 | } | 2185 | } |
2182 | 2186 | ||
@@ -2193,7 +2197,11 @@ static void __exit af_unix_exit(void) | |||
2193 | unregister_pernet_subsys(&unix_net_ops); | 2197 | unregister_pernet_subsys(&unix_net_ops); |
2194 | } | 2198 | } |
2195 | 2199 | ||
2196 | module_init(af_unix_init); | 2200 | /* Earlier than device_initcall() so that other drivers invoking |
2201 | request_module() don't end up in a loop when modprobe tries | ||
2202 | to use a UNIX socket. But later than subsys_initcall() because | ||
2203 | we depend on stuff initialised there */ | ||
2204 | fs_initcall(af_unix_init); | ||
2197 | module_exit(af_unix_exit); | 2205 | module_exit(af_unix_exit); |
2198 | 2206 | ||
2199 | MODULE_LICENSE("GPL"); | 2207 | MODULE_LICENSE("GPL"); |