net/unix: sk_socket can disappear when state is unlocked
authorMark Salyzyn <salyzyn@google.com>
Thu, 21 May 2015 16:25:02 +0000 (09:25 -0700)
committerMark Salyzyn <salyzyn@google.com>
Wed, 27 May 2015 15:53:07 +0000 (08:53 -0700)
got a rare NULL pointer dereference in clear_bit

Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Bug: 21252747
Change-Id: I27e70f2543034097c8a590a212c2c6fa846fe695

net/caif/caif_socket.c
net/unix/af_unix.c

index 05a41c7ec304e4256dca41b6b111bc1a267598b5..955e83af1f3ac645cb873ac1ce768217d3d4c175 100644 (file)
@@ -334,6 +334,10 @@ static long caif_stream_data_wait(struct sock *sk, long timeo)
                release_sock(sk);
                timeo = schedule_timeout(timeo);
                lock_sock(sk);
+
+               if (sock_flag(sk, SOCK_DEAD))
+                       break;
+
                clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
        }
 
@@ -380,6 +384,10 @@ static int caif_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
                struct sk_buff *skb;
 
                lock_sock(sk);
+               if (sock_flag(sk, SOCK_DEAD)) {
+                       err = -ECONNRESET;
+                       goto unlock;
+               }
                skb = skb_dequeue(&sk->sk_receive_queue);
                caif_check_flow_release(sk);
 
index c4ce243824bb19c6e600dd98da2d8a6d16747dc1..53e062a2eee0cc058d215e9c3e09830c0e0f002b 100644 (file)
@@ -1882,6 +1882,10 @@ static long unix_stream_data_wait(struct sock *sk, long timeo,
                unix_state_unlock(sk);
                timeo = freezable_schedule_timeout(timeo);
                unix_state_lock(sk);
+
+               if (sock_flag(sk, SOCK_DEAD))
+                       break;
+
                clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
        }
 
@@ -1939,6 +1943,10 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
                struct sk_buff *skb, *last;
 
                unix_state_lock(sk);
+               if (sock_flag(sg, SOCK_DEAD)) {
+                       err = -ECONNRESET;
+                       goto unlock;
+               }
                last = skb = skb_peek(&sk->sk_receive_queue);
 again:
                if (skb == NULL) {