Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

af_unix: Don't hold unix_state_lock() in __unix_dgram_recvmsg().

When __skb_try_recv_datagram() returns NULL in __unix_dgram_recvmsg(),
we hold unix_state_lock() unconditionally.

This is because SOCK_SEQPACKET sk needs to return EOF in case its peer
has been close()d concurrently.

This behaviour totally depends on the timing of the peer's close() and
reading sk->sk_shutdown, and taking the lock does not play a role.

Let's drop the lock from __unix_dgram_recvmsg() and use READ_ONCE().

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20250702223606.1054680-2-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Kuniyuki Iwashima and committed by
Jakub Kicinski
b429a5ad d18e43dd

+1 -3
+1 -3
net/unix/af_unix.c
··· 2527 2527 &err, &timeo, last)); 2528 2528 2529 2529 if (!skb) { /* implies iolock unlocked */ 2530 - unix_state_lock(sk); 2531 2530 /* Signal EOF on disconnected non-blocking SEQPACKET socket. */ 2532 2531 if (sk->sk_type == SOCK_SEQPACKET && err == -EAGAIN && 2533 - (sk->sk_shutdown & RCV_SHUTDOWN)) 2532 + (READ_ONCE(sk->sk_shutdown) & RCV_SHUTDOWN)) 2534 2533 err = 0; 2535 - unix_state_unlock(sk); 2536 2534 goto out; 2537 2535 } 2538 2536