Skip to content

Commit d0c6416

Browse files
Jiang-BDborkmann
authored andcommitted
unix: Fix an issue in unix_shutdown causing the other end read/write failures
Commit 94531cf ("af_unix: Add unix_stream_proto for sockmap") sets unix domain socket peer state to TCP_CLOSE in unix_shutdown. This could happen when the local end is shutdown but the other end is not. Then, the other end will get read or write failures which is not expected. Fix the issue by setting the local state to shutdown. Fixes: 94531cf ("af_unix: Add unix_stream_proto for sockmap") Reported-by: Casey Schaufler <[email protected]> Suggested-by: Cong Wang <[email protected]> Signed-off-by: Jiang Wang <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Tested-by: Casey Schaufler <[email protected]> Reviewed-by: Casey Schaufler <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent b0e875b commit d0c6416

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
@@ -2860,6 +2860,9 @@ static int unix_shutdown(struct socket *sock, int mode)
28602860

28612861
unix_state_lock(sk);
28622862
sk->sk_shutdown |= mode;
2863+
if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) &&
2864+
mode == SHUTDOWN_MASK)
2865+
sk->sk_state = TCP_CLOSE;
28632866
other = unix_peer(sk);
28642867
if (other)
28652868
sock_hold(other);
@@ -2882,12 +2885,10 @@ static int unix_shutdown(struct socket *sock, int mode)
28822885
other->sk_shutdown |= peer_mode;
28832886
unix_state_unlock(other);
28842887
other->sk_state_change(other);
2885-
if (peer_mode == SHUTDOWN_MASK) {
2888+
if (peer_mode == SHUTDOWN_MASK)
28862889
sk_wake_async(other, SOCK_WAKE_WAITD, POLL_HUP);
2887-
other->sk_state = TCP_CLOSE;
2888-
} else if (peer_mode & RCV_SHUTDOWN) {
2890+
else if (peer_mode & RCV_SHUTDOWN)
28892891
sk_wake_async(other, SOCK_WAKE_WAITD, POLL_IN);
2890-
}
28912892
}
28922893
if (other)
28932894
sock_put(other);

0 commit comments

Comments
 (0)