Skip to content

Commit 1145b52

Browse files
q2venSasha Levin
authored andcommitted
af_unix: Use unix_recvq_full_lockless() in unix_stream_connect().
[ Upstream commit 45d872f ] Once sk->sk_state is changed to TCP_LISTEN, it never changes. unix_accept() takes advantage of this characteristics; it does not hold the listener's unix_state_lock() and only acquires recvq lock to pop one skb. It means unix_state_lock() does not prevent the queue length from changing in unix_stream_connect(). Thus, we need to use unix_recvq_full_lockless() to avoid data-race. Now we remove unix_recvq_full() as no one uses it. Note that we can remove READ_ONCE() for sk->sk_max_ack_backlog in unix_recvq_full_lockless() because of the following reasons: (1) For SOCK_DGRAM, it is a written-once field in unix_create1() (2) For SOCK_STREAM and SOCK_SEQPACKET, it is changed under the listener's unix_state_lock() in unix_listen(), and we hold the lock in unix_stream_connect() Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8c16e55 commit 1145b52

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

net/unix/af_unix.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,9 @@ static inline int unix_may_send(struct sock *sk, struct sock *osk)
221221
return unix_peer(osk) == NULL || unix_our_peer(sk, osk);
222222
}
223223

224-
static inline int unix_recvq_full(const struct sock *sk)
225-
{
226-
return skb_queue_len(&sk->sk_receive_queue) > sk->sk_max_ack_backlog;
227-
}
228-
229224
static inline int unix_recvq_full_lockless(const struct sock *sk)
230225
{
231-
return skb_queue_len_lockless(&sk->sk_receive_queue) >
232-
READ_ONCE(sk->sk_max_ack_backlog);
226+
return skb_queue_len_lockless(&sk->sk_receive_queue) > sk->sk_max_ack_backlog;
233227
}
234228

235229
struct sock *unix_peer_get(struct sock *s)
@@ -1527,7 +1521,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
15271521
if (other->sk_shutdown & RCV_SHUTDOWN)
15281522
goto out_unlock;
15291523

1530-
if (unix_recvq_full(other)) {
1524+
if (unix_recvq_full_lockless(other)) {
15311525
err = -EAGAIN;
15321526
if (!timeo)
15331527
goto out_unlock;

0 commit comments

Comments
 (0)