diff options
author | Mark Salyzyn <salyzyn@android.com> | 2015-05-26 08:22:19 -0700 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2015-08-07 00:32:16 +0100 |
commit | f25e48cb938644c632f140c8bc92e0c4210ce20b (patch) | |
tree | 9a09dd7dddf868e9625fe4325137bb9c907c540c | |
parent | dbd061fc4f55c9759b2e59f13080e1735095bbce (diff) | |
download | lwn-f25e48cb938644c632f140c8bc92e0c4210ce20b.tar.gz lwn-f25e48cb938644c632f140c8bc92e0c4210ce20b.zip |
unix/caif: sk_socket can disappear when state is unlocked
[ Upstream commit b48732e4a48d80ed4a14812f0bab09560846514e ]
got a rare NULL pointer dereference in clear_bit
Signed-off-by: Mark Salyzyn <salyzyn@android.com>
Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
----
v2: switch to sock_flag(sk, SOCK_DEAD) and added net/caif/caif_socket.c
v3: return -ECONNRESET in upstream caller of wait function for SOCK_DEAD
Signed-off-by: David S. Miller <davem@davemloft.net>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r-- | net/caif/caif_socket.c | 8 | ||||
-rw-r--r-- | net/unix/af_unix.c | 8 |
2 files changed, 16 insertions, 0 deletions
diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c index 7eed9eb2b9dd..7e4b4b45cf8e 100644 --- a/net/caif/caif_socket.c +++ b/net/caif/caif_socket.c @@ -366,6 +366,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); } @@ -410,6 +414,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); diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 8705ee3b11ef..9b1f371ebd94 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -1870,6 +1870,10 @@ static long unix_stream_data_wait(struct sock *sk, long timeo) unix_state_unlock(sk); timeo = schedule_timeout(timeo); unix_state_lock(sk); + + if (sock_flag(sk, SOCK_DEAD)) + break; + clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags); } @@ -1930,6 +1934,10 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock, struct sk_buff *skb; unix_state_lock(sk); + if (sock_flag(sk, SOCK_DEAD)) { + err = -ECONNRESET; + goto unlock; + } skb = skb_peek(&sk->sk_receive_queue); if (skb == NULL) { unix_sk(sk)->recursion_level = 0; |