[PATCH net 6/7] mptcp: don't send a FIN before the pending data on fallback

From: Matthieu Baerts (NGI0)

Date: Mon Nov 16 2026 - 17:11:05 EST


When an MPTCP connection falls back to TCP after having been shut down,
the data that is still in the write queue of the MPTCP socket is lost:
a FIN is sent at fallback time, and this data cannot be sent after it.
This can happen with TCP Fast Open (TFO), when a server writes data and
shuts the connection down before the third ACK, and this ACK has no
MPTCP options.

When the MPTCP socket has been shut down, mptcp_try_fallback() also
shuts the subflow down: if the DATA_FIN had already been sent, nothing
would send a FIN on this subflow otherwise. The commit introducing this
only considered the case where all the data had already been pushed to
the subflow.

The fix used here is to only shut the subflow down at fallback time if
no new data is pending, i.e. if all the data before the DATA_FIN has
already been sent. Otherwise, mptcp_check_send_data_fin() will do it
once this data has been pushed, e.g. by the previous commit. Pending
data that has been reinjected, e.g. after the failure of another
subflow, is not new: it is already in this subflow.

This issue has been found by an AI code review agent, while reviewing
the code of the previous commit, and confirmed with a new Packetdrill
test, where the server writes data and shuts the connection down before
the third ACK, from which the MPTCP options are removed. Without this
patch, a FIN was sent right after this ACK, and the data was never
sent:

inbound injected packet: 0.240127 . 501:501(0) ack 4103187975 win 450
outbound sniffed packet: 0.240207 F. 4103187975:4103187975(0) ack 501 win 1050
outbound sniffed packet: 1.347800 F. 4103187975:4103187975(0) ack 501 win 1050
outbound sniffed packet: 2.499829 F. 4103187975:4103187975(0) ack 501 win 1050
outbound sniffed packet: 4.739843 F. 4103187975:4103187975(0) ack 501 win 1050
server-tfo-fallback-shutdown-before-3rd-ack.pkt:27: error handling packet: Timed out waiting for packet

Fixes: d51991e2e314 ("mptcp: fix shutdown vs fallback race")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@xxxxxxxxxx>
---
net/mptcp/protocol.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 011e73d04ee6..7d226ee38315 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -1333,7 +1333,11 @@ static inline bool mptcp_try_fallback(struct sock *ssk, int fb_mib)
msk = mptcp_sk(sk);
if (!__mptcp_try_fallback(msk, fb_mib))
return false;
- if (READ_ONCE(msk->snd_data_fin_enable) && !(ssk->sk_shutdown & SEND_SHUTDOWN)) {
+
+ /* no FIN before new data: see mptcp_check_send_data_fin() */
+ if (READ_ONCE(msk->snd_data_fin_enable) &&
+ !before64(READ_ONCE(msk->snd_nxt) + 1, READ_ONCE(msk->write_seq)) &&
+ !(ssk->sk_shutdown & SEND_SHUTDOWN)) {
gfp_t saved_allocation = ssk->sk_allocation;

/* we are in a atomic (BH) scope, override ssk default for data

--
2.55.0