Skip to content

Commit 32accd7

Browse files
edumazetSasha Levin
authored andcommitted
af_unix: annotate lockless accesses to sk->sk_err
[ Upstream commit cc04410 ] unix_poll() and unix_dgram_poll() read sk->sk_err without any lock held. Add relevant READ_ONCE()/WRITE_ONCE() annotations. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Stable-dep-of: 83690b8 ("af_unix: Use skb_queue_empty_lockless() in unix_release_sock().") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 1145b52 commit 32accd7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

net/unix/af_unix.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ static void unix_dgram_disconnected(struct sock *sk, struct sock *other)
548548
* when peer was not connected to us.
549549
*/
550550
if (!sock_flag(other, SOCK_DEAD) && unix_peer(other) == sk) {
551-
other->sk_err = ECONNRESET;
551+
WRITE_ONCE(other->sk_err, ECONNRESET);
552552
sk_error_report(other);
553553
}
554554
}
@@ -620,7 +620,7 @@ static void unix_release_sock(struct sock *sk, int embrion)
620620
/* No more writes */
621621
WRITE_ONCE(skpair->sk_shutdown, SHUTDOWN_MASK);
622622
if (!skb_queue_empty(&sk->sk_receive_queue) || embrion)
623-
skpair->sk_err = ECONNRESET;
623+
WRITE_ONCE(skpair->sk_err, ECONNRESET);
624624
unix_state_unlock(skpair);
625625
skpair->sk_state_change(skpair);
626626
sk_wake_async(skpair, SOCK_WAKE_WAITD, POLL_HUP);
@@ -3181,7 +3181,7 @@ static __poll_t unix_poll(struct file *file, struct socket *sock, poll_table *wa
31813181
state = READ_ONCE(sk->sk_state);
31823182

31833183
/* exceptional events? */
3184-
if (sk->sk_err)
3184+
if (READ_ONCE(sk->sk_err))
31853185
mask |= EPOLLERR;
31863186
if (shutdown == SHUTDOWN_MASK)
31873187
mask |= EPOLLHUP;
@@ -3228,7 +3228,8 @@ static __poll_t unix_dgram_poll(struct file *file, struct socket *sock,
32283228
state = READ_ONCE(sk->sk_state);
32293229

32303230
/* exceptional events? */
3231-
if (sk->sk_err || !skb_queue_empty_lockless(&sk->sk_error_queue))
3231+
if (READ_ONCE(sk->sk_err) ||
3232+
!skb_queue_empty_lockless(&sk->sk_error_queue))
32323233
mask |= EPOLLERR |
32333234
(sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0);
32343235

0 commit comments

Comments
 (0)