Skip to content

Commit c2b2ae3

Browse files
Paolo Abenikuba-moo
authored andcommitted
mptcp: handle correctly disconnect() failures
Currently the mptcp code has assumes that disconnect() can fail only at mptcp_sendmsg_fastopen() time - to avoid a deadlock scenario - and don't even bother returning an error code. Soon mptcp_disconnect() will handle more error conditions: let's track them explicitly. As a bonus, explicitly annotate TCP-level disconnect as not failing: the mptcp code never blocks for event on the subflows. Fixes: 7d80334 ("mptcp: fix deadlock in fastopen error path") Cc: [email protected] Signed-off-by: Paolo Abeni <[email protected]> Tested-by: Christoph Paasch <[email protected]> Reviewed-by: Matthieu Baerts <[email protected]> Signed-off-by: Matthieu Baerts <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 59bb14b commit c2b2ae3

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

net/mptcp/protocol.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,13 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
17271727
if (ret && ret != -EINPROGRESS && ret != -ERESTARTSYS && ret != -EINTR)
17281728
*copied_syn = 0;
17291729
} else if (ret && ret != -EINPROGRESS) {
1730-
mptcp_disconnect(sk, 0);
1730+
/* The disconnect() op called by tcp_sendmsg_fastopen()/
1731+
* __inet_stream_connect() can fail, due to looking check,
1732+
* see mptcp_disconnect().
1733+
* Attempt it again outside the problematic scope.
1734+
*/
1735+
if (!mptcp_disconnect(sk, 0))
1736+
sk->sk_socket->state = SS_UNCONNECTED;
17311737
}
17321738
inet_sk(sk)->defer_connect = 0;
17331739

@@ -2389,7 +2395,10 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
23892395

23902396
need_push = (flags & MPTCP_CF_PUSH) && __mptcp_retransmit_pending_data(sk);
23912397
if (!dispose_it) {
2392-
tcp_disconnect(ssk, 0);
2398+
/* The MPTCP code never wait on the subflow sockets, TCP-level
2399+
* disconnect should never fail
2400+
*/
2401+
WARN_ON_ONCE(tcp_disconnect(ssk, 0));
23932402
msk->subflow->state = SS_UNCONNECTED;
23942403
mptcp_subflow_ctx_reset(subflow);
23952404
release_sock(ssk);
@@ -2812,7 +2821,7 @@ void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how)
28122821
break;
28132822
fallthrough;
28142823
case TCP_SYN_SENT:
2815-
tcp_disconnect(ssk, O_NONBLOCK);
2824+
WARN_ON_ONCE(tcp_disconnect(ssk, O_NONBLOCK));
28162825
break;
28172826
default:
28182827
if (__mptcp_check_fallback(mptcp_sk(sk))) {
@@ -3075,11 +3084,10 @@ static int mptcp_disconnect(struct sock *sk, int flags)
30753084

30763085
/* We are on the fastopen error path. We can't call straight into the
30773086
* subflows cleanup code due to lock nesting (we are already under
3078-
* msk->firstsocket lock). Do nothing and leave the cleanup to the
3079-
* caller.
3087+
* msk->firstsocket lock).
30803088
*/
30813089
if (msk->fastopening)
3082-
return 0;
3090+
return -EBUSY;
30833091

30843092
mptcp_listen_inuse_dec(sk);
30853093
inet_sk_state_store(sk, TCP_CLOSE);

0 commit comments

Comments
 (0)