aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix
diff options
context:
space:
mode:
Diffstat (limited to 'net/unix')
-rw-r--r--net/unix/af_unix.c197
-rw-r--r--net/unix/garbage.c12
-rw-r--r--net/unix/sysctl_net_unix.c3
3 files changed, 104 insertions, 108 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index eb90f77bb0e2..e1ca8f744ca5 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -164,7 +164,7 @@ static inline int unix_our_peer(struct sock *sk, struct sock *osk)
164 164
165static inline int unix_may_send(struct sock *sk, struct sock *osk) 165static inline int unix_may_send(struct sock *sk, struct sock *osk)
166{ 166{
167 return (unix_peer(osk) == NULL || unix_our_peer(sk, osk)); 167 return unix_peer(osk) == NULL || unix_our_peer(sk, osk);
168} 168}
169 169
170static inline int unix_recvq_full(struct sock const *sk) 170static inline int unix_recvq_full(struct sock const *sk)
@@ -197,7 +197,7 @@ static inline void unix_release_addr(struct unix_address *addr)
197 * - if started by zero, it is abstract name. 197 * - if started by zero, it is abstract name.
198 */ 198 */
199 199
200static int unix_mkname(struct sockaddr_un * sunaddr, int len, unsigned *hashp) 200static int unix_mkname(struct sockaddr_un *sunaddr, int len, unsigned *hashp)
201{ 201{
202 if (len <= sizeof(short) || len > sizeof(*sunaddr)) 202 if (len <= sizeof(short) || len > sizeof(*sunaddr))
203 return -EINVAL; 203 return -EINVAL;
@@ -211,12 +211,12 @@ static int unix_mkname(struct sockaddr_un * sunaddr, int len, unsigned *hashp)
211 * we are guaranteed that it is a valid memory location in our 211 * we are guaranteed that it is a valid memory location in our
212 * kernel address buffer. 212 * kernel address buffer.
213 */ 213 */
214 ((char *)sunaddr)[len]=0; 214 ((char *)sunaddr)[len] = 0;
215 len = strlen(sunaddr->sun_path)+1+sizeof(short); 215 len = strlen(sunaddr->sun_path)+1+sizeof(short);
216 return len; 216 return len;
217 } 217 }
218 218
219 *hashp = unix_hash_fold(csum_partial((char*)sunaddr, len, 0)); 219 *hashp = unix_hash_fold(csum_partial(sunaddr, len, 0));
220 return len; 220 return len;
221} 221}
222 222
@@ -295,8 +295,7 @@ static struct sock *unix_find_socket_byinode(struct net *net, struct inode *i)
295 if (!net_eq(sock_net(s), net)) 295 if (!net_eq(sock_net(s), net))
296 continue; 296 continue;
297 297
298 if(dentry && dentry->d_inode == i) 298 if (dentry && dentry->d_inode == i) {
299 {
300 sock_hold(s); 299 sock_hold(s);
301 goto found; 300 goto found;
302 } 301 }
@@ -354,7 +353,7 @@ static void unix_sock_destructor(struct sock *sk)
354 WARN_ON(!sk_unhashed(sk)); 353 WARN_ON(!sk_unhashed(sk));
355 WARN_ON(sk->sk_socket); 354 WARN_ON(sk->sk_socket);
356 if (!sock_flag(sk, SOCK_DEAD)) { 355 if (!sock_flag(sk, SOCK_DEAD)) {
357 printk("Attempt to release alive unix socket: %p\n", sk); 356 printk(KERN_INFO "Attempt to release alive unix socket: %p\n", sk);
358 return; 357 return;
359 } 358 }
360 359
@@ -362,12 +361,14 @@ static void unix_sock_destructor(struct sock *sk)
362 unix_release_addr(u->addr); 361 unix_release_addr(u->addr);
363 362
364 atomic_dec(&unix_nr_socks); 363 atomic_dec(&unix_nr_socks);
364 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
365#ifdef UNIX_REFCNT_DEBUG 365#ifdef UNIX_REFCNT_DEBUG
366 printk(KERN_DEBUG "UNIX %p is destroyed, %d are still alive.\n", sk, atomic_read(&unix_nr_socks)); 366 printk(KERN_DEBUG "UNIX %p is destroyed, %d are still alive.\n", sk,
367 atomic_read(&unix_nr_socks));
367#endif 368#endif
368} 369}
369 370
370static int unix_release_sock (struct sock *sk, int embrion) 371static int unix_release_sock(struct sock *sk, int embrion)
371{ 372{
372 struct unix_sock *u = unix_sk(sk); 373 struct unix_sock *u = unix_sk(sk);
373 struct dentry *dentry; 374 struct dentry *dentry;
@@ -392,9 +393,9 @@ static int unix_release_sock (struct sock *sk, int embrion)
392 393
393 wake_up_interruptible_all(&u->peer_wait); 394 wake_up_interruptible_all(&u->peer_wait);
394 395
395 skpair=unix_peer(sk); 396 skpair = unix_peer(sk);
396 397
397 if (skpair!=NULL) { 398 if (skpair != NULL) {
398 if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) { 399 if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) {
399 unix_state_lock(skpair); 400 unix_state_lock(skpair);
400 /* No more writes */ 401 /* No more writes */
@@ -414,7 +415,7 @@ static int unix_release_sock (struct sock *sk, int embrion)
414 /* Try to flush out this socket. Throw out buffers at least */ 415 /* Try to flush out this socket. Throw out buffers at least */
415 416
416 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) { 417 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
417 if (state==TCP_LISTEN) 418 if (state == TCP_LISTEN)
418 unix_release_sock(skb->sk, 1); 419 unix_release_sock(skb->sk, 1);
419 /* passed fds are erased in the kfree_skb hook */ 420 /* passed fds are erased in the kfree_skb hook */
420 kfree_skb(skb); 421 kfree_skb(skb);
@@ -453,11 +454,11 @@ static int unix_listen(struct socket *sock, int backlog)
453 struct unix_sock *u = unix_sk(sk); 454 struct unix_sock *u = unix_sk(sk);
454 455
455 err = -EOPNOTSUPP; 456 err = -EOPNOTSUPP;
456 if (sock->type!=SOCK_STREAM && sock->type!=SOCK_SEQPACKET) 457 if (sock->type != SOCK_STREAM && sock->type != SOCK_SEQPACKET)
457 goto out; /* Only stream/seqpacket sockets accept */ 458 goto out; /* Only stream/seqpacket sockets accept */
458 err = -EINVAL; 459 err = -EINVAL;
459 if (!u->addr) 460 if (!u->addr)
460 goto out; /* No listens on an unbound socket */ 461 goto out; /* No listens on an unbound socket */
461 unix_state_lock(sk); 462 unix_state_lock(sk);
462 if (sk->sk_state != TCP_CLOSE && sk->sk_state != TCP_LISTEN) 463 if (sk->sk_state != TCP_CLOSE && sk->sk_state != TCP_LISTEN)
463 goto out_unlock; 464 goto out_unlock;
@@ -566,9 +567,10 @@ static const struct proto_ops unix_seqpacket_ops = {
566}; 567};
567 568
568static struct proto unix_proto = { 569static struct proto unix_proto = {
569 .name = "UNIX", 570 .name = "UNIX",
570 .owner = THIS_MODULE, 571 .owner = THIS_MODULE,
571 .obj_size = sizeof(struct unix_sock), 572 .sockets_allocated = &unix_nr_socks,
573 .obj_size = sizeof(struct unix_sock),
572}; 574};
573 575
574/* 576/*
@@ -579,7 +581,7 @@ static struct proto unix_proto = {
579 */ 581 */
580static struct lock_class_key af_unix_sk_receive_queue_lock_key; 582static struct lock_class_key af_unix_sk_receive_queue_lock_key;
581 583
582static struct sock * unix_create1(struct net *net, struct socket *sock) 584static struct sock *unix_create1(struct net *net, struct socket *sock)
583{ 585{
584 struct sock *sk = NULL; 586 struct sock *sk = NULL;
585 struct unix_sock *u; 587 struct unix_sock *u;
@@ -592,7 +594,7 @@ static struct sock * unix_create1(struct net *net, struct socket *sock)
592 if (!sk) 594 if (!sk)
593 goto out; 595 goto out;
594 596
595 sock_init_data(sock,sk); 597 sock_init_data(sock, sk);
596 lockdep_set_class(&sk->sk_receive_queue.lock, 598 lockdep_set_class(&sk->sk_receive_queue.lock,
597 &af_unix_sk_receive_queue_lock_key); 599 &af_unix_sk_receive_queue_lock_key);
598 600
@@ -611,6 +613,9 @@ static struct sock * unix_create1(struct net *net, struct socket *sock)
611out: 613out:
612 if (sk == NULL) 614 if (sk == NULL)
613 atomic_dec(&unix_nr_socks); 615 atomic_dec(&unix_nr_socks);
616 else
617 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
618
614 return sk; 619 return sk;
615} 620}
616 621
@@ -630,7 +635,7 @@ static int unix_create(struct net *net, struct socket *sock, int protocol)
630 * nothing uses it. 635 * nothing uses it.
631 */ 636 */
632 case SOCK_RAW: 637 case SOCK_RAW:
633 sock->type=SOCK_DGRAM; 638 sock->type = SOCK_DGRAM;
634 case SOCK_DGRAM: 639 case SOCK_DGRAM:
635 sock->ops = &unix_dgram_ops; 640 sock->ops = &unix_dgram_ops;
636 break; 641 break;
@@ -653,7 +658,7 @@ static int unix_release(struct socket *sock)
653 658
654 sock->sk = NULL; 659 sock->sk = NULL;
655 660
656 return unix_release_sock (sk, 0); 661 return unix_release_sock(sk, 0);
657} 662}
658 663
659static int unix_autobind(struct socket *sock) 664static int unix_autobind(struct socket *sock)
@@ -662,7 +667,7 @@ static int unix_autobind(struct socket *sock)
662 struct net *net = sock_net(sk); 667 struct net *net = sock_net(sk);
663 struct unix_sock *u = unix_sk(sk); 668 struct unix_sock *u = unix_sk(sk);
664 static u32 ordernum = 1; 669 static u32 ordernum = 1;
665 struct unix_address * addr; 670 struct unix_address *addr;
666 int err; 671 int err;
667 672
668 mutex_lock(&u->readlock); 673 mutex_lock(&u->readlock);
@@ -681,7 +686,7 @@ static int unix_autobind(struct socket *sock)
681 686
682retry: 687retry:
683 addr->len = sprintf(addr->name->sun_path+1, "%05x", ordernum) + 1 + sizeof(short); 688 addr->len = sprintf(addr->name->sun_path+1, "%05x", ordernum) + 1 + sizeof(short);
684 addr->hash = unix_hash_fold(csum_partial((void*)addr->name, addr->len, 0)); 689 addr->hash = unix_hash_fold(csum_partial(addr->name, addr->len, 0));
685 690
686 spin_lock(&unix_table_lock); 691 spin_lock(&unix_table_lock);
687 ordernum = (ordernum+1)&0xFFFFF; 692 ordernum = (ordernum+1)&0xFFFFF;
@@ -736,14 +741,14 @@ static struct sock *unix_find_other(struct net *net,
736 741
737 path_put(&path); 742 path_put(&path);
738 743
739 err=-EPROTOTYPE; 744 err = -EPROTOTYPE;
740 if (u->sk_type != type) { 745 if (u->sk_type != type) {
741 sock_put(u); 746 sock_put(u);
742 goto fail; 747 goto fail;
743 } 748 }
744 } else { 749 } else {
745 err = -ECONNREFUSED; 750 err = -ECONNREFUSED;
746 u=unix_find_socket_byname(net, sunname, len, type, hash); 751 u = unix_find_socket_byname(net, sunname, len, type, hash);
747 if (u) { 752 if (u) {
748 struct dentry *dentry; 753 struct dentry *dentry;
749 dentry = unix_sk(u)->dentry; 754 dentry = unix_sk(u)->dentry;
@@ -757,7 +762,7 @@ static struct sock *unix_find_other(struct net *net,
757put_fail: 762put_fail:
758 path_put(&path); 763 path_put(&path);
759fail: 764fail:
760 *error=err; 765 *error = err;
761 return NULL; 766 return NULL;
762} 767}
763 768
@@ -767,8 +772,8 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
767 struct sock *sk = sock->sk; 772 struct sock *sk = sock->sk;
768 struct net *net = sock_net(sk); 773 struct net *net = sock_net(sk);
769 struct unix_sock *u = unix_sk(sk); 774 struct unix_sock *u = unix_sk(sk);
770 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; 775 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
771 struct dentry * dentry = NULL; 776 struct dentry *dentry = NULL;
772 struct nameidata nd; 777 struct nameidata nd;
773 int err; 778 int err;
774 unsigned hash; 779 unsigned hash;
@@ -779,7 +784,7 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
779 if (sunaddr->sun_family != AF_UNIX) 784 if (sunaddr->sun_family != AF_UNIX)
780 goto out; 785 goto out;
781 786
782 if (addr_len==sizeof(short)) { 787 if (addr_len == sizeof(short)) {
783 err = unix_autobind(sock); 788 err = unix_autobind(sock);
784 goto out; 789 goto out;
785 } 790 }
@@ -875,8 +880,8 @@ out_mknod_unlock:
875 mutex_unlock(&nd.path.dentry->d_inode->i_mutex); 880 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
876 path_put(&nd.path); 881 path_put(&nd.path);
877out_mknod_parent: 882out_mknod_parent:
878 if (err==-EEXIST) 883 if (err == -EEXIST)
879 err=-EADDRINUSE; 884 err = -EADDRINUSE;
880 unix_release_addr(addr); 885 unix_release_addr(addr);
881 goto out_up; 886 goto out_up;
882} 887}
@@ -911,7 +916,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
911{ 916{
912 struct sock *sk = sock->sk; 917 struct sock *sk = sock->sk;
913 struct net *net = sock_net(sk); 918 struct net *net = sock_net(sk);
914 struct sockaddr_un *sunaddr=(struct sockaddr_un*)addr; 919 struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr;
915 struct sock *other; 920 struct sock *other;
916 unsigned hash; 921 unsigned hash;
917 int err; 922 int err;
@@ -927,7 +932,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
927 goto out; 932 goto out;
928 933
929restart: 934restart:
930 other=unix_find_other(net, sunaddr, alen, sock->type, hash, &err); 935 other = unix_find_other(net, sunaddr, alen, sock->type, hash, &err);
931 if (!other) 936 if (!other)
932 goto out; 937 goto out;
933 938
@@ -961,14 +966,14 @@ restart:
961 */ 966 */
962 if (unix_peer(sk)) { 967 if (unix_peer(sk)) {
963 struct sock *old_peer = unix_peer(sk); 968 struct sock *old_peer = unix_peer(sk);
964 unix_peer(sk)=other; 969 unix_peer(sk) = other;
965 unix_state_double_unlock(sk, other); 970 unix_state_double_unlock(sk, other);
966 971
967 if (other != old_peer) 972 if (other != old_peer)
968 unix_dgram_disconnected(sk, old_peer); 973 unix_dgram_disconnected(sk, old_peer);
969 sock_put(old_peer); 974 sock_put(old_peer);
970 } else { 975 } else {
971 unix_peer(sk)=other; 976 unix_peer(sk) = other;
972 unix_state_double_unlock(sk, other); 977 unix_state_double_unlock(sk, other);
973 } 978 }
974 return 0; 979 return 0;
@@ -1004,7 +1009,7 @@ static long unix_wait_for_peer(struct sock *other, long timeo)
1004static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, 1009static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
1005 int addr_len, int flags) 1010 int addr_len, int flags)
1006{ 1011{
1007 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; 1012 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
1008 struct sock *sk = sock->sk; 1013 struct sock *sk = sock->sk;
1009 struct net *net = sock_net(sk); 1014 struct net *net = sock_net(sk);
1010 struct unix_sock *u = unix_sk(sk), *newu, *otheru; 1015 struct unix_sock *u = unix_sk(sk), *newu, *otheru;
@@ -1179,13 +1184,13 @@ out:
1179 1184
1180static int unix_socketpair(struct socket *socka, struct socket *sockb) 1185static int unix_socketpair(struct socket *socka, struct socket *sockb)
1181{ 1186{
1182 struct sock *ska=socka->sk, *skb = sockb->sk; 1187 struct sock *ska = socka->sk, *skb = sockb->sk;
1183 1188
1184 /* Join our sockets back to back */ 1189 /* Join our sockets back to back */
1185 sock_hold(ska); 1190 sock_hold(ska);
1186 sock_hold(skb); 1191 sock_hold(skb);
1187 unix_peer(ska)=skb; 1192 unix_peer(ska) = skb;
1188 unix_peer(skb)=ska; 1193 unix_peer(skb) = ska;
1189 ska->sk_peercred.pid = skb->sk_peercred.pid = task_tgid_vnr(current); 1194 ska->sk_peercred.pid = skb->sk_peercred.pid = task_tgid_vnr(current);
1190 ska->sk_peercred.uid = skb->sk_peercred.uid = current->euid; 1195 ska->sk_peercred.uid = skb->sk_peercred.uid = current->euid;
1191 ska->sk_peercred.gid = skb->sk_peercred.gid = current->egid; 1196 ska->sk_peercred.gid = skb->sk_peercred.gid = current->egid;
@@ -1207,7 +1212,7 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags)
1207 int err; 1212 int err;
1208 1213
1209 err = -EOPNOTSUPP; 1214 err = -EOPNOTSUPP;
1210 if (sock->type!=SOCK_STREAM && sock->type!=SOCK_SEQPACKET) 1215 if (sock->type != SOCK_STREAM && sock->type != SOCK_SEQPACKET)
1211 goto out; 1216 goto out;
1212 1217
1213 err = -EINVAL; 1218 err = -EINVAL;
@@ -1246,7 +1251,7 @@ static int unix_getname(struct socket *sock, struct sockaddr *uaddr, int *uaddr_
1246{ 1251{
1247 struct sock *sk = sock->sk; 1252 struct sock *sk = sock->sk;
1248 struct unix_sock *u; 1253 struct unix_sock *u;
1249 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; 1254 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
1250 int err = 0; 1255 int err = 0;
1251 1256
1252 if (peer) { 1257 if (peer) {
@@ -1286,7 +1291,7 @@ static void unix_detach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1286 skb->destructor = sock_wfree; 1291 skb->destructor = sock_wfree;
1287 UNIXCB(skb).fp = NULL; 1292 UNIXCB(skb).fp = NULL;
1288 1293
1289 for (i=scm->fp->count-1; i>=0; i--) 1294 for (i = scm->fp->count-1; i >= 0; i--)
1290 unix_notinflight(scm->fp->fp[i]); 1295 unix_notinflight(scm->fp->fp[i]);
1291} 1296}
1292 1297
@@ -1315,7 +1320,7 @@ static int unix_attach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1315 if (!UNIXCB(skb).fp) 1320 if (!UNIXCB(skb).fp)
1316 return -ENOMEM; 1321 return -ENOMEM;
1317 1322
1318 for (i=scm->fp->count-1; i>=0; i--) 1323 for (i = scm->fp->count-1; i >= 0; i--)
1319 unix_inflight(scm->fp->fp[i]); 1324 unix_inflight(scm->fp->fp[i]);
1320 skb->destructor = unix_destruct_fds; 1325 skb->destructor = unix_destruct_fds;
1321 return 0; 1326 return 0;
@@ -1332,7 +1337,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1332 struct sock *sk = sock->sk; 1337 struct sock *sk = sock->sk;
1333 struct net *net = sock_net(sk); 1338 struct net *net = sock_net(sk);
1334 struct unix_sock *u = unix_sk(sk); 1339 struct unix_sock *u = unix_sk(sk);
1335 struct sockaddr_un *sunaddr=msg->msg_name; 1340 struct sockaddr_un *sunaddr = msg->msg_name;
1336 struct sock *other = NULL; 1341 struct sock *other = NULL;
1337 int namelen = 0; /* fake GCC */ 1342 int namelen = 0; /* fake GCC */
1338 int err; 1343 int err;
@@ -1373,7 +1378,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1373 goto out; 1378 goto out;
1374 1379
1375 skb = sock_alloc_send_skb(sk, len, msg->msg_flags&MSG_DONTWAIT, &err); 1380 skb = sock_alloc_send_skb(sk, len, msg->msg_flags&MSG_DONTWAIT, &err);
1376 if (skb==NULL) 1381 if (skb == NULL)
1377 goto out; 1382 goto out;
1378 1383
1379 memcpy(UNIXCREDS(skb), &siocb->scm->creds, sizeof(struct ucred)); 1384 memcpy(UNIXCREDS(skb), &siocb->scm->creds, sizeof(struct ucred));
@@ -1385,7 +1390,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1385 unix_get_secdata(siocb->scm, skb); 1390 unix_get_secdata(siocb->scm, skb);
1386 1391
1387 skb_reset_transport_header(skb); 1392 skb_reset_transport_header(skb);
1388 err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len); 1393 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
1389 if (err) 1394 if (err)
1390 goto out_free; 1395 goto out_free;
1391 1396
@@ -1399,7 +1404,7 @@ restart:
1399 1404
1400 other = unix_find_other(net, sunaddr, namelen, sk->sk_type, 1405 other = unix_find_other(net, sunaddr, namelen, sk->sk_type,
1401 hash, &err); 1406 hash, &err);
1402 if (other==NULL) 1407 if (other == NULL)
1403 goto out_free; 1408 goto out_free;
1404 } 1409 }
1405 1410
@@ -1419,7 +1424,7 @@ restart:
1419 err = 0; 1424 err = 0;
1420 unix_state_lock(sk); 1425 unix_state_lock(sk);
1421 if (unix_peer(sk) == other) { 1426 if (unix_peer(sk) == other) {
1422 unix_peer(sk)=NULL; 1427 unix_peer(sk) = NULL;
1423 unix_state_unlock(sk); 1428 unix_state_unlock(sk);
1424 1429
1425 unix_dgram_disconnected(sk, other); 1430 unix_dgram_disconnected(sk, other);
@@ -1485,10 +1490,10 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1485 struct sock_iocb *siocb = kiocb_to_siocb(kiocb); 1490 struct sock_iocb *siocb = kiocb_to_siocb(kiocb);
1486 struct sock *sk = sock->sk; 1491 struct sock *sk = sock->sk;
1487 struct sock *other = NULL; 1492 struct sock *other = NULL;
1488 struct sockaddr_un *sunaddr=msg->msg_name; 1493 struct sockaddr_un *sunaddr = msg->msg_name;
1489 int err,size; 1494 int err, size;
1490 struct sk_buff *skb; 1495 struct sk_buff *skb;
1491 int sent=0; 1496 int sent = 0;
1492 struct scm_cookie tmp_scm; 1497 struct scm_cookie tmp_scm;
1493 1498
1494 if (NULL == siocb->scm) 1499 if (NULL == siocb->scm)
@@ -1515,8 +1520,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1515 if (sk->sk_shutdown & SEND_SHUTDOWN) 1520 if (sk->sk_shutdown & SEND_SHUTDOWN)
1516 goto pipe_err; 1521 goto pipe_err;
1517 1522
1518 while(sent < len) 1523 while (sent < len) {
1519 {
1520 /* 1524 /*
1521 * Optimisation for the fact that under 0.01% of X 1525 * Optimisation for the fact that under 0.01% of X
1522 * messages typically need breaking up. 1526 * messages typically need breaking up.
@@ -1535,9 +1539,10 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1535 * Grab a buffer 1539 * Grab a buffer
1536 */ 1540 */
1537 1541
1538 skb=sock_alloc_send_skb(sk,size,msg->msg_flags&MSG_DONTWAIT, &err); 1542 skb = sock_alloc_send_skb(sk, size, msg->msg_flags&MSG_DONTWAIT,
1543 &err);
1539 1544
1540 if (skb==NULL) 1545 if (skb == NULL)
1541 goto out_err; 1546 goto out_err;
1542 1547
1543 /* 1548 /*
@@ -1558,7 +1563,8 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1558 } 1563 }
1559 } 1564 }
1560 1565
1561 if ((err = memcpy_fromiovec(skb_put(skb,size), msg->msg_iov, size)) != 0) { 1566 err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size);
1567 if (err) {
1562 kfree_skb(skb); 1568 kfree_skb(skb);
1563 goto out_err; 1569 goto out_err;
1564 } 1570 }
@@ -1572,7 +1578,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1572 skb_queue_tail(&other->sk_receive_queue, skb); 1578 skb_queue_tail(&other->sk_receive_queue, skb);
1573 unix_state_unlock(other); 1579 unix_state_unlock(other);
1574 other->sk_data_ready(other, size); 1580 other->sk_data_ready(other, size);
1575 sent+=size; 1581 sent += size;
1576 } 1582 }
1577 1583
1578 scm_destroy(siocb->scm); 1584 scm_destroy(siocb->scm);
@@ -1584,8 +1590,8 @@ pipe_err_free:
1584 unix_state_unlock(other); 1590 unix_state_unlock(other);
1585 kfree_skb(skb); 1591 kfree_skb(skb);
1586pipe_err: 1592pipe_err:
1587 if (sent==0 && !(msg->msg_flags&MSG_NOSIGNAL)) 1593 if (sent == 0 && !(msg->msg_flags&MSG_NOSIGNAL))
1588 send_sig(SIGPIPE,current,0); 1594 send_sig(SIGPIPE, current, 0);
1589 err = -EPIPE; 1595 err = -EPIPE;
1590out_err: 1596out_err:
1591 scm_destroy(siocb->scm); 1597 scm_destroy(siocb->scm);
@@ -1675,13 +1681,10 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1675 siocb->scm->creds = *UNIXCREDS(skb); 1681 siocb->scm->creds = *UNIXCREDS(skb);
1676 unix_set_secdata(siocb->scm, skb); 1682 unix_set_secdata(siocb->scm, skb);
1677 1683
1678 if (!(flags & MSG_PEEK)) 1684 if (!(flags & MSG_PEEK)) {
1679 {
1680 if (UNIXCB(skb).fp) 1685 if (UNIXCB(skb).fp)
1681 unix_detach_fds(siocb->scm, skb); 1686 unix_detach_fds(siocb->scm, skb);
1682 } 1687 } else {
1683 else
1684 {
1685 /* It is questionable: on PEEK we could: 1688 /* It is questionable: on PEEK we could:
1686 - do not return fds - good, but too simple 8) 1689 - do not return fds - good, but too simple 8)
1687 - return fds, and do not return them on read (old strategy, 1690 - return fds, and do not return them on read (old strategy,
@@ -1702,7 +1705,7 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1702 scm_recv(sock, msg, siocb->scm, flags); 1705 scm_recv(sock, msg, siocb->scm, flags);
1703 1706
1704out_free: 1707out_free:
1705 skb_free_datagram(sk,skb); 1708 skb_free_datagram(sk, skb);
1706out_unlock: 1709out_unlock:
1707 mutex_unlock(&u->readlock); 1710 mutex_unlock(&u->readlock);
1708out: 1711out:
@@ -1713,7 +1716,7 @@ out:
1713 * Sleep until data has arrive. But check for races.. 1716 * Sleep until data has arrive. But check for races..
1714 */ 1717 */
1715 1718
1716static long unix_stream_data_wait(struct sock * sk, long timeo) 1719static long unix_stream_data_wait(struct sock *sk, long timeo)
1717{ 1720{
1718 DEFINE_WAIT(wait); 1721 DEFINE_WAIT(wait);
1719 1722
@@ -1751,7 +1754,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1751 struct scm_cookie tmp_scm; 1754 struct scm_cookie tmp_scm;
1752 struct sock *sk = sock->sk; 1755 struct sock *sk = sock->sk;
1753 struct unix_sock *u = unix_sk(sk); 1756 struct unix_sock *u = unix_sk(sk);
1754 struct sockaddr_un *sunaddr=msg->msg_name; 1757 struct sockaddr_un *sunaddr = msg->msg_name;
1755 int copied = 0; 1758 int copied = 0;
1756 int check_creds = 0; 1759 int check_creds = 0;
1757 int target; 1760 int target;
@@ -1782,15 +1785,13 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1782 1785
1783 mutex_lock(&u->readlock); 1786 mutex_lock(&u->readlock);
1784 1787
1785 do 1788 do {
1786 {
1787 int chunk; 1789 int chunk;
1788 struct sk_buff *skb; 1790 struct sk_buff *skb;
1789 1791
1790 unix_state_lock(sk); 1792 unix_state_lock(sk);
1791 skb = skb_dequeue(&sk->sk_receive_queue); 1793 skb = skb_dequeue(&sk->sk_receive_queue);
1792 if (skb==NULL) 1794 if (skb == NULL) {
1793 {
1794 if (copied >= target) 1795 if (copied >= target)
1795 goto unlock; 1796 goto unlock;
1796 1797
@@ -1798,7 +1799,8 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1798 * POSIX 1003.1g mandates this order. 1799 * POSIX 1003.1g mandates this order.
1799 */ 1800 */
1800 1801
1801 if ((err = sock_error(sk)) != 0) 1802 err = sock_error(sk);
1803 if (err)
1802 goto unlock; 1804 goto unlock;
1803 if (sk->sk_shutdown & RCV_SHUTDOWN) 1805 if (sk->sk_shutdown & RCV_SHUTDOWN)
1804 goto unlock; 1806 goto unlock;
@@ -1825,7 +1827,8 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1825 1827
1826 if (check_creds) { 1828 if (check_creds) {
1827 /* Never glue messages from different writers */ 1829 /* Never glue messages from different writers */
1828 if (memcmp(UNIXCREDS(skb), &siocb->scm->creds, sizeof(siocb->scm->creds)) != 0) { 1830 if (memcmp(UNIXCREDS(skb), &siocb->scm->creds,
1831 sizeof(siocb->scm->creds)) != 0) {
1829 skb_queue_head(&sk->sk_receive_queue, skb); 1832 skb_queue_head(&sk->sk_receive_queue, skb);
1830 break; 1833 break;
1831 } 1834 }
@@ -1836,8 +1839,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1836 } 1839 }
1837 1840
1838 /* Copy address just once */ 1841 /* Copy address just once */
1839 if (sunaddr) 1842 if (sunaddr) {
1840 {
1841 unix_copy_addr(msg, skb->sk); 1843 unix_copy_addr(msg, skb->sk);
1842 sunaddr = NULL; 1844 sunaddr = NULL;
1843 } 1845 }
@@ -1853,16 +1855,14 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1853 size -= chunk; 1855 size -= chunk;
1854 1856
1855 /* Mark read part of skb as used */ 1857 /* Mark read part of skb as used */
1856 if (!(flags & MSG_PEEK)) 1858 if (!(flags & MSG_PEEK)) {
1857 {
1858 skb_pull(skb, chunk); 1859 skb_pull(skb, chunk);
1859 1860
1860 if (UNIXCB(skb).fp) 1861 if (UNIXCB(skb).fp)
1861 unix_detach_fds(siocb->scm, skb); 1862 unix_detach_fds(siocb->scm, skb);
1862 1863
1863 /* put the skb back if we didn't use it up.. */ 1864 /* put the skb back if we didn't use it up.. */
1864 if (skb->len) 1865 if (skb->len) {
1865 {
1866 skb_queue_head(&sk->sk_receive_queue, skb); 1866 skb_queue_head(&sk->sk_receive_queue, skb);
1867 break; 1867 break;
1868 } 1868 }
@@ -1871,9 +1871,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1871 1871
1872 if (siocb->scm->fp) 1872 if (siocb->scm->fp)
1873 break; 1873 break;
1874 } 1874 } else {
1875 else
1876 {
1877 /* It is questionable, see note in unix_dgram_recvmsg. 1875 /* It is questionable, see note in unix_dgram_recvmsg.
1878 */ 1876 */
1879 if (UNIXCB(skb).fp) 1877 if (UNIXCB(skb).fp)
@@ -1901,7 +1899,7 @@ static int unix_shutdown(struct socket *sock, int mode)
1901 if (mode) { 1899 if (mode) {
1902 unix_state_lock(sk); 1900 unix_state_lock(sk);
1903 sk->sk_shutdown |= mode; 1901 sk->sk_shutdown |= mode;
1904 other=unix_peer(sk); 1902 other = unix_peer(sk);
1905 if (other) 1903 if (other)
1906 sock_hold(other); 1904 sock_hold(other);
1907 unix_state_unlock(sk); 1905 unix_state_unlock(sk);
@@ -1936,16 +1934,15 @@ static int unix_shutdown(struct socket *sock, int mode)
1936static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 1934static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1937{ 1935{
1938 struct sock *sk = sock->sk; 1936 struct sock *sk = sock->sk;
1939 long amount=0; 1937 long amount = 0;
1940 int err; 1938 int err;
1941 1939
1942 switch(cmd) 1940 switch (cmd) {
1943 { 1941 case SIOCOUTQ:
1944 case SIOCOUTQ: 1942 amount = atomic_read(&sk->sk_wmem_alloc);
1945 amount = atomic_read(&sk->sk_wmem_alloc); 1943 err = put_user(amount, (int __user *)arg);
1946 err = put_user(amount, (int __user *)arg); 1944 break;
1947 break; 1945 case SIOCINQ:
1948 case SIOCINQ:
1949 { 1946 {
1950 struct sk_buff *skb; 1947 struct sk_buff *skb;
1951 1948
@@ -1962,21 +1959,21 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1962 } else { 1959 } else {
1963 skb = skb_peek(&sk->sk_receive_queue); 1960 skb = skb_peek(&sk->sk_receive_queue);
1964 if (skb) 1961 if (skb)
1965 amount=skb->len; 1962 amount = skb->len;
1966 } 1963 }
1967 spin_unlock(&sk->sk_receive_queue.lock); 1964 spin_unlock(&sk->sk_receive_queue.lock);
1968 err = put_user(amount, (int __user *)arg); 1965 err = put_user(amount, (int __user *)arg);
1969 break; 1966 break;
1970 } 1967 }
1971 1968
1972 default: 1969 default:
1973 err = -ENOIOCTLCMD; 1970 err = -ENOIOCTLCMD;
1974 break; 1971 break;
1975 } 1972 }
1976 return err; 1973 return err;
1977} 1974}
1978 1975
1979static unsigned int unix_poll(struct file * file, struct socket *sock, poll_table *wait) 1976static unsigned int unix_poll(struct file *file, struct socket *sock, poll_table *wait)
1980{ 1977{
1981 struct sock *sk = sock->sk; 1978 struct sock *sk = sock->sk;
1982 unsigned int mask; 1979 unsigned int mask;
@@ -1998,7 +1995,8 @@ static unsigned int unix_poll(struct file * file, struct socket *sock, poll_tabl
1998 mask |= POLLIN | POLLRDNORM; 1995 mask |= POLLIN | POLLRDNORM;
1999 1996
2000 /* Connection-based need to check for termination and startup */ 1997 /* Connection-based need to check for termination and startup */
2001 if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) && sk->sk_state == TCP_CLOSE) 1998 if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) &&
1999 sk->sk_state == TCP_CLOSE)
2002 mask |= POLLHUP; 2000 mask |= POLLHUP;
2003 2001
2004 /* 2002 /*
@@ -2094,6 +2092,7 @@ struct unix_iter_state {
2094 struct seq_net_private p; 2092 struct seq_net_private p;
2095 int i; 2093 int i;
2096}; 2094};
2095
2097static struct sock *unix_seq_idx(struct seq_file *seq, loff_t pos) 2096static struct sock *unix_seq_idx(struct seq_file *seq, loff_t pos)
2098{ 2097{
2099 struct unix_iter_state *iter = seq->private; 2098 struct unix_iter_state *iter = seq->private;
@@ -2110,7 +2109,6 @@ static struct sock *unix_seq_idx(struct seq_file *seq, loff_t pos)
2110 return NULL; 2109 return NULL;
2111} 2110}
2112 2111
2113
2114static void *unix_seq_start(struct seq_file *seq, loff_t *pos) 2112static void *unix_seq_start(struct seq_file *seq, loff_t *pos)
2115 __acquires(unix_table_lock) 2113 __acquires(unix_table_lock)
2116{ 2114{
@@ -2190,7 +2188,6 @@ static const struct seq_operations unix_seq_ops = {
2190 .show = unix_seq_show, 2188 .show = unix_seq_show,
2191}; 2189};
2192 2190
2193
2194static int unix_seq_open(struct inode *inode, struct file *file) 2191static int unix_seq_open(struct inode *inode, struct file *file)
2195{ 2192{
2196 return seq_open_net(inode, file, &unix_seq_ops, 2193 return seq_open_net(inode, file, &unix_seq_ops,
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index 6d4a9a8de5ef..5a0061d6b9bc 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -104,8 +104,8 @@ static struct sock *unix_get_socket(struct file *filp)
104 * Socket ? 104 * Socket ?
105 */ 105 */
106 if (S_ISSOCK(inode->i_mode)) { 106 if (S_ISSOCK(inode->i_mode)) {
107 struct socket * sock = SOCKET_I(inode); 107 struct socket *sock = SOCKET_I(inode);
108 struct sock * s = sock->sk; 108 struct sock *s = sock->sk;
109 109
110 /* 110 /*
111 * PF_UNIX ? 111 * PF_UNIX ?
@@ -124,7 +124,7 @@ static struct sock *unix_get_socket(struct file *filp)
124void unix_inflight(struct file *fp) 124void unix_inflight(struct file *fp)
125{ 125{
126 struct sock *s = unix_get_socket(fp); 126 struct sock *s = unix_get_socket(fp);
127 if(s) { 127 if (s) {
128 struct unix_sock *u = unix_sk(s); 128 struct unix_sock *u = unix_sk(s);
129 spin_lock(&unix_gc_lock); 129 spin_lock(&unix_gc_lock);
130 if (atomic_long_inc_return(&u->inflight) == 1) { 130 if (atomic_long_inc_return(&u->inflight) == 1) {
@@ -141,7 +141,7 @@ void unix_inflight(struct file *fp)
141void unix_notinflight(struct file *fp) 141void unix_notinflight(struct file *fp)
142{ 142{
143 struct sock *s = unix_get_socket(fp); 143 struct sock *s = unix_get_socket(fp);
144 if(s) { 144 if (s) {
145 struct unix_sock *u = unix_sk(s); 145 struct unix_sock *u = unix_sk(s);
146 spin_lock(&unix_gc_lock); 146 spin_lock(&unix_gc_lock);
147 BUG_ON(list_empty(&u->link)); 147 BUG_ON(list_empty(&u->link));
@@ -154,7 +154,7 @@ void unix_notinflight(struct file *fp)
154 154
155static inline struct sk_buff *sock_queue_head(struct sock *sk) 155static inline struct sk_buff *sock_queue_head(struct sock *sk)
156{ 156{
157 return (struct sk_buff *) &sk->sk_receive_queue; 157 return (struct sk_buff *)&sk->sk_receive_queue;
158} 158}
159 159
160#define receive_queue_for_each_skb(sk, next, skb) \ 160#define receive_queue_for_each_skb(sk, next, skb) \
@@ -364,7 +364,7 @@ void unix_gc(void)
364 */ 364 */
365 skb_queue_head_init(&hitlist); 365 skb_queue_head_init(&hitlist);
366 list_for_each_entry(u, &gc_candidates, link) 366 list_for_each_entry(u, &gc_candidates, link)
367 scan_children(&u->sk, inc_inflight, &hitlist); 367 scan_children(&u->sk, inc_inflight, &hitlist);
368 368
369 spin_unlock(&unix_gc_lock); 369 spin_unlock(&unix_gc_lock);
370 370
diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
index 77513d7e35f2..83c093077ebc 100644
--- a/net/unix/sysctl_net_unix.c
+++ b/net/unix/sysctl_net_unix.c
@@ -21,7 +21,7 @@ static ctl_table unix_table[] = {
21 .data = &init_net.unx.sysctl_max_dgram_qlen, 21 .data = &init_net.unx.sysctl_max_dgram_qlen,
22 .maxlen = sizeof(int), 22 .maxlen = sizeof(int),
23 .mode = 0644, 23 .mode = 0644,
24 .proc_handler = &proc_dointvec 24 .proc_handler = proc_dointvec
25 }, 25 },
26 { .ctl_name = 0 } 26 { .ctl_name = 0 }
27}; 27};
@@ -61,4 +61,3 @@ void unix_sysctl_unregister(struct net *net)
61 unregister_sysctl_table(net->unx.ctl); 61 unregister_sysctl_table(net->unx.ctl);
62 kfree(table); 62 kfree(table);
63} 63}
64