* [PATCH v3] net/unix: sk_socket can disappear when state is unlocked
@ 2015-05-26 15:22 Mark Salyzyn
2015-05-26 21:24 ` Hannes Frederic Sowa
0 siblings, 1 reply; 3+ messages in thread
From: Mark Salyzyn @ 2015-05-26 15:22 UTC (permalink / raw)
To: hannes, linux-kernel
Cc: Mark Salyzyn, Dmitry Tarnyagin, David S. Miller, Al Viro,
David Howells, Ying Xue, Christoph Hellwig, netdev
got a rare NULL pointer dereference in clear_bit
Signed-off-by: Mark Salyzyn <salyzyn@android.com>
----
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
---
net/caif/caif_socket.c | 8 ++++++++
net/unix/af_unix.c | 8 ++++++++
2 files changed, 16 insertions(+)
diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
index 4ec0c80..112ad78 100644
--- a/net/caif/caif_socket.c
+++ b/net/caif/caif_socket.c
@@ -330,6 +330,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);
}
@@ -373,6 +377,10 @@ static int caif_stream_recvmsg(struct socket *sock, struct msghdr *msg,
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 5266ea7..0643059 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1880,6 +1880,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 socket *sock, struct msghdr *msg,
struct sk_buff *skb, *last;
unix_state_lock(sk);
+ if (sock_flag(sk, SOCK_DEAD)) {
+ err = -ECONNRESET;
+ goto unlock;
+ }
last = skb = skb_peek(&sk->sk_receive_queue);
again:
if (skb == NULL) {
--
2.2.0.rc0.207.ga3a616c
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] net/unix: sk_socket can disappear when state is unlocked
2015-05-26 15:22 [PATCH v3] net/unix: sk_socket can disappear when state is unlocked Mark Salyzyn
@ 2015-05-26 21:24 ` Hannes Frederic Sowa
2015-05-27 3:20 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Hannes Frederic Sowa @ 2015-05-26 21:24 UTC (permalink / raw)
To: Mark Salyzyn, hannes, linux-kernel
Cc: Dmitry Tarnyagin, David S. Miller, Al Viro, David Howells,
Ying Xue, Christoph Hellwig, netdev
Hi,
On Tue, May 26, 2015, at 17:22, Mark Salyzyn wrote:
> got a rare NULL pointer dereference in clear_bit
>
> Signed-off-by: Mark Salyzyn <salyzyn@android.com>
IMHO, this is the right approach, I didn't came up with something
easier, thanks!
Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] net/unix: sk_socket can disappear when state is unlocked
2015-05-26 21:24 ` Hannes Frederic Sowa
@ 2015-05-27 3:20 ` David Miller
0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2015-05-27 3:20 UTC (permalink / raw)
To: hannes
Cc: salyzyn, hannes, linux-kernel, dmitry.tarnyagin, viro, dhowells,
ying.xue, hch, netdev
From: Hannes Frederic Sowa <hannes@stressinduktion.org>
Date: Tue, 26 May 2015 23:24:59 +0200
> On Tue, May 26, 2015, at 17:22, Mark Salyzyn wrote:
>> got a rare NULL pointer dereference in clear_bit
>>
>> Signed-off-by: Mark Salyzyn <salyzyn@android.com>
>
> IMHO, this is the right approach, I didn't came up with something
> easier, thanks!
>
> Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Applied and queued up for -stable, thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-05-27 3:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-26 15:22 [PATCH v3] net/unix: sk_socket can disappear when state is unlocked Mark Salyzyn
2015-05-26 21:24 ` Hannes Frederic Sowa
2015-05-27 3:20 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).