AF_UNIX: Fix deadlock on connecting to shutdown socket (CVE-2009-3621)
[pandora-kernel.git] / net / unix / af_unix.c
index 8bde9bf..facdaa9 100644 (file)
@@ -1061,6 +1061,8 @@ restart:
        err = -ECONNREFUSED;
        if (other->sk_state != TCP_LISTEN)
                goto out_unlock;
+       if (other->sk_shutdown & RCV_SHUTDOWN)
+               goto out_unlock;
 
        if (unix_recvq_full(other)) {
                err = -EAGAIN;
@@ -1341,6 +1343,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
 
        if (NULL == siocb->scm)
                siocb->scm = &tmp_scm;
+       wait_for_unix_gc();
        err = scm_send(sock, msg, siocb->scm);
        if (err < 0)
                return err;
@@ -1491,6 +1494,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
 
        if (NULL == siocb->scm)
                siocb->scm = &tmp_scm;
+       wait_for_unix_gc();
        err = scm_send(sock, msg, siocb->scm);
        if (err < 0)
                return err;
@@ -2228,7 +2232,7 @@ static int unix_net_init(struct net *net)
 #endif
        error = 0;
 out:
-       return 0;
+       return error;
 }
 
 static void unix_net_exit(struct net *net)