summaryrefslogtreecommitdiff
path: root/net/unix
diff options
context:
space:
mode:
authorJiang Wang <jiang.wang@bytedance.com>2021-10-05 02:25:28 +0300
committerDaniel Borkmann <daniel@iogearbox.net>2021-10-06 15:40:21 +0300
commitd0c6416bd7091647f6041599f396bfa19ae30368 (patch)
treea731f7ecafcf4deb48ad7e2ce2c4e304d3ed8e12 /net/unix
parentb0e875bac0fab3e7a7431c2eee36a8ccc0c712ac (diff)
downloadlinux-d0c6416bd7091647f6041599f396bfa19ae30368.tar.xz
unix: Fix an issue in unix_shutdown causing the other end read/write failures
Commit 94531cfcbe79 ("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: 94531cfcbe79 ("af_unix: Add unix_stream_proto for sockmap") Reported-by: Casey Schaufler <casey@schaufler-ca.com> Suggested-by: Cong Wang <cong.wang@bytedance.com> Signed-off-by: Jiang Wang <jiang.wang@bytedance.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Tested-by: Casey Schaufler <casey@schaufler-ca.com> Reviewed-by: Casey Schaufler <casey@schaufler-ca.com> Acked-by: Song Liu <songliubraving@fb.com> Link: https://lore.kernel.org/bpf/20211004232530.2377085-1-jiang.wang@bytedance.com
Diffstat (limited to 'net/unix')
-rw-r--r--net/unix/af_unix.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index f505b89bda6a..915afcae6a12 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2860,6 +2860,9 @@ static int unix_shutdown(struct socket *sock, int mode)
unix_state_lock(sk);
sk->sk_shutdown |= mode;
+ if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) &&
+ mode == SHUTDOWN_MASK)
+ sk->sk_state = TCP_CLOSE;
other = unix_peer(sk);
if (other)
sock_hold(other);
@@ -2882,12 +2885,10 @@ static int unix_shutdown(struct socket *sock, int mode)
other->sk_shutdown |= peer_mode;
unix_state_unlock(other);
other->sk_state_change(other);
- if (peer_mode == SHUTDOWN_MASK) {
+ if (peer_mode == SHUTDOWN_MASK)
sk_wake_async(other, SOCK_WAKE_WAITD, POLL_HUP);
- other->sk_state = TCP_CLOSE;
- } else if (peer_mode & RCV_SHUTDOWN) {
+ else if (peer_mode & RCV_SHUTDOWN)
sk_wake_async(other, SOCK_WAKE_WAITD, POLL_IN);
- }
}
if (other)
sock_put(other);