Commit cda91d5b authored by Xin Long's avatar Xin Long Committed by David S. Miller

sctp: cancel a blocking accept when shutdown a listen socket

As David Laight noticed,

"In a multithreaded program it is reasonable to have a thread blocked in
 accept(). With TCP a subsequent shutdown(listen_fd, SHUT_RDWR) causes
 the accept to fail. But nothing happens for SCTP."

sctp_disconnect() is eventually called when shutdown a listen socket,
but nothing is done in this function. This patch sets RCV_SHUTDOWN
flag in sk->sk_shutdown there, and adds the check (sk->sk_shutdown &
RCV_SHUTDOWN) to break and return in sctp_accept().

Note that shutdown() is only supported on TCP-style SCTP socket.
Reported-by: default avatarDavid Laight <David.Laight@aculab.com>
Signed-off-by: default avatarXin Long <lucien.xin@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2e3ed20c
...@@ -4834,10 +4834,14 @@ int sctp_inet_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -4834,10 +4834,14 @@ int sctp_inet_connect(struct socket *sock, struct sockaddr *uaddr,
return sctp_connect(sock->sk, uaddr, addr_len, flags); return sctp_connect(sock->sk, uaddr, addr_len, flags);
} }
/* FIXME: Write comments. */ /* Only called when shutdown a listening SCTP socket. */
static int sctp_disconnect(struct sock *sk, int flags) static int sctp_disconnect(struct sock *sk, int flags)
{ {
return -EOPNOTSUPP; /* STUB */ if (!sctp_style(sk, TCP))
return -EOPNOTSUPP;
sk->sk_shutdown |= RCV_SHUTDOWN;
return 0;
} }
/* 4.1.4 accept() - TCP Style Syntax /* 4.1.4 accept() - TCP Style Syntax
...@@ -4866,7 +4870,8 @@ static struct sock *sctp_accept(struct sock *sk, struct proto_accept_arg *arg) ...@@ -4866,7 +4870,8 @@ static struct sock *sctp_accept(struct sock *sk, struct proto_accept_arg *arg)
goto out; goto out;
} }
if (!sctp_sstate(sk, LISTENING)) { if (!sctp_sstate(sk, LISTENING) ||
(sk->sk_shutdown & RCV_SHUTDOWN)) {
error = -EINVAL; error = -EINVAL;
goto out; goto out;
} }
...@@ -9393,7 +9398,8 @@ static int sctp_wait_for_accept(struct sock *sk, long timeo) ...@@ -9393,7 +9398,8 @@ static int sctp_wait_for_accept(struct sock *sk, long timeo)
} }
err = -EINVAL; err = -EINVAL;
if (!sctp_sstate(sk, LISTENING)) if (!sctp_sstate(sk, LISTENING) ||
(sk->sk_shutdown & RCV_SHUTDOWN))
break; break;
err = 0; err = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment