Skip to content

Commit b7bb71d

Browse files
Paolo Abenigregkh
authored andcommitted
mptcp: handle correctly disconnect() failures
commit c2b2ae3 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1d9dc9b commit b7bb71d

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
@@ -1708,7 +1708,13 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct sock *ssk, struct msgh
17081708
if (ret && ret != -EINPROGRESS && ret != -ERESTARTSYS && ret != -EINTR)
17091709
*copied_syn = 0;
17101710
} else if (ret && ret != -EINPROGRESS) {
1711-
mptcp_disconnect(sk, 0);
1711+
/* The disconnect() op called by tcp_sendmsg_fastopen()/
1712+
* __inet_stream_connect() can fail, due to looking check,
1713+
* see mptcp_disconnect().
1714+
* Attempt it again outside the problematic scope.
1715+
*/
1716+
if (!mptcp_disconnect(sk, 0))
1717+
sk->sk_socket->state = SS_UNCONNECTED;
17121718
}
17131719

17141720
return ret;
@@ -2375,7 +2381,10 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
23752381

23762382
need_push = (flags & MPTCP_CF_PUSH) && __mptcp_retransmit_pending_data(sk);
23772383
if (!dispose_it) {
2378-
tcp_disconnect(ssk, 0);
2384+
/* The MPTCP code never wait on the subflow sockets, TCP-level
2385+
* disconnect should never fail
2386+
*/
2387+
WARN_ON_ONCE(tcp_disconnect(ssk, 0));
23792388
msk->subflow->state = SS_UNCONNECTED;
23802389
mptcp_subflow_ctx_reset(subflow);
23812390
release_sock(ssk);
@@ -2799,7 +2808,7 @@ void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how)
27992808
break;
28002809
fallthrough;
28012810
case TCP_SYN_SENT:
2802-
tcp_disconnect(ssk, O_NONBLOCK);
2811+
WARN_ON_ONCE(tcp_disconnect(ssk, O_NONBLOCK));
28032812
break;
28042813
default:
28052814
if (__mptcp_check_fallback(mptcp_sk(sk))) {
@@ -3053,11 +3062,10 @@ static int mptcp_disconnect(struct sock *sk, int flags)
30533062

30543063
/* We are on the fastopen error path. We can't call straight into the
30553064
* subflows cleanup code due to lock nesting (we are already under
3056-
* msk->firstsocket lock). Do nothing and leave the cleanup to the
3057-
* caller.
3065+
* msk->firstsocket lock).
30583066
*/
30593067
if (msk->fastopening)
3060-
return 0;
3068+
return -EBUSY;
30613069

30623070
inet_sk_state_store(sk, TCP_CLOSE);
30633071

0 commit comments

Comments
 (0)