diff options
author | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2012-09-03 02:26:33 -0400 |
---|---|---|
committer | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2012-09-03 02:26:33 -0400 |
commit | c50e86ce7c2961a41f2f7aa6e4fd6c99229ba205 (patch) | |
tree | 4ea36009719bd8fc523239fe1bdccb90f0dce3ae /net/unix | |
parent | 14d33d384693eb6083396199de516fdef320f7af (diff) | |
parent | 4cbe5a555fa58a79b6ecbb6c531b8bab0650778d (diff) |
Merge tag 'v3.6-rc4'
Merge 3.6-rc4 to get latest OMAP and device tree fixes.
Diffstat (limited to 'net/unix')
-rw-r--r-- | net/unix/af_unix.c | 207 | ||||
-rw-r--r-- | net/unix/diag.c | 115 |
2 files changed, 162 insertions, 160 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 641f2e47f165..c5ee4ff61364 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c | |||
@@ -115,15 +115,24 @@ | |||
115 | #include <net/checksum.h> | 115 | #include <net/checksum.h> |
116 | #include <linux/security.h> | 116 | #include <linux/security.h> |
117 | 117 | ||
118 | struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1]; | 118 | struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE]; |
119 | EXPORT_SYMBOL_GPL(unix_socket_table); | 119 | EXPORT_SYMBOL_GPL(unix_socket_table); |
120 | DEFINE_SPINLOCK(unix_table_lock); | 120 | DEFINE_SPINLOCK(unix_table_lock); |
121 | EXPORT_SYMBOL_GPL(unix_table_lock); | 121 | EXPORT_SYMBOL_GPL(unix_table_lock); |
122 | static atomic_long_t unix_nr_socks; | 122 | static atomic_long_t unix_nr_socks; |
123 | 123 | ||
124 | #define unix_sockets_unbound (&unix_socket_table[UNIX_HASH_SIZE]) | ||
125 | 124 | ||
126 | #define UNIX_ABSTRACT(sk) (unix_sk(sk)->addr->hash != UNIX_HASH_SIZE) | 125 | static struct hlist_head *unix_sockets_unbound(void *addr) |
126 | { | ||
127 | unsigned long hash = (unsigned long)addr; | ||
128 | |||
129 | hash ^= hash >> 16; | ||
130 | hash ^= hash >> 8; | ||
131 | hash %= UNIX_HASH_SIZE; | ||
132 | return &unix_socket_table[UNIX_HASH_SIZE + hash]; | ||
133 | } | ||
134 | |||
135 | #define UNIX_ABSTRACT(sk) (unix_sk(sk)->addr->hash < UNIX_HASH_SIZE) | ||
127 | 136 | ||
128 | #ifdef CONFIG_SECURITY_NETWORK | 137 | #ifdef CONFIG_SECURITY_NETWORK |
129 | static void unix_get_secdata(struct scm_cookie *scm, struct sk_buff *skb) | 138 | static void unix_get_secdata(struct scm_cookie *scm, struct sk_buff *skb) |
@@ -645,7 +654,7 @@ static struct sock *unix_create1(struct net *net, struct socket *sock) | |||
645 | INIT_LIST_HEAD(&u->link); | 654 | INIT_LIST_HEAD(&u->link); |
646 | mutex_init(&u->readlock); /* single task reading lock */ | 655 | mutex_init(&u->readlock); /* single task reading lock */ |
647 | init_waitqueue_head(&u->peer_wait); | 656 | init_waitqueue_head(&u->peer_wait); |
648 | unix_insert_socket(unix_sockets_unbound, sk); | 657 | unix_insert_socket(unix_sockets_unbound(sk), sk); |
649 | out: | 658 | out: |
650 | if (sk == NULL) | 659 | if (sk == NULL) |
651 | atomic_long_dec(&unix_nr_socks); | 660 | atomic_long_dec(&unix_nr_socks); |
@@ -814,6 +823,34 @@ fail: | |||
814 | return NULL; | 823 | return NULL; |
815 | } | 824 | } |
816 | 825 | ||
826 | static int unix_mknod(const char *sun_path, umode_t mode, struct path *res) | ||
827 | { | ||
828 | struct dentry *dentry; | ||
829 | struct path path; | ||
830 | int err = 0; | ||
831 | /* | ||
832 | * Get the parent directory, calculate the hash for last | ||
833 | * component. | ||
834 | */ | ||
835 | dentry = kern_path_create(AT_FDCWD, sun_path, &path, 0); | ||
836 | err = PTR_ERR(dentry); | ||
837 | if (IS_ERR(dentry)) | ||
838 | return err; | ||
839 | |||
840 | /* | ||
841 | * All right, let's create it. | ||
842 | */ | ||
843 | err = security_path_mknod(&path, dentry, mode, 0); | ||
844 | if (!err) { | ||
845 | err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0); | ||
846 | if (!err) { | ||
847 | res->mnt = mntget(path.mnt); | ||
848 | res->dentry = dget(dentry); | ||
849 | } | ||
850 | } | ||
851 | done_path_create(&path, dentry); | ||
852 | return err; | ||
853 | } | ||
817 | 854 | ||
818 | static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) | 855 | static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) |
819 | { | 856 | { |
@@ -822,8 +859,6 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) | |||
822 | struct unix_sock *u = unix_sk(sk); | 859 | struct unix_sock *u = unix_sk(sk); |
823 | struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr; | 860 | struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr; |
824 | char *sun_path = sunaddr->sun_path; | 861 | char *sun_path = sunaddr->sun_path; |
825 | struct dentry *dentry = NULL; | ||
826 | struct path path; | ||
827 | int err; | 862 | int err; |
828 | unsigned int hash; | 863 | unsigned int hash; |
829 | struct unix_address *addr; | 864 | struct unix_address *addr; |
@@ -860,43 +895,23 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) | |||
860 | atomic_set(&addr->refcnt, 1); | 895 | atomic_set(&addr->refcnt, 1); |
861 | 896 | ||
862 | if (sun_path[0]) { | 897 | if (sun_path[0]) { |
863 | umode_t mode; | 898 | struct path path; |
864 | err = 0; | 899 | umode_t mode = S_IFSOCK | |
865 | /* | ||
866 | * Get the parent directory, calculate the hash for last | ||
867 | * component. | ||
868 | */ | ||
869 | dentry = kern_path_create(AT_FDCWD, sun_path, &path, 0); | ||
870 | err = PTR_ERR(dentry); | ||
871 | if (IS_ERR(dentry)) | ||
872 | goto out_mknod_parent; | ||
873 | |||
874 | /* | ||
875 | * All right, let's create it. | ||
876 | */ | ||
877 | mode = S_IFSOCK | | ||
878 | (SOCK_INODE(sock)->i_mode & ~current_umask()); | 900 | (SOCK_INODE(sock)->i_mode & ~current_umask()); |
879 | err = mnt_want_write(path.mnt); | 901 | err = unix_mknod(sun_path, mode, &path); |
880 | if (err) | 902 | if (err) { |
881 | goto out_mknod_dput; | 903 | if (err == -EEXIST) |
882 | err = security_path_mknod(&path, dentry, mode, 0); | 904 | err = -EADDRINUSE; |
883 | if (err) | 905 | unix_release_addr(addr); |
884 | goto out_mknod_drop_write; | 906 | goto out_up; |
885 | err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0); | 907 | } |
886 | out_mknod_drop_write: | ||
887 | mnt_drop_write(path.mnt); | ||
888 | if (err) | ||
889 | goto out_mknod_dput; | ||
890 | mutex_unlock(&path.dentry->d_inode->i_mutex); | ||
891 | dput(path.dentry); | ||
892 | path.dentry = dentry; | ||
893 | |||
894 | addr->hash = UNIX_HASH_SIZE; | 908 | addr->hash = UNIX_HASH_SIZE; |
895 | } | 909 | hash = path.dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1); |
896 | 910 | spin_lock(&unix_table_lock); | |
897 | spin_lock(&unix_table_lock); | 911 | u->path = path; |
898 | 912 | list = &unix_socket_table[hash]; | |
899 | if (!sun_path[0]) { | 913 | } else { |
914 | spin_lock(&unix_table_lock); | ||
900 | err = -EADDRINUSE; | 915 | err = -EADDRINUSE; |
901 | if (__unix_find_socket_byname(net, sunaddr, addr_len, | 916 | if (__unix_find_socket_byname(net, sunaddr, addr_len, |
902 | sk->sk_type, hash)) { | 917 | sk->sk_type, hash)) { |
@@ -905,9 +920,6 @@ out_mknod_drop_write: | |||
905 | } | 920 | } |
906 | 921 | ||
907 | list = &unix_socket_table[addr->hash]; | 922 | list = &unix_socket_table[addr->hash]; |
908 | } else { | ||
909 | list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)]; | ||
910 | u->path = path; | ||
911 | } | 923 | } |
912 | 924 | ||
913 | err = 0; | 925 | err = 0; |
@@ -921,16 +933,6 @@ out_up: | |||
921 | mutex_unlock(&u->readlock); | 933 | mutex_unlock(&u->readlock); |
922 | out: | 934 | out: |
923 | return err; | 935 | return err; |
924 | |||
925 | out_mknod_dput: | ||
926 | dput(dentry); | ||
927 | mutex_unlock(&path.dentry->d_inode->i_mutex); | ||
928 | path_put(&path); | ||
929 | out_mknod_parent: | ||
930 | if (err == -EEXIST) | ||
931 | err = -EADDRINUSE; | ||
932 | unix_release_addr(addr); | ||
933 | goto out_up; | ||
934 | } | 936 | } |
935 | 937 | ||
936 | static void unix_state_double_lock(struct sock *sk1, struct sock *sk2) | 938 | static void unix_state_double_lock(struct sock *sk1, struct sock *sk2) |
@@ -1448,7 +1450,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock, | |||
1448 | if (NULL == siocb->scm) | 1450 | if (NULL == siocb->scm) |
1449 | siocb->scm = &tmp_scm; | 1451 | siocb->scm = &tmp_scm; |
1450 | wait_for_unix_gc(); | 1452 | wait_for_unix_gc(); |
1451 | err = scm_send(sock, msg, siocb->scm); | 1453 | err = scm_send(sock, msg, siocb->scm, false); |
1452 | if (err < 0) | 1454 | if (err < 0) |
1453 | return err; | 1455 | return err; |
1454 | 1456 | ||
@@ -1617,7 +1619,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock, | |||
1617 | if (NULL == siocb->scm) | 1619 | if (NULL == siocb->scm) |
1618 | siocb->scm = &tmp_scm; | 1620 | siocb->scm = &tmp_scm; |
1619 | wait_for_unix_gc(); | 1621 | wait_for_unix_gc(); |
1620 | err = scm_send(sock, msg, siocb->scm); | 1622 | err = scm_send(sock, msg, siocb->scm, false); |
1621 | if (err < 0) | 1623 | if (err < 0) |
1622 | return err; | 1624 | return err; |
1623 | 1625 | ||
@@ -2239,47 +2241,54 @@ static unsigned int unix_dgram_poll(struct file *file, struct socket *sock, | |||
2239 | } | 2241 | } |
2240 | 2242 | ||
2241 | #ifdef CONFIG_PROC_FS | 2243 | #ifdef CONFIG_PROC_FS |
2242 | static struct sock *first_unix_socket(int *i) | 2244 | |
2245 | #define BUCKET_SPACE (BITS_PER_LONG - (UNIX_HASH_BITS + 1) - 1) | ||
2246 | |||
2247 | #define get_bucket(x) ((x) >> BUCKET_SPACE) | ||
2248 | #define get_offset(x) ((x) & ((1L << BUCKET_SPACE) - 1)) | ||
2249 | #define set_bucket_offset(b, o) ((b) << BUCKET_SPACE | (o)) | ||
2250 | |||
2251 | static struct sock *unix_from_bucket(struct seq_file *seq, loff_t *pos) | ||
2243 | { | 2252 | { |
2244 | for (*i = 0; *i <= UNIX_HASH_SIZE; (*i)++) { | 2253 | unsigned long offset = get_offset(*pos); |
2245 | if (!hlist_empty(&unix_socket_table[*i])) | 2254 | unsigned long bucket = get_bucket(*pos); |
2246 | return __sk_head(&unix_socket_table[*i]); | 2255 | struct sock *sk; |
2256 | unsigned long count = 0; | ||
2257 | |||
2258 | for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) { | ||
2259 | if (sock_net(sk) != seq_file_net(seq)) | ||
2260 | continue; | ||
2261 | if (++count == offset) | ||
2262 | break; | ||
2247 | } | 2263 | } |
2248 | return NULL; | 2264 | |
2265 | return sk; | ||
2249 | } | 2266 | } |
2250 | 2267 | ||
2251 | static struct sock *next_unix_socket(int *i, struct sock *s) | 2268 | static struct sock *unix_next_socket(struct seq_file *seq, |
2269 | struct sock *sk, | ||
2270 | loff_t *pos) | ||
2252 | { | 2271 | { |
2253 | struct sock *next = sk_next(s); | 2272 | unsigned long bucket; |
2254 | /* More in this chain? */ | 2273 | |
2255 | if (next) | 2274 | while (sk > (struct sock *)SEQ_START_TOKEN) { |
2256 | return next; | 2275 | sk = sk_next(sk); |
2257 | /* Look for next non-empty chain. */ | 2276 | if (!sk) |
2258 | for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) { | 2277 | goto next_bucket; |
2259 | if (!hlist_empty(&unix_socket_table[*i])) | 2278 | if (sock_net(sk) == seq_file_net(seq)) |
2260 | return __sk_head(&unix_socket_table[*i]); | 2279 | return sk; |
2261 | } | 2280 | } |
2262 | return NULL; | ||
2263 | } | ||
2264 | 2281 | ||
2265 | struct unix_iter_state { | 2282 | do { |
2266 | struct seq_net_private p; | 2283 | sk = unix_from_bucket(seq, pos); |
2267 | int i; | 2284 | if (sk) |
2268 | }; | 2285 | return sk; |
2269 | 2286 | ||
2270 | static struct sock *unix_seq_idx(struct seq_file *seq, loff_t pos) | 2287 | next_bucket: |
2271 | { | 2288 | bucket = get_bucket(*pos) + 1; |
2272 | struct unix_iter_state *iter = seq->private; | 2289 | *pos = set_bucket_offset(bucket, 1); |
2273 | loff_t off = 0; | 2290 | } while (bucket < ARRAY_SIZE(unix_socket_table)); |
2274 | struct sock *s; | ||
2275 | 2291 | ||
2276 | for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) { | ||
2277 | if (sock_net(s) != seq_file_net(seq)) | ||
2278 | continue; | ||
2279 | if (off == pos) | ||
2280 | return s; | ||
2281 | ++off; | ||
2282 | } | ||
2283 | return NULL; | 2292 | return NULL; |
2284 | } | 2293 | } |
2285 | 2294 | ||
@@ -2287,22 +2296,20 @@ static void *unix_seq_start(struct seq_file *seq, loff_t *pos) | |||
2287 | __acquires(unix_table_lock) | 2296 | __acquires(unix_table_lock) |
2288 | { | 2297 | { |
2289 | spin_lock(&unix_table_lock); | 2298 | spin_lock(&unix_table_lock); |
2290 | return *pos ? unix_seq_idx(seq, *pos - 1) : SEQ_START_TOKEN; | 2299 | |
2300 | if (!*pos) | ||
2301 | return SEQ_START_TOKEN; | ||
2302 | |||
2303 | if (get_bucket(*pos) >= ARRAY_SIZE(unix_socket_table)) | ||
2304 | return NULL; | ||
2305 | |||
2306 | return unix_next_socket(seq, NULL, pos); | ||
2291 | } | 2307 | } |
2292 | 2308 | ||
2293 | static void *unix_seq_next(struct seq_file *seq, void *v, loff_t *pos) | 2309 | static void *unix_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
2294 | { | 2310 | { |
2295 | struct unix_iter_state *iter = seq->private; | ||
2296 | struct sock *sk = v; | ||
2297 | ++*pos; | 2311 | ++*pos; |
2298 | 2312 | return unix_next_socket(seq, v, pos); | |
2299 | if (v == SEQ_START_TOKEN) | ||
2300 | sk = first_unix_socket(&iter->i); | ||
2301 | else | ||
2302 | sk = next_unix_socket(&iter->i, sk); | ||
2303 | while (sk && (sock_net(sk) != seq_file_net(seq))) | ||
2304 | sk = next_unix_socket(&iter->i, sk); | ||
2305 | return sk; | ||
2306 | } | 2313 | } |
2307 | 2314 | ||
2308 | static void unix_seq_stop(struct seq_file *seq, void *v) | 2315 | static void unix_seq_stop(struct seq_file *seq, void *v) |
@@ -2365,7 +2372,7 @@ static const struct seq_operations unix_seq_ops = { | |||
2365 | static int unix_seq_open(struct inode *inode, struct file *file) | 2372 | static int unix_seq_open(struct inode *inode, struct file *file) |
2366 | { | 2373 | { |
2367 | return seq_open_net(inode, file, &unix_seq_ops, | 2374 | return seq_open_net(inode, file, &unix_seq_ops, |
2368 | sizeof(struct unix_iter_state)); | 2375 | sizeof(struct seq_net_private)); |
2369 | } | 2376 | } |
2370 | 2377 | ||
2371 | static const struct file_operations unix_seq_fops = { | 2378 | static const struct file_operations unix_seq_fops = { |
diff --git a/net/unix/diag.c b/net/unix/diag.c index 47d3002737f5..750b13408449 100644 --- a/net/unix/diag.c +++ b/net/unix/diag.c | |||
@@ -8,40 +8,31 @@ | |||
8 | #include <net/af_unix.h> | 8 | #include <net/af_unix.h> |
9 | #include <net/tcp_states.h> | 9 | #include <net/tcp_states.h> |
10 | 10 | ||
11 | #define UNIX_DIAG_PUT(skb, attrtype, attrlen) \ | ||
12 | RTA_DATA(__RTA_PUT(skb, attrtype, attrlen)) | ||
13 | |||
14 | static int sk_diag_dump_name(struct sock *sk, struct sk_buff *nlskb) | 11 | static int sk_diag_dump_name(struct sock *sk, struct sk_buff *nlskb) |
15 | { | 12 | { |
16 | struct unix_address *addr = unix_sk(sk)->addr; | 13 | struct unix_address *addr = unix_sk(sk)->addr; |
17 | char *s; | ||
18 | |||
19 | if (addr) { | ||
20 | s = UNIX_DIAG_PUT(nlskb, UNIX_DIAG_NAME, addr->len - sizeof(short)); | ||
21 | memcpy(s, addr->name->sun_path, addr->len - sizeof(short)); | ||
22 | } | ||
23 | 14 | ||
24 | return 0; | 15 | if (!addr) |
16 | return 0; | ||
25 | 17 | ||
26 | rtattr_failure: | 18 | return nla_put(nlskb, UNIX_DIAG_NAME, addr->len - sizeof(short), |
27 | return -EMSGSIZE; | 19 | addr->name->sun_path); |
28 | } | 20 | } |
29 | 21 | ||
30 | static int sk_diag_dump_vfs(struct sock *sk, struct sk_buff *nlskb) | 22 | static int sk_diag_dump_vfs(struct sock *sk, struct sk_buff *nlskb) |
31 | { | 23 | { |
32 | struct dentry *dentry = unix_sk(sk)->path.dentry; | 24 | struct dentry *dentry = unix_sk(sk)->path.dentry; |
33 | struct unix_diag_vfs *uv; | ||
34 | 25 | ||
35 | if (dentry) { | 26 | if (dentry) { |
36 | uv = UNIX_DIAG_PUT(nlskb, UNIX_DIAG_VFS, sizeof(*uv)); | 27 | struct unix_diag_vfs uv = { |
37 | uv->udiag_vfs_ino = dentry->d_inode->i_ino; | 28 | .udiag_vfs_ino = dentry->d_inode->i_ino, |
38 | uv->udiag_vfs_dev = dentry->d_sb->s_dev; | 29 | .udiag_vfs_dev = dentry->d_sb->s_dev, |
30 | }; | ||
31 | |||
32 | return nla_put(nlskb, UNIX_DIAG_VFS, sizeof(uv), &uv); | ||
39 | } | 33 | } |
40 | 34 | ||
41 | return 0; | 35 | return 0; |
42 | |||
43 | rtattr_failure: | ||
44 | return -EMSGSIZE; | ||
45 | } | 36 | } |
46 | 37 | ||
47 | static int sk_diag_dump_peer(struct sock *sk, struct sk_buff *nlskb) | 38 | static int sk_diag_dump_peer(struct sock *sk, struct sk_buff *nlskb) |
@@ -56,24 +47,28 @@ static int sk_diag_dump_peer(struct sock *sk, struct sk_buff *nlskb) | |||
56 | unix_state_unlock(peer); | 47 | unix_state_unlock(peer); |
57 | sock_put(peer); | 48 | sock_put(peer); |
58 | 49 | ||
59 | RTA_PUT_U32(nlskb, UNIX_DIAG_PEER, ino); | 50 | return nla_put_u32(nlskb, UNIX_DIAG_PEER, ino); |
60 | } | 51 | } |
61 | 52 | ||
62 | return 0; | 53 | return 0; |
63 | rtattr_failure: | ||
64 | return -EMSGSIZE; | ||
65 | } | 54 | } |
66 | 55 | ||
67 | static int sk_diag_dump_icons(struct sock *sk, struct sk_buff *nlskb) | 56 | static int sk_diag_dump_icons(struct sock *sk, struct sk_buff *nlskb) |
68 | { | 57 | { |
69 | struct sk_buff *skb; | 58 | struct sk_buff *skb; |
59 | struct nlattr *attr; | ||
70 | u32 *buf; | 60 | u32 *buf; |
71 | int i; | 61 | int i; |
72 | 62 | ||
73 | if (sk->sk_state == TCP_LISTEN) { | 63 | if (sk->sk_state == TCP_LISTEN) { |
74 | spin_lock(&sk->sk_receive_queue.lock); | 64 | spin_lock(&sk->sk_receive_queue.lock); |
75 | buf = UNIX_DIAG_PUT(nlskb, UNIX_DIAG_ICONS, | 65 | |
76 | sk->sk_receive_queue.qlen * sizeof(u32)); | 66 | attr = nla_reserve(nlskb, UNIX_DIAG_ICONS, |
67 | sk->sk_receive_queue.qlen * sizeof(u32)); | ||
68 | if (!attr) | ||
69 | goto errout; | ||
70 | |||
71 | buf = nla_data(attr); | ||
77 | i = 0; | 72 | i = 0; |
78 | skb_queue_walk(&sk->sk_receive_queue, skb) { | 73 | skb_queue_walk(&sk->sk_receive_queue, skb) { |
79 | struct sock *req, *peer; | 74 | struct sock *req, *peer; |
@@ -94,43 +89,38 @@ static int sk_diag_dump_icons(struct sock *sk, struct sk_buff *nlskb) | |||
94 | 89 | ||
95 | return 0; | 90 | return 0; |
96 | 91 | ||
97 | rtattr_failure: | 92 | errout: |
98 | spin_unlock(&sk->sk_receive_queue.lock); | 93 | spin_unlock(&sk->sk_receive_queue.lock); |
99 | return -EMSGSIZE; | 94 | return -EMSGSIZE; |
100 | } | 95 | } |
101 | 96 | ||
102 | static int sk_diag_show_rqlen(struct sock *sk, struct sk_buff *nlskb) | 97 | static int sk_diag_show_rqlen(struct sock *sk, struct sk_buff *nlskb) |
103 | { | 98 | { |
104 | struct unix_diag_rqlen *rql; | 99 | struct unix_diag_rqlen rql; |
105 | |||
106 | rql = UNIX_DIAG_PUT(nlskb, UNIX_DIAG_RQLEN, sizeof(*rql)); | ||
107 | 100 | ||
108 | if (sk->sk_state == TCP_LISTEN) { | 101 | if (sk->sk_state == TCP_LISTEN) { |
109 | rql->udiag_rqueue = sk->sk_receive_queue.qlen; | 102 | rql.udiag_rqueue = sk->sk_receive_queue.qlen; |
110 | rql->udiag_wqueue = sk->sk_max_ack_backlog; | 103 | rql.udiag_wqueue = sk->sk_max_ack_backlog; |
111 | } else { | 104 | } else { |
112 | rql->udiag_rqueue = (__u32)unix_inq_len(sk); | 105 | rql.udiag_rqueue = (u32) unix_inq_len(sk); |
113 | rql->udiag_wqueue = (__u32)unix_outq_len(sk); | 106 | rql.udiag_wqueue = (u32) unix_outq_len(sk); |
114 | } | 107 | } |
115 | 108 | ||
116 | return 0; | 109 | return nla_put(nlskb, UNIX_DIAG_RQLEN, sizeof(rql), &rql); |
117 | |||
118 | rtattr_failure: | ||
119 | return -EMSGSIZE; | ||
120 | } | 110 | } |
121 | 111 | ||
122 | static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct unix_diag_req *req, | 112 | static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct unix_diag_req *req, |
123 | u32 pid, u32 seq, u32 flags, int sk_ino) | 113 | u32 pid, u32 seq, u32 flags, int sk_ino) |
124 | { | 114 | { |
125 | unsigned char *b = skb_tail_pointer(skb); | ||
126 | struct nlmsghdr *nlh; | 115 | struct nlmsghdr *nlh; |
127 | struct unix_diag_msg *rep; | 116 | struct unix_diag_msg *rep; |
128 | 117 | ||
129 | nlh = NLMSG_PUT(skb, pid, seq, SOCK_DIAG_BY_FAMILY, sizeof(*rep)); | 118 | nlh = nlmsg_put(skb, pid, seq, SOCK_DIAG_BY_FAMILY, sizeof(*rep), |
130 | nlh->nlmsg_flags = flags; | 119 | flags); |
131 | 120 | if (!nlh) | |
132 | rep = NLMSG_DATA(nlh); | 121 | return -EMSGSIZE; |
133 | 122 | ||
123 | rep = nlmsg_data(nlh); | ||
134 | rep->udiag_family = AF_UNIX; | 124 | rep->udiag_family = AF_UNIX; |
135 | rep->udiag_type = sk->sk_type; | 125 | rep->udiag_type = sk->sk_type; |
136 | rep->udiag_state = sk->sk_state; | 126 | rep->udiag_state = sk->sk_state; |
@@ -139,33 +129,32 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct unix_diag_r | |||
139 | 129 | ||
140 | if ((req->udiag_show & UDIAG_SHOW_NAME) && | 130 | if ((req->udiag_show & UDIAG_SHOW_NAME) && |
141 | sk_diag_dump_name(sk, skb)) | 131 | sk_diag_dump_name(sk, skb)) |
142 | goto nlmsg_failure; | 132 | goto out_nlmsg_trim; |
143 | 133 | ||
144 | if ((req->udiag_show & UDIAG_SHOW_VFS) && | 134 | if ((req->udiag_show & UDIAG_SHOW_VFS) && |
145 | sk_diag_dump_vfs(sk, skb)) | 135 | sk_diag_dump_vfs(sk, skb)) |
146 | goto nlmsg_failure; | 136 | goto out_nlmsg_trim; |
147 | 137 | ||
148 | if ((req->udiag_show & UDIAG_SHOW_PEER) && | 138 | if ((req->udiag_show & UDIAG_SHOW_PEER) && |
149 | sk_diag_dump_peer(sk, skb)) | 139 | sk_diag_dump_peer(sk, skb)) |
150 | goto nlmsg_failure; | 140 | goto out_nlmsg_trim; |
151 | 141 | ||
152 | if ((req->udiag_show & UDIAG_SHOW_ICONS) && | 142 | if ((req->udiag_show & UDIAG_SHOW_ICONS) && |
153 | sk_diag_dump_icons(sk, skb)) | 143 | sk_diag_dump_icons(sk, skb)) |
154 | goto nlmsg_failure; | 144 | goto out_nlmsg_trim; |
155 | 145 | ||
156 | if ((req->udiag_show & UDIAG_SHOW_RQLEN) && | 146 | if ((req->udiag_show & UDIAG_SHOW_RQLEN) && |
157 | sk_diag_show_rqlen(sk, skb)) | 147 | sk_diag_show_rqlen(sk, skb)) |
158 | goto nlmsg_failure; | 148 | goto out_nlmsg_trim; |
159 | 149 | ||
160 | if ((req->udiag_show & UDIAG_SHOW_MEMINFO) && | 150 | if ((req->udiag_show & UDIAG_SHOW_MEMINFO) && |
161 | sock_diag_put_meminfo(sk, skb, UNIX_DIAG_MEMINFO)) | 151 | sock_diag_put_meminfo(sk, skb, UNIX_DIAG_MEMINFO)) |
162 | goto nlmsg_failure; | 152 | goto out_nlmsg_trim; |
163 | 153 | ||
164 | nlh->nlmsg_len = skb_tail_pointer(skb) - b; | 154 | return nlmsg_end(skb, nlh); |
165 | return skb->len; | ||
166 | 155 | ||
167 | nlmsg_failure: | 156 | out_nlmsg_trim: |
168 | nlmsg_trim(skb, b); | 157 | nlmsg_cancel(skb, nlh); |
169 | return -EMSGSIZE; | 158 | return -EMSGSIZE; |
170 | } | 159 | } |
171 | 160 | ||
@@ -188,19 +177,24 @@ static int unix_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
188 | { | 177 | { |
189 | struct unix_diag_req *req; | 178 | struct unix_diag_req *req; |
190 | int num, s_num, slot, s_slot; | 179 | int num, s_num, slot, s_slot; |
180 | struct net *net = sock_net(skb->sk); | ||
191 | 181 | ||
192 | req = NLMSG_DATA(cb->nlh); | 182 | req = nlmsg_data(cb->nlh); |
193 | 183 | ||
194 | s_slot = cb->args[0]; | 184 | s_slot = cb->args[0]; |
195 | num = s_num = cb->args[1]; | 185 | num = s_num = cb->args[1]; |
196 | 186 | ||
197 | spin_lock(&unix_table_lock); | 187 | spin_lock(&unix_table_lock); |
198 | for (slot = s_slot; slot <= UNIX_HASH_SIZE; s_num = 0, slot++) { | 188 | for (slot = s_slot; |
189 | slot < ARRAY_SIZE(unix_socket_table); | ||
190 | s_num = 0, slot++) { | ||
199 | struct sock *sk; | 191 | struct sock *sk; |
200 | struct hlist_node *node; | 192 | struct hlist_node *node; |
201 | 193 | ||
202 | num = 0; | 194 | num = 0; |
203 | sk_for_each(sk, node, &unix_socket_table[slot]) { | 195 | sk_for_each(sk, node, &unix_socket_table[slot]) { |
196 | if (!net_eq(sock_net(sk), net)) | ||
197 | continue; | ||
204 | if (num < s_num) | 198 | if (num < s_num) |
205 | goto next; | 199 | goto next; |
206 | if (!(req->udiag_states & (1 << sk->sk_state))) | 200 | if (!(req->udiag_states & (1 << sk->sk_state))) |
@@ -228,7 +222,7 @@ static struct sock *unix_lookup_by_ino(int ino) | |||
228 | struct sock *sk; | 222 | struct sock *sk; |
229 | 223 | ||
230 | spin_lock(&unix_table_lock); | 224 | spin_lock(&unix_table_lock); |
231 | for (i = 0; i <= UNIX_HASH_SIZE; i++) { | 225 | for (i = 0; i < ARRAY_SIZE(unix_socket_table); i++) { |
232 | struct hlist_node *node; | 226 | struct hlist_node *node; |
233 | 227 | ||
234 | sk_for_each(sk, node, &unix_socket_table[i]) | 228 | sk_for_each(sk, node, &unix_socket_table[i]) |
@@ -252,6 +246,7 @@ static int unix_diag_get_exact(struct sk_buff *in_skb, | |||
252 | struct sock *sk; | 246 | struct sock *sk; |
253 | struct sk_buff *rep; | 247 | struct sk_buff *rep; |
254 | unsigned int extra_len; | 248 | unsigned int extra_len; |
249 | struct net *net = sock_net(in_skb->sk); | ||
255 | 250 | ||
256 | if (req->udiag_ino == 0) | 251 | if (req->udiag_ino == 0) |
257 | goto out_nosk; | 252 | goto out_nosk; |
@@ -268,22 +263,21 @@ static int unix_diag_get_exact(struct sk_buff *in_skb, | |||
268 | extra_len = 256; | 263 | extra_len = 256; |
269 | again: | 264 | again: |
270 | err = -ENOMEM; | 265 | err = -ENOMEM; |
271 | rep = alloc_skb(NLMSG_SPACE((sizeof(struct unix_diag_msg) + extra_len)), | 266 | rep = nlmsg_new(sizeof(struct unix_diag_msg) + extra_len, GFP_KERNEL); |
272 | GFP_KERNEL); | ||
273 | if (!rep) | 267 | if (!rep) |
274 | goto out; | 268 | goto out; |
275 | 269 | ||
276 | err = sk_diag_fill(sk, rep, req, NETLINK_CB(in_skb).pid, | 270 | err = sk_diag_fill(sk, rep, req, NETLINK_CB(in_skb).pid, |
277 | nlh->nlmsg_seq, 0, req->udiag_ino); | 271 | nlh->nlmsg_seq, 0, req->udiag_ino); |
278 | if (err < 0) { | 272 | if (err < 0) { |
279 | kfree_skb(rep); | 273 | nlmsg_free(rep); |
280 | extra_len += 256; | 274 | extra_len += 256; |
281 | if (extra_len >= PAGE_SIZE) | 275 | if (extra_len >= PAGE_SIZE) |
282 | goto out; | 276 | goto out; |
283 | 277 | ||
284 | goto again; | 278 | goto again; |
285 | } | 279 | } |
286 | err = netlink_unicast(sock_diag_nlsk, rep, NETLINK_CB(in_skb).pid, | 280 | err = netlink_unicast(net->diag_nlsk, rep, NETLINK_CB(in_skb).pid, |
287 | MSG_DONTWAIT); | 281 | MSG_DONTWAIT); |
288 | if (err > 0) | 282 | if (err > 0) |
289 | err = 0; | 283 | err = 0; |
@@ -297,6 +291,7 @@ out_nosk: | |||
297 | static int unix_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) | 291 | static int unix_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) |
298 | { | 292 | { |
299 | int hdrlen = sizeof(struct unix_diag_req); | 293 | int hdrlen = sizeof(struct unix_diag_req); |
294 | struct net *net = sock_net(skb->sk); | ||
300 | 295 | ||
301 | if (nlmsg_len(h) < hdrlen) | 296 | if (nlmsg_len(h) < hdrlen) |
302 | return -EINVAL; | 297 | return -EINVAL; |
@@ -305,9 +300,9 @@ static int unix_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) | |||
305 | struct netlink_dump_control c = { | 300 | struct netlink_dump_control c = { |
306 | .dump = unix_diag_dump, | 301 | .dump = unix_diag_dump, |
307 | }; | 302 | }; |
308 | return netlink_dump_start(sock_diag_nlsk, skb, h, &c); | 303 | return netlink_dump_start(net->diag_nlsk, skb, h, &c); |
309 | } else | 304 | } else |
310 | return unix_diag_get_exact(skb, h, (struct unix_diag_req *)NLMSG_DATA(h)); | 305 | return unix_diag_get_exact(skb, h, nlmsg_data(h)); |
311 | } | 306 | } |
312 | 307 | ||
313 | static const struct sock_diag_handler unix_diag_handler = { | 308 | static const struct sock_diag_handler unix_diag_handler = { |