Since the previous commit, an orphan with data to send is kept while
the peer acks something, at least the window probes: a peer keeping its
window closed, e.g. not reading, could then keep the orphan forever.
TCP limits this for its orphans: tcp_probe_timer() aborts them instead
of probing again after the max interval. The subflows of an MPTCP orphan
are not orphaned: they probe again then, and back off once more, up to
tcp_retries2. So check if TCP would have aborted them, when the close
timeout expires. Same with data in flight, when the peer has shrunk its
window to zero: tcp_retransmit_timer() only aborts orphans then.
Two corner cases needing non-default settings are not covered, which is
fine: an idle subflow refreshed by keepalives still keeps the orphan
when the stale detection is disabled, and tcp_orphan_retries is ignored.
This was found by an AI code review agent, while reviewing the previous
commit. With its reproducer and a long pause, the orphan was kept until
the end of the pause. It is now reset as TCP does, respecting
tcp_retries2.
Note for the backports: this patch is needed with the previous one, and
before v6.15, tcp_rto_max() can be replaced by TCP_RTO_MAX.
Fixes: e16163b6e2b7 ("mptcp: refactor shutdown and close")
Cc: stab…@vger.kernel.org
Reviewed-by: Mat Martineau <mart…@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matt…@kernel.org>
---
net/mptcp/protocol.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 82a0cbe38192..96b3baef341f 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2814,6 +2814,32 @@ static bool mptcp_close_tout_expired(const struct sock *sk)
inet_csk(sk)->icsk_mtup.probe_timestamp + mptcp_close_timeout(sk));
}
+/* Would TCP abort this subflow if it were an orphan probing a zero window? */
+static bool mptcp_subflow_probe_timed_out(struct sock *ssk)
+{
+ u8 retries2 = READ_ONCE(sock_net(ssk)->ipv4.sysctl_tcp_retries2);
+ struct inet_connection_sock *icsk = inet_csk(ssk);
+ const struct tcp_sock *tp = tcp_sk(ssk);
+ unsigned long limit;
+ bool slow, ret;
+ u64 when;
+
+ slow = lock_sock_fast_nested(ssk);
+ limit = tcp_rto_max(ssk);
+ if (tp->packets_out) {
+ ret = !tp->snd_wnd && icsk->icsk_rto >= limit;
+ } else {
+ if (icsk->icsk_backoff < retries2)
+ limit *= 2;
+ /* a shift of 32 already exceeds the limit */
+ when = (u64)icsk->icsk_rto << min_t(u8, icsk->icsk_backoff, 32);
+ ret = tcp_send_head(ssk) && when >= limit;
+ }
+ unlock_sock_fast(ssk, slow);
+
+ return ret;
+}
+
/* Before its DATA_FIN, keep an orphan while a subflow can send its data */
static bool mptcp_orphan_keep(struct sock *sk)
{
@@ -2829,7 +2855,8 @@ static bool mptcp_orphan_keep(struct sock *sk)
/* 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)
+ 2 * TCP_RTO_MAX &&
+ !mptcp_subflow_probe_timed_out(ssk))
return true;
}
--
2.55.0