The close timeout of an orphaned MPTCP socket started at close(), and its expiry reset the connection, while some data could still be waiting for the peer to open its window: a peer reading slowly or pausing got a reset 60 seconds after close(), and lost the end of the data, while TCP delivers it. This timeout is there for the DATA_FIN exchange, see commit d866ae9aaa43 ("mptcp: add a new sysctl for make after break timeout"), and for an orphan that can no longer send anything. So restart it when the DATA_FIN is sent, and when it expires before, as long as a subflow can still send the data, which is then pushed again: an established subflow, on which the peer acked something recently, at least the window probes. Until then, as for a TCP socket that is not orphaned, nothing limits how long the peer can keep its window closed, while it acks the window probes. The timeout still starts at close(): the subflows are not TCP orphans, so its expiry is the only check that the orphan can still send. This was reported on GitHub, with a reproducer: a server writes 2 MB, then calls close(), while the client pauses before reading the rest. After a pause of 90 seconds, the client got ECONNRESET, while TCP delivered everything, as MPTCP now does. If the client vanishes instead, the orphan is now reset as TCP does. Fixes: e16163b6e2b7 ("mptcp: refactor shutdown and close") Cc: stable@vger.kernel.org Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/647 Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index d6a07fa4b4e4..82a0cbe38192 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2814,6 +2814,28 @@ static bool mptcp_close_tout_expired(const struct sock *sk) inet_csk(sk)->icsk_mtup.probe_timestamp + mptcp_close_timeout(sk)); } +/* Before its DATA_FIN, keep an orphan while a subflow can send its data */ +static bool mptcp_orphan_keep(struct sock *sk) +{ + struct mptcp_sock *msk = mptcp_sk(sk); + struct mptcp_subflow_context *subflow; + + if (!sock_flag(sk, SOCK_DEAD) || msk->snd_nxt == msk->write_seq) + return false; + + mptcp_for_each_subflow(msk, subflow) { + struct sock *ssk = mptcp_subflow_tcp_sock(subflow); + + /* a live peer acks at least the probes, every TCP_RTO_MAX */ + if (__mptcp_subflow_active(subflow) && + tcp_jiffies32 - READ_ONCE(tcp_sk(ssk)->rcv_tstamp) < + 2 * TCP_RTO_MAX) + return true; + } + + return false; +} + static void mptcp_check_fastclose(struct mptcp_sock *msk) { struct mptcp_subflow_context *subflow, *tmp; @@ -3151,6 +3173,11 @@ static void mptcp_worker(struct work_struct *work) if (test_and_clear_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags)) __mptcp_close_subflow(sk); + if (mptcp_close_tout_expired(sk) && mptcp_orphan_keep(sk)) { + mptcp_start_tout_timer(sk); + __mptcp_push_pending(sk, 0); + } + if (mptcp_close_tout_expired(sk)) { struct mptcp_subflow_context *subflow, *tmp; @@ -3392,6 +3419,10 @@ static void mptcp_check_send_data_fin(struct sock *sk) WRITE_ONCE(msk->snd_nxt, msk->write_seq); + /* an orphan's close timeout is for the DATA_FIN exchange */ + if (sock_flag(sk, SOCK_DEAD)) + mptcp_start_tout_timer(sk); + mptcp_for_each_subflow(msk, subflow) { struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow); -- 2.55.0