aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix
diff options
context:
space:
mode:
Diffstat (limited to 'net/unix')
-rw-r--r--net/unix/af_unix.c200
-rw-r--r--net/unix/garbage.c12
-rw-r--r--net/unix/sysctl_net_unix.c3
3 files changed, 107 insertions, 108 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index b152e2b9b988..c6250d0055d2 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,16 @@ 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 local_bh_disable();
365 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
366 local_bh_enable();
365#ifdef UNIX_REFCNT_DEBUG 367#ifdef UNIX_REFCNT_DEBUG
366 printk(KERN_DEBUG "UNIX %p is destroyed, %d are still alive.\n", sk, atomic_read(&unix_nr_socks)); 368 printk(KERN_DEBUG "UNIX %p is destroyed, %d are still alive.\n", sk,
369 atomic_read(&unix_nr_socks));
367#endif 370#endif
368} 371}
369 372
370static int unix_release_sock (struct sock *sk, int embrion) 373static int unix_release_sock(struct sock *sk, int embrion)
371{ 374{
372 struct unix_sock *u = unix_sk(sk); 375 struct unix_sock *u = unix_sk(sk);
373 struct dentry *dentry; 376 struct dentry *dentry;
@@ -392,9 +395,9 @@ static int unix_release_sock (struct sock *sk, int embrion)
392 395
393 wake_up_interruptible_all(&u->peer_wait); 396 wake_up_interruptible_all(&u->peer_wait);
394 397
395 skpair=unix_peer(sk); 398 skpair = unix_peer(sk);
396 399
397 if (skpair!=NULL) { 400 if (skpair != NULL) {
398 if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) { 401 if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) {
399 unix_state_lock(skpair); 402 unix_state_lock(skpair);
400 /* No more writes */ 403 /* No more writes */
@@ -414,7 +417,7 @@ static int unix_release_sock (struct sock *sk, int embrion)
414 /* Try to flush out this socket. Throw out buffers at least */ 417 /* Try to flush out this socket. Throw out buffers at least */
415 418
416 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) { 419 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
417 if (state==TCP_LISTEN) 420 if (state == TCP_LISTEN)
418 unix_release_sock(skb->sk, 1); 421 unix_release_sock(skb->sk, 1);
419 /* passed fds are erased in the kfree_skb hook */ 422 /* passed fds are erased in the kfree_skb hook */
420 kfree_skb(skb); 423 kfree_skb(skb);
@@ -453,11 +456,11 @@ static int unix_listen(struct socket *sock, int backlog)
453 struct unix_sock *u = unix_sk(sk); 456 struct unix_sock *u = unix_sk(sk);
454 457
455 err = -EOPNOTSUPP; 458 err = -EOPNOTSUPP;
456 if (sock->type!=SOCK_STREAM && sock->type!=SOCK_SEQPACKET) 459 if (sock->type != SOCK_STREAM && sock->type != SOCK_SEQPACKET)
457 goto out; /* Only stream/seqpacket sockets accept */ 460 goto out; /* Only stream/seqpacket sockets accept */
458 err = -EINVAL; 461 err = -EINVAL;
459 if (!u->addr) 462 if (!u->addr)
460 goto out; /* No listens on an unbound socket */ 463 goto out; /* No listens on an unbound socket */
461 unix_state_lock(sk); 464 unix_state_lock(sk);
462 if (sk->sk_state != TCP_CLOSE && sk->sk_state != TCP_LISTEN) 465 if (sk->sk_state != TCP_CLOSE && sk->sk_state != TCP_LISTEN)
463 goto out_unlock; 466 goto out_unlock;
@@ -565,9 +568,9 @@ static const struct proto_ops unix_seqpacket_ops = {
565}; 568};
566 569
567static struct proto unix_proto = { 570static struct proto unix_proto = {
568 .name = "UNIX", 571 .name = "UNIX",
569 .owner = THIS_MODULE, 572 .owner = THIS_MODULE,
570 .obj_size = sizeof(struct unix_sock), 573 .obj_size = sizeof(struct unix_sock),
571}; 574};
572 575
573/* 576/*
@@ -578,7 +581,7 @@ static struct proto unix_proto = {
578 */ 581 */
579static struct lock_class_key af_unix_sk_receive_queue_lock_key; 582static struct lock_class_key af_unix_sk_receive_queue_lock_key;
580 583
581static struct sock * unix_create1(struct net *net, struct socket *sock) 584static struct sock *unix_create1(struct net *net, struct socket *sock)
582{ 585{
583 struct sock *sk = NULL; 586 struct sock *sk = NULL;
584 struct unix_sock *u; 587 struct unix_sock *u;
@@ -591,7 +594,7 @@ static struct sock * unix_create1(struct net *net, struct socket *sock)
591 if (!sk) 594 if (!sk)
592 goto out; 595 goto out;
593 596
594 sock_init_data(sock,sk); 597 sock_init_data(sock, sk);
595 lockdep_set_class(&sk->sk_receive_queue.lock, 598 lockdep_set_class(&sk->sk_receive_queue.lock,
596 &af_unix_sk_receive_queue_lock_key); 599 &af_unix_sk_receive_queue_lock_key);
597 600
@@ -610,6 +613,11 @@ static struct sock * unix_create1(struct net *net, struct socket *sock)
610out: 613out:
611 if (sk == NULL) 614 if (sk == NULL)
612 atomic_dec(&unix_nr_socks); 615 atomic_dec(&unix_nr_socks);
616 else {
617 local_bh_disable();
618 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
619 local_bh_enable();
620 }
613 return sk; 621 return sk;
614} 622}
615 623
@@ -629,7 +637,7 @@ static int unix_create(struct net *net, struct socket *sock, int protocol)
629 * nothing uses it. 637 * nothing uses it.
630 */ 638 */
631 case SOCK_RAW: 639 case SOCK_RAW:
632 sock->type=SOCK_DGRAM; 640 sock->type = SOCK_DGRAM;
633 case SOCK_DGRAM: 641 case SOCK_DGRAM:
634 sock->ops = &unix_dgram_ops; 642 sock->ops = &unix_dgram_ops;
635 break; 643 break;
@@ -652,7 +660,7 @@ static int unix_release(struct socket *sock)
652 660
653 sock->sk = NULL; 661 sock->sk = NULL;
654 662
655 return unix_release_sock (sk, 0); 663 return unix_release_sock(sk, 0);
656} 664}
657 665
658static int unix_autobind(struct socket *sock) 666static int unix_autobind(struct socket *sock)
@@ -661,7 +669,7 @@ static int unix_autobind(struct socket *sock)
661 struct net *net = sock_net(sk); 669 struct net *net = sock_net(sk);
662 struct unix_sock *u = unix_sk(sk); 670 struct unix_sock *u = unix_sk(sk);
663 static u32 ordernum = 1; 671 static u32 ordernum = 1;
664 struct unix_address * addr; 672 struct unix_address *addr;
665 int err; 673 int err;
666 674
667 mutex_lock(&u->readlock); 675 mutex_lock(&u->readlock);
@@ -680,7 +688,7 @@ static int unix_autobind(struct socket *sock)
680 688
681retry: 689retry:
682 addr->len = sprintf(addr->name->sun_path+1, "%05x", ordernum) + 1 + sizeof(short); 690 addr->len = sprintf(addr->name->sun_path+1, "%05x", ordernum) + 1 + sizeof(short);
683 addr->hash = unix_hash_fold(csum_partial((void*)addr->name, addr->len, 0)); 691 addr->hash = unix_hash_fold(csum_partial(addr->name, addr->len, 0));
684 692
685 spin_lock(&unix_table_lock); 693 spin_lock(&unix_table_lock);
686 ordernum = (ordernum+1)&0xFFFFF; 694 ordernum = (ordernum+1)&0xFFFFF;
@@ -735,14 +743,14 @@ static struct sock *unix_find_other(struct net *net,
735 743
736 path_put(&path); 744 path_put(&path);
737 745
738 err=-EPROTOTYPE; 746 err = -EPROTOTYPE;
739 if (u->sk_type != type) { 747 if (u->sk_type != type) {
740 sock_put(u); 748 sock_put(u);
741 goto fail; 749 goto fail;
742 } 750 }
743 } else { 751 } else {
744 err = -ECONNREFUSED; 752 err = -ECONNREFUSED;
745 u=unix_find_socket_byname(net, sunname, len, type, hash); 753 u = unix_find_socket_byname(net, sunname, len, type, hash);
746 if (u) { 754 if (u) {
747 struct dentry *dentry; 755 struct dentry *dentry;
748 dentry = unix_sk(u)->dentry; 756 dentry = unix_sk(u)->dentry;
@@ -756,7 +764,7 @@ static struct sock *unix_find_other(struct net *net,
756put_fail: 764put_fail:
757 path_put(&path); 765 path_put(&path);
758fail: 766fail:
759 *error=err; 767 *error = err;
760 return NULL; 768 return NULL;
761} 769}
762 770
@@ -766,8 +774,8 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
766 struct sock *sk = sock->sk; 774 struct sock *sk = sock->sk;
767 struct net *net = sock_net(sk); 775 struct net *net = sock_net(sk);
768 struct unix_sock *u = unix_sk(sk); 776 struct unix_sock *u = unix_sk(sk);
769 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; 777 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
770 struct dentry * dentry = NULL; 778 struct dentry *dentry = NULL;
771 struct nameidata nd; 779 struct nameidata nd;
772 int err; 780 int err;
773 unsigned hash; 781 unsigned hash;
@@ -778,7 +786,7 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
778 if (sunaddr->sun_family != AF_UNIX) 786 if (sunaddr->sun_family != AF_UNIX)
779 goto out; 787 goto out;
780 788
781 if (addr_len==sizeof(short)) { 789 if (addr_len == sizeof(short)) {
782 err = unix_autobind(sock); 790 err = unix_autobind(sock);
783 goto out; 791 goto out;
784 } 792 }
@@ -874,8 +882,8 @@ out_mknod_unlock:
874 mutex_unlock(&nd.path.dentry->d_inode->i_mutex); 882 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
875 path_put(&nd.path); 883 path_put(&nd.path);
876out_mknod_parent: 884out_mknod_parent:
877 if (err==-EEXIST) 885 if (err == -EEXIST)
878 err=-EADDRINUSE; 886 err = -EADDRINUSE;
879 unix_release_addr(addr); 887 unix_release_addr(addr);
880 goto out_up; 888 goto out_up;
881} 889}
@@ -910,7 +918,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
910{ 918{
911 struct sock *sk = sock->sk; 919 struct sock *sk = sock->sk;
912 struct net *net = sock_net(sk); 920 struct net *net = sock_net(sk);
913 struct sockaddr_un *sunaddr=(struct sockaddr_un*)addr; 921 struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr;
914 struct sock *other; 922 struct sock *other;
915 unsigned hash; 923 unsigned hash;
916 int err; 924 int err;
@@ -926,7 +934,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
926 goto out; 934 goto out;
927 935
928restart: 936restart:
929 other=unix_find_other(net, sunaddr, alen, sock->type, hash, &err); 937 other = unix_find_other(net, sunaddr, alen, sock->type, hash, &err);
930 if (!other) 938 if (!other)
931 goto out; 939 goto out;
932 940
@@ -960,14 +968,14 @@ restart:
960 */ 968 */
961 if (unix_peer(sk)) { 969 if (unix_peer(sk)) {
962 struct sock *old_peer = unix_peer(sk); 970 struct sock *old_peer = unix_peer(sk);
963 unix_peer(sk)=other; 971 unix_peer(sk) = other;
964 unix_state_double_unlock(sk, other); 972 unix_state_double_unlock(sk, other);
965 973
966 if (other != old_peer) 974 if (other != old_peer)
967 unix_dgram_disconnected(sk, old_peer); 975 unix_dgram_disconnected(sk, old_peer);
968 sock_put(old_peer); 976 sock_put(old_peer);
969 } else { 977 } else {
970 unix_peer(sk)=other; 978 unix_peer(sk) = other;
971 unix_state_double_unlock(sk, other); 979 unix_state_double_unlock(sk, other);
972 } 980 }
973 return 0; 981 return 0;
@@ -1003,7 +1011,7 @@ static long unix_wait_for_peer(struct sock *other, long timeo)
1003static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, 1011static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
1004 int addr_len, int flags) 1012 int addr_len, int flags)
1005{ 1013{
1006 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; 1014 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
1007 struct sock *sk = sock->sk; 1015 struct sock *sk = sock->sk;
1008 struct net *net = sock_net(sk); 1016 struct net *net = sock_net(sk);
1009 struct unix_sock *u = unix_sk(sk), *newu, *otheru; 1017 struct unix_sock *u = unix_sk(sk), *newu, *otheru;
@@ -1177,13 +1185,13 @@ out:
1177 1185
1178static int unix_socketpair(struct socket *socka, struct socket *sockb) 1186static int unix_socketpair(struct socket *socka, struct socket *sockb)
1179{ 1187{
1180 struct sock *ska=socka->sk, *skb = sockb->sk; 1188 struct sock *ska = socka->sk, *skb = sockb->sk;
1181 1189
1182 /* Join our sockets back to back */ 1190 /* Join our sockets back to back */
1183 sock_hold(ska); 1191 sock_hold(ska);
1184 sock_hold(skb); 1192 sock_hold(skb);
1185 unix_peer(ska)=skb; 1193 unix_peer(ska) = skb;
1186 unix_peer(skb)=ska; 1194 unix_peer(skb) = ska;
1187 ska->sk_peercred.pid = skb->sk_peercred.pid = task_tgid_vnr(current); 1195 ska->sk_peercred.pid = skb->sk_peercred.pid = task_tgid_vnr(current);
1188 current_euid_egid(&skb->sk_peercred.uid, &skb->sk_peercred.gid); 1196 current_euid_egid(&skb->sk_peercred.uid, &skb->sk_peercred.gid);
1189 ska->sk_peercred.uid = skb->sk_peercred.uid; 1197 ska->sk_peercred.uid = skb->sk_peercred.uid;
@@ -1206,7 +1214,7 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags)
1206 int err; 1214 int err;
1207 1215
1208 err = -EOPNOTSUPP; 1216 err = -EOPNOTSUPP;
1209 if (sock->type!=SOCK_STREAM && sock->type!=SOCK_SEQPACKET) 1217 if (sock->type != SOCK_STREAM && sock->type != SOCK_SEQPACKET)
1210 goto out; 1218 goto out;
1211 1219
1212 err = -EINVAL; 1220 err = -EINVAL;
@@ -1245,7 +1253,7 @@ static int unix_getname(struct socket *sock, struct sockaddr *uaddr, int *uaddr_
1245{ 1253{
1246 struct sock *sk = sock->sk; 1254 struct sock *sk = sock->sk;
1247 struct unix_sock *u; 1255 struct unix_sock *u;
1248 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; 1256 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
1249 int err = 0; 1257 int err = 0;
1250 1258
1251 if (peer) { 1259 if (peer) {
@@ -1285,7 +1293,7 @@ static void unix_detach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1285 skb->destructor = sock_wfree; 1293 skb->destructor = sock_wfree;
1286 UNIXCB(skb).fp = NULL; 1294 UNIXCB(skb).fp = NULL;
1287 1295
1288 for (i=scm->fp->count-1; i>=0; i--) 1296 for (i = scm->fp->count-1; i >= 0; i--)
1289 unix_notinflight(scm->fp->fp[i]); 1297 unix_notinflight(scm->fp->fp[i]);
1290} 1298}
1291 1299
@@ -1314,7 +1322,7 @@ static int unix_attach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1314 if (!UNIXCB(skb).fp) 1322 if (!UNIXCB(skb).fp)
1315 return -ENOMEM; 1323 return -ENOMEM;
1316 1324
1317 for (i=scm->fp->count-1; i>=0; i--) 1325 for (i = scm->fp->count-1; i >= 0; i--)
1318 unix_inflight(scm->fp->fp[i]); 1326 unix_inflight(scm->fp->fp[i]);
1319 skb->destructor = unix_destruct_fds; 1327 skb->destructor = unix_destruct_fds;
1320 return 0; 1328 return 0;
@@ -1331,7 +1339,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1331 struct sock *sk = sock->sk; 1339 struct sock *sk = sock->sk;
1332 struct net *net = sock_net(sk); 1340 struct net *net = sock_net(sk);
1333 struct unix_sock *u = unix_sk(sk); 1341 struct unix_sock *u = unix_sk(sk);
1334 struct sockaddr_un *sunaddr=msg->msg_name; 1342 struct sockaddr_un *sunaddr = msg->msg_name;
1335 struct sock *other = NULL; 1343 struct sock *other = NULL;
1336 int namelen = 0; /* fake GCC */ 1344 int namelen = 0; /* fake GCC */
1337 int err; 1345 int err;
@@ -1373,7 +1381,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1373 goto out; 1381 goto out;
1374 1382
1375 skb = sock_alloc_send_skb(sk, len, msg->msg_flags&MSG_DONTWAIT, &err); 1383 skb = sock_alloc_send_skb(sk, len, msg->msg_flags&MSG_DONTWAIT, &err);
1376 if (skb==NULL) 1384 if (skb == NULL)
1377 goto out; 1385 goto out;
1378 1386
1379 memcpy(UNIXCREDS(skb), &siocb->scm->creds, sizeof(struct ucred)); 1387 memcpy(UNIXCREDS(skb), &siocb->scm->creds, sizeof(struct ucred));
@@ -1385,7 +1393,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1385 unix_get_secdata(siocb->scm, skb); 1393 unix_get_secdata(siocb->scm, skb);
1386 1394
1387 skb_reset_transport_header(skb); 1395 skb_reset_transport_header(skb);
1388 err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len); 1396 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
1389 if (err) 1397 if (err)
1390 goto out_free; 1398 goto out_free;
1391 1399
@@ -1399,7 +1407,7 @@ restart:
1399 1407
1400 other = unix_find_other(net, sunaddr, namelen, sk->sk_type, 1408 other = unix_find_other(net, sunaddr, namelen, sk->sk_type,
1401 hash, &err); 1409 hash, &err);
1402 if (other==NULL) 1410 if (other == NULL)
1403 goto out_free; 1411 goto out_free;
1404 } 1412 }
1405 1413
@@ -1419,7 +1427,7 @@ restart:
1419 err = 0; 1427 err = 0;
1420 unix_state_lock(sk); 1428 unix_state_lock(sk);
1421 if (unix_peer(sk) == other) { 1429 if (unix_peer(sk) == other) {
1422 unix_peer(sk)=NULL; 1430 unix_peer(sk) = NULL;
1423 unix_state_unlock(sk); 1431 unix_state_unlock(sk);
1424 1432
1425 unix_dgram_disconnected(sk, other); 1433 unix_dgram_disconnected(sk, other);
@@ -1485,10 +1493,10 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1485 struct sock_iocb *siocb = kiocb_to_siocb(kiocb); 1493 struct sock_iocb *siocb = kiocb_to_siocb(kiocb);
1486 struct sock *sk = sock->sk; 1494 struct sock *sk = sock->sk;
1487 struct sock *other = NULL; 1495 struct sock *other = NULL;
1488 struct sockaddr_un *sunaddr=msg->msg_name; 1496 struct sockaddr_un *sunaddr = msg->msg_name;
1489 int err,size; 1497 int err, size;
1490 struct sk_buff *skb; 1498 struct sk_buff *skb;
1491 int sent=0; 1499 int sent = 0;
1492 struct scm_cookie tmp_scm; 1500 struct scm_cookie tmp_scm;
1493 1501
1494 if (NULL == siocb->scm) 1502 if (NULL == siocb->scm)
@@ -1516,8 +1524,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1516 if (sk->sk_shutdown & SEND_SHUTDOWN) 1524 if (sk->sk_shutdown & SEND_SHUTDOWN)
1517 goto pipe_err; 1525 goto pipe_err;
1518 1526
1519 while(sent < len) 1527 while (sent < len) {
1520 {
1521 /* 1528 /*
1522 * Optimisation for the fact that under 0.01% of X 1529 * Optimisation for the fact that under 0.01% of X
1523 * messages typically need breaking up. 1530 * messages typically need breaking up.
@@ -1536,9 +1543,10 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1536 * Grab a buffer 1543 * Grab a buffer
1537 */ 1544 */
1538 1545
1539 skb=sock_alloc_send_skb(sk,size,msg->msg_flags&MSG_DONTWAIT, &err); 1546 skb = sock_alloc_send_skb(sk, size, msg->msg_flags&MSG_DONTWAIT,
1547 &err);
1540 1548
1541 if (skb==NULL) 1549 if (skb == NULL)
1542 goto out_err; 1550 goto out_err;
1543 1551
1544 /* 1552 /*
@@ -1559,7 +1567,8 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1559 } 1567 }
1560 } 1568 }
1561 1569
1562 if ((err = memcpy_fromiovec(skb_put(skb,size), msg->msg_iov, size)) != 0) { 1570 err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size);
1571 if (err) {
1563 kfree_skb(skb); 1572 kfree_skb(skb);
1564 goto out_err; 1573 goto out_err;
1565 } 1574 }
@@ -1573,7 +1582,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1573 skb_queue_tail(&other->sk_receive_queue, skb); 1582 skb_queue_tail(&other->sk_receive_queue, skb);
1574 unix_state_unlock(other); 1583 unix_state_unlock(other);
1575 other->sk_data_ready(other, size); 1584 other->sk_data_ready(other, size);
1576 sent+=size; 1585 sent += size;
1577 } 1586 }
1578 1587
1579 scm_destroy(siocb->scm); 1588 scm_destroy(siocb->scm);
@@ -1585,8 +1594,8 @@ pipe_err_free:
1585 unix_state_unlock(other); 1594 unix_state_unlock(other);
1586 kfree_skb(skb); 1595 kfree_skb(skb);
1587pipe_err: 1596pipe_err:
1588 if (sent==0 && !(msg->msg_flags&MSG_NOSIGNAL)) 1597 if (sent == 0 && !(msg->msg_flags&MSG_NOSIGNAL))
1589 send_sig(SIGPIPE,current,0); 1598 send_sig(SIGPIPE, current, 0);
1590 err = -EPIPE; 1599 err = -EPIPE;
1591out_err: 1600out_err:
1592 scm_destroy(siocb->scm); 1601 scm_destroy(siocb->scm);
@@ -1676,13 +1685,10 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1676 siocb->scm->creds = *UNIXCREDS(skb); 1685 siocb->scm->creds = *UNIXCREDS(skb);
1677 unix_set_secdata(siocb->scm, skb); 1686 unix_set_secdata(siocb->scm, skb);
1678 1687
1679 if (!(flags & MSG_PEEK)) 1688 if (!(flags & MSG_PEEK)) {
1680 {
1681 if (UNIXCB(skb).fp) 1689 if (UNIXCB(skb).fp)
1682 unix_detach_fds(siocb->scm, skb); 1690 unix_detach_fds(siocb->scm, skb);
1683 } 1691 } else {
1684 else
1685 {
1686 /* It is questionable: on PEEK we could: 1692 /* It is questionable: on PEEK we could:
1687 - do not return fds - good, but too simple 8) 1693 - do not return fds - good, but too simple 8)
1688 - return fds, and do not return them on read (old strategy, 1694 - return fds, and do not return them on read (old strategy,
@@ -1703,7 +1709,7 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1703 scm_recv(sock, msg, siocb->scm, flags); 1709 scm_recv(sock, msg, siocb->scm, flags);
1704 1710
1705out_free: 1711out_free:
1706 skb_free_datagram(sk,skb); 1712 skb_free_datagram(sk, skb);
1707out_unlock: 1713out_unlock:
1708 mutex_unlock(&u->readlock); 1714 mutex_unlock(&u->readlock);
1709out: 1715out:
@@ -1714,7 +1720,7 @@ out:
1714 * Sleep until data has arrive. But check for races.. 1720 * Sleep until data has arrive. But check for races..
1715 */ 1721 */
1716 1722
1717static long unix_stream_data_wait(struct sock * sk, long timeo) 1723static long unix_stream_data_wait(struct sock *sk, long timeo)
1718{ 1724{
1719 DEFINE_WAIT(wait); 1725 DEFINE_WAIT(wait);
1720 1726
@@ -1752,7 +1758,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1752 struct scm_cookie tmp_scm; 1758 struct scm_cookie tmp_scm;
1753 struct sock *sk = sock->sk; 1759 struct sock *sk = sock->sk;
1754 struct unix_sock *u = unix_sk(sk); 1760 struct unix_sock *u = unix_sk(sk);
1755 struct sockaddr_un *sunaddr=msg->msg_name; 1761 struct sockaddr_un *sunaddr = msg->msg_name;
1756 int copied = 0; 1762 int copied = 0;
1757 int check_creds = 0; 1763 int check_creds = 0;
1758 int target; 1764 int target;
@@ -1783,15 +1789,13 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1783 1789
1784 mutex_lock(&u->readlock); 1790 mutex_lock(&u->readlock);
1785 1791
1786 do 1792 do {
1787 {
1788 int chunk; 1793 int chunk;
1789 struct sk_buff *skb; 1794 struct sk_buff *skb;
1790 1795
1791 unix_state_lock(sk); 1796 unix_state_lock(sk);
1792 skb = skb_dequeue(&sk->sk_receive_queue); 1797 skb = skb_dequeue(&sk->sk_receive_queue);
1793 if (skb==NULL) 1798 if (skb == NULL) {
1794 {
1795 if (copied >= target) 1799 if (copied >= target)
1796 goto unlock; 1800 goto unlock;
1797 1801
@@ -1799,7 +1803,8 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1799 * POSIX 1003.1g mandates this order. 1803 * POSIX 1003.1g mandates this order.
1800 */ 1804 */
1801 1805
1802 if ((err = sock_error(sk)) != 0) 1806 err = sock_error(sk);
1807 if (err)
1803 goto unlock; 1808 goto unlock;
1804 if (sk->sk_shutdown & RCV_SHUTDOWN) 1809 if (sk->sk_shutdown & RCV_SHUTDOWN)
1805 goto unlock; 1810 goto unlock;
@@ -1826,7 +1831,8 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1826 1831
1827 if (check_creds) { 1832 if (check_creds) {
1828 /* Never glue messages from different writers */ 1833 /* Never glue messages from different writers */
1829 if (memcmp(UNIXCREDS(skb), &siocb->scm->creds, sizeof(siocb->scm->creds)) != 0) { 1834 if (memcmp(UNIXCREDS(skb), &siocb->scm->creds,
1835 sizeof(siocb->scm->creds)) != 0) {
1830 skb_queue_head(&sk->sk_receive_queue, skb); 1836 skb_queue_head(&sk->sk_receive_queue, skb);
1831 break; 1837 break;
1832 } 1838 }
@@ -1837,8 +1843,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1837 } 1843 }
1838 1844
1839 /* Copy address just once */ 1845 /* Copy address just once */
1840 if (sunaddr) 1846 if (sunaddr) {
1841 {
1842 unix_copy_addr(msg, skb->sk); 1847 unix_copy_addr(msg, skb->sk);
1843 sunaddr = NULL; 1848 sunaddr = NULL;
1844 } 1849 }
@@ -1854,16 +1859,14 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1854 size -= chunk; 1859 size -= chunk;
1855 1860
1856 /* Mark read part of skb as used */ 1861 /* Mark read part of skb as used */
1857 if (!(flags & MSG_PEEK)) 1862 if (!(flags & MSG_PEEK)) {
1858 {
1859 skb_pull(skb, chunk); 1863 skb_pull(skb, chunk);
1860 1864
1861 if (UNIXCB(skb).fp) 1865 if (UNIXCB(skb).fp)
1862 unix_detach_fds(siocb->scm, skb); 1866 unix_detach_fds(siocb->scm, skb);
1863 1867
1864 /* put the skb back if we didn't use it up.. */ 1868 /* put the skb back if we didn't use it up.. */
1865 if (skb->len) 1869 if (skb->len) {
1866 {
1867 skb_queue_head(&sk->sk_receive_queue, skb); 1870 skb_queue_head(&sk->sk_receive_queue, skb);
1868 break; 1871 break;
1869 } 1872 }
@@ -1872,9 +1875,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1872 1875
1873 if (siocb->scm->fp) 1876 if (siocb->scm->fp)
1874 break; 1877 break;
1875 } 1878 } else {
1876 else
1877 {
1878 /* It is questionable, see note in unix_dgram_recvmsg. 1879 /* It is questionable, see note in unix_dgram_recvmsg.
1879 */ 1880 */
1880 if (UNIXCB(skb).fp) 1881 if (UNIXCB(skb).fp)
@@ -1902,7 +1903,7 @@ static int unix_shutdown(struct socket *sock, int mode)
1902 if (mode) { 1903 if (mode) {
1903 unix_state_lock(sk); 1904 unix_state_lock(sk);
1904 sk->sk_shutdown |= mode; 1905 sk->sk_shutdown |= mode;
1905 other=unix_peer(sk); 1906 other = unix_peer(sk);
1906 if (other) 1907 if (other)
1907 sock_hold(other); 1908 sock_hold(other);
1908 unix_state_unlock(sk); 1909 unix_state_unlock(sk);
@@ -1937,16 +1938,15 @@ static int unix_shutdown(struct socket *sock, int mode)
1937static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 1938static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1938{ 1939{
1939 struct sock *sk = sock->sk; 1940 struct sock *sk = sock->sk;
1940 long amount=0; 1941 long amount = 0;
1941 int err; 1942 int err;
1942 1943
1943 switch(cmd) 1944 switch (cmd) {
1944 { 1945 case SIOCOUTQ:
1945 case SIOCOUTQ: 1946 amount = atomic_read(&sk->sk_wmem_alloc);
1946 amount = atomic_read(&sk->sk_wmem_alloc); 1947 err = put_user(amount, (int __user *)arg);
1947 err = put_user(amount, (int __user *)arg); 1948 break;
1948 break; 1949 case SIOCINQ:
1949 case SIOCINQ:
1950 { 1950 {
1951 struct sk_buff *skb; 1951 struct sk_buff *skb;
1952 1952
@@ -1963,21 +1963,21 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1963 } else { 1963 } else {
1964 skb = skb_peek(&sk->sk_receive_queue); 1964 skb = skb_peek(&sk->sk_receive_queue);
1965 if (skb) 1965 if (skb)
1966 amount=skb->len; 1966 amount = skb->len;
1967 } 1967 }
1968 spin_unlock(&sk->sk_receive_queue.lock); 1968 spin_unlock(&sk->sk_receive_queue.lock);
1969 err = put_user(amount, (int __user *)arg); 1969 err = put_user(amount, (int __user *)arg);
1970 break; 1970 break;
1971 } 1971 }
1972 1972
1973 default: 1973 default:
1974 err = -ENOIOCTLCMD; 1974 err = -ENOIOCTLCMD;
1975 break; 1975 break;
1976 } 1976 }
1977 return err; 1977 return err;
1978} 1978}
1979 1979
1980static unsigned int unix_poll(struct file * file, struct socket *sock, poll_table *wait) 1980static unsigned int unix_poll(struct file *file, struct socket *sock, poll_table *wait)
1981{ 1981{
1982 struct sock *sk = sock->sk; 1982 struct sock *sk = sock->sk;
1983 unsigned int mask; 1983 unsigned int mask;
@@ -1999,7 +1999,8 @@ static unsigned int unix_poll(struct file * file, struct socket *sock, poll_tabl
1999 mask |= POLLIN | POLLRDNORM; 1999 mask |= POLLIN | POLLRDNORM;
2000 2000
2001 /* Connection-based need to check for termination and startup */ 2001 /* Connection-based need to check for termination and startup */
2002 if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) && sk->sk_state == TCP_CLOSE) 2002 if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) &&
2003 sk->sk_state == TCP_CLOSE)
2003 mask |= POLLHUP; 2004 mask |= POLLHUP;
2004 2005
2005 /* 2006 /*
@@ -2095,6 +2096,7 @@ struct unix_iter_state {
2095 struct seq_net_private p; 2096 struct seq_net_private p;
2096 int i; 2097 int i;
2097}; 2098};
2099
2098static struct sock *unix_seq_idx(struct seq_file *seq, loff_t pos) 2100static struct sock *unix_seq_idx(struct seq_file *seq, loff_t pos)
2099{ 2101{
2100 struct unix_iter_state *iter = seq->private; 2102 struct unix_iter_state *iter = seq->private;
@@ -2111,7 +2113,6 @@ static struct sock *unix_seq_idx(struct seq_file *seq, loff_t pos)
2111 return NULL; 2113 return NULL;
2112} 2114}
2113 2115
2114
2115static void *unix_seq_start(struct seq_file *seq, loff_t *pos) 2116static void *unix_seq_start(struct seq_file *seq, loff_t *pos)
2116 __acquires(unix_table_lock) 2117 __acquires(unix_table_lock)
2117{ 2118{
@@ -2191,7 +2192,6 @@ static const struct seq_operations unix_seq_ops = {
2191 .show = unix_seq_show, 2192 .show = unix_seq_show,
2192}; 2193};
2193 2194
2194
2195static int unix_seq_open(struct inode *inode, struct file *file) 2195static int unix_seq_open(struct inode *inode, struct file *file)
2196{ 2196{
2197 return seq_open_net(inode, file, &unix_seq_ops, 2197 return seq_open_net(inode, file, &unix_seq_ops,
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index abb3ab34cb1e..19c17e4a0c8b 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -106,8 +106,8 @@ static struct sock *unix_get_socket(struct file *filp)
106 * Socket ? 106 * Socket ?
107 */ 107 */
108 if (S_ISSOCK(inode->i_mode)) { 108 if (S_ISSOCK(inode->i_mode)) {
109 struct socket * sock = SOCKET_I(inode); 109 struct socket *sock = SOCKET_I(inode);
110 struct sock * s = sock->sk; 110 struct sock *s = sock->sk;
111 111
112 /* 112 /*
113 * PF_UNIX ? 113 * PF_UNIX ?
@@ -126,7 +126,7 @@ static struct sock *unix_get_socket(struct file *filp)
126void unix_inflight(struct file *fp) 126void unix_inflight(struct file *fp)
127{ 127{
128 struct sock *s = unix_get_socket(fp); 128 struct sock *s = unix_get_socket(fp);
129 if(s) { 129 if (s) {
130 struct unix_sock *u = unix_sk(s); 130 struct unix_sock *u = unix_sk(s);
131 spin_lock(&unix_gc_lock); 131 spin_lock(&unix_gc_lock);
132 if (atomic_long_inc_return(&u->inflight) == 1) { 132 if (atomic_long_inc_return(&u->inflight) == 1) {
@@ -143,7 +143,7 @@ void unix_inflight(struct file *fp)
143void unix_notinflight(struct file *fp) 143void unix_notinflight(struct file *fp)
144{ 144{
145 struct sock *s = unix_get_socket(fp); 145 struct sock *s = unix_get_socket(fp);
146 if(s) { 146 if (s) {
147 struct unix_sock *u = unix_sk(s); 147 struct unix_sock *u = unix_sk(s);
148 spin_lock(&unix_gc_lock); 148 spin_lock(&unix_gc_lock);
149 BUG_ON(list_empty(&u->link)); 149 BUG_ON(list_empty(&u->link));
@@ -156,7 +156,7 @@ void unix_notinflight(struct file *fp)
156 156
157static inline struct sk_buff *sock_queue_head(struct sock *sk) 157static inline struct sk_buff *sock_queue_head(struct sock *sk)
158{ 158{
159 return (struct sk_buff *) &sk->sk_receive_queue; 159 return (struct sk_buff *)&sk->sk_receive_queue;
160} 160}
161 161
162#define receive_queue_for_each_skb(sk, next, skb) \ 162#define receive_queue_for_each_skb(sk, next, skb) \
@@ -370,7 +370,7 @@ void unix_gc(void)
370 */ 370 */
371 skb_queue_head_init(&hitlist); 371 skb_queue_head_init(&hitlist);
372 list_for_each_entry(u, &gc_candidates, link) 372 list_for_each_entry(u, &gc_candidates, link)
373 scan_children(&u->sk, inc_inflight, &hitlist); 373 scan_children(&u->sk, inc_inflight, &hitlist);
374 374
375 spin_unlock(&unix_gc_lock); 375 spin_unlock(&unix_gc_lock);
376 376
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