Skip to content

Commit cc04410

Browse files
Eric Dumazetdavem330
authored andcommitted
af_unix: annotate lockless accesses to sk->sk_err
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9ae8e5a commit cc04410

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
@@ -557,7 +557,7 @@ static void unix_dgram_disconnected(struct sock *sk, struct sock *other)
557557
* when peer was not connected to us.
558558
*/
559559
if (!sock_flag(other, SOCK_DEAD) && unix_peer(other) == sk) {
560-
other->sk_err = ECONNRESET;
560+
WRITE_ONCE(other->sk_err, ECONNRESET);
561561
sk_error_report(other);
562562
}
563563
}
@@ -630,7 +630,7 @@ static void unix_release_sock(struct sock *sk, int embrion)
630630
/* No more writes */
631631
skpair->sk_shutdown = SHUTDOWN_MASK;
632632
if (!skb_queue_empty(&sk->sk_receive_queue) || embrion)
633-
skpair->sk_err = ECONNRESET;
633+
WRITE_ONCE(skpair->sk_err, ECONNRESET);
634634
unix_state_unlock(skpair);
635635
skpair->sk_state_change(skpair);
636636
sk_wake_async(skpair, SOCK_WAKE_WAITD, POLL_HUP);
@@ -3165,7 +3165,7 @@ static __poll_t unix_poll(struct file *file, struct socket *sock, poll_table *wa
31653165
mask = 0;
31663166

31673167
/* exceptional events? */
3168-
if (sk->sk_err)
3168+
if (READ_ONCE(sk->sk_err))
31693169
mask |= EPOLLERR;
31703170
if (sk->sk_shutdown == SHUTDOWN_MASK)
31713171
mask |= EPOLLHUP;
@@ -3208,7 +3208,8 @@ static __poll_t unix_dgram_poll(struct file *file, struct socket *sock,
32083208
mask = 0;
32093209

32103210
/* exceptional events? */
3211-
if (sk->sk_err || !skb_queue_empty_lockless(&sk->sk_error_queue))
3211+
if (READ_ONCE(sk->sk_err) ||
3212+
!skb_queue_empty_lockless(&sk->sk_error_queue))
32123213
mask |= EPOLLERR |
32133214
(sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0);
32143215

0 commit comments

Comments
 (0)