🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by "Matthieu Baerts (NGI0)" Mon, 16 Nov 2026 22:06
[PATCH net 6/7] mptcp: don't send a FIN before the pending data on fallback
#17472
Author: "Matthieu Baerts (NGI0)"
Date: Mon, 16 Nov 2026 22:06
62 lines
11272 bytes
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@vger.kernel.org
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 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
Re: [PATCH net 6/7] mptcp: don't send a FIN before the pending data on fallback
#18162
Author: netdev-bot+sashiko
Date: Tue, 17 Nov 2026 22:29
163 lines
14174 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The new 'no FIN before new data' check in mptcp_try_fallback()
  (net/mptcp/protocol.h) is not reliable.
- [Medium] mptcp: missing pending data push after fallback in
  subflow_check_data_avail()

--

mptcp: don't send a FIN before the pending data on fallback

After this change, mptcp_try_fallback() shuts the subflow down at fallback
time only when no new data is pending before the DATA_FIN. Otherwise,
mptcp_check_send_data_fin() is expected to shut the subflow down once that
data has been pushed. This stops a TCP FIN from going out ahead of data
still in the MPTCP write queue, as in the TFO server case.

> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index 011e73d04ee60..7d226ee38315d 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)) {

[Severity: Medium]
With this change, the subflow FIN is deferred while new data is still
pending, and mptcp_check_send_data_fin() is expected to send it once
that data has been pushed. check_fully_established() now calls
__mptcp_check_push() after a successful fallback, so that path is
covered. What about the other mptcp_try_fallback() callers?

subflow_check_data_avail() falls back on MAPPING_NODSS and
MAPPING_DUMMY:

net/mptcp/subflow.c:subflow_check_data_avail() {
    ...
		if (!mptcp_try_fallback(ssk, MPTCP_MIB_DSSFALLBACK)) {
    ...
}

mptcp_dss_corruption() does the same on a corrupted mapping:

net/mptcp/protocol.c:mptcp_dss_corruption() {
    ...
	if (!mptcp_try_fallback(ssk, MPTCP_MIB_DSSCORRUPTIONFALLBACK)) {
    ...
}

In both cases, mptcp_incoming_options() has already run for this packet
while MPTCP_FALLBACK_DONE was still clear. Without a DSS option, it
returns early, before ack_update_msk() and __mptcp_check_push() are
reached. Neither caller pushes the pending data once the fallback has
succeeded.

Before this patch, the FIN was sent here unconditionally. The data was
lost, but the connection could still be closed. Now the FIN is skipped.
If the peer doesn't send anything else, what pushes the data from
msk->first_pending and then calls mptcp_check_send_data_fin()?

The retransmit timer doesn't seem to help either. If there is unacked
data at the head of the rtx_queue, __mptcp_push_retrans() returns -1
on a fallen-back msk, and __mptcp_retrans() jumps to clear_scheduled:

net/mptcp/protocol.c:__mptcp_retrans() {
    ...
		/* Can fail only in case of fallback. */
		len = __mptcp_push_retrans(sk, dfrag, retrans_seq);
		if (len < 0)
			goto clear_scheduled;
    ...
}

This skips mptcp_check_and_set_pending(sk), so the pending data isn't
scheduled from there either.

Couldn't the connection then be left with both the pending data and
the deferred FIN stuck, so the shutdown never completes? Should
subflow_check_data_avail() and mptcp_dss_corruption() also trigger a
push after a successful fallback, like check_fully_established() does?
Or is another path expected to flush this data?

[Severity: Medium]
Is this lockless check ordered against the writer?

mptcp_try_fallback() can run in BH context with only the ssk lock held.
One example is check_fully_established(), when the 3rd ACK arrives without
MPTCP options:

net/mptcp/options.c:check_fully_established() {
    ...
	if (!mptcp_try_fallback(ssk, MPTCP_MIB_MPCAPABLEDATAFALLBACK)) {
    ...
}

The writer is __mptcp_wr_shutdown(), called from mptcp_shutdown() and
mptcp_close(). It holds only the msk socket lock, not the ssk lock or
msk->fallback_lock:

net/mptcp/protocol.c:__mptcp_wr_shutdown() {
    ...
	WRITE_ONCE(msk->write_seq, msk->write_seq + 1);
	WRITE_ONCE(msk->snd_data_fin_enable, 1);
    ...
}

Nothing orders these two stores. Nothing orders the three READ_ONCE()
loads in mptcp_try_fallback() either. The spin_lock_bh() on
msk->fallback_lock in __mptcp_try_fallback() doesn't help, because the
writer never takes that lock.

On a weakly ordered CPU such as arm64 or POWER, could the BH reader see
snd_data_fin_enable == 1 together with the old write_seq?

Suppose exactly one byte of new data is still unsent, so snd_nxt + 1
equals the old write_seq. The new check then evaluates to true, and
tcp_shutdown(ssk) sends the FIN before that byte.

After that, mptcp_check_send_data_fin() returns early on the writer side:

net/mptcp/protocol.c:mptcp_check_send_data_fin() {
    ...
	if (!msk->snd_data_fin_enable || msk->snd_nxt + 1 != msk->write_seq ||
	    mptcp_send_head(sk))
		return;
    ...
}

The byte can't be pushed later either. The subflow is now in FIN_WAIT1 or
LAST_ACK, so __tcp_can_send() fails in __mptcp_subflow_active().

Wouldn't this truncate the stream in the same way this patch is meant to
prevent, only within a narrower window? The later patch in the series,
"mptcp: fix dummy mapping of overlapping segments", doesn't touch
protocol.h or protocol.c, so the window would still be open at the end of
the series.

Would it close the window to publish snd_data_fin_enable with
smp_store_release() after the write_seq update, and read it with
smp_load_acquire() in mptcp_try_fallback()? An smp_wmb()/smp_rmb() pair
would also work.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-net-mptcp-misc-fixes-7-4-rc4-v1-0-bf7656de653e%40kernel.org
Re: [PATCH net 6/7] mptcp: don't send a FIN before the pending data on fallback
#18774
Author: Matthieu Baerts
Date: Wed, 18 Nov 2026 22:03
164 lines
17576 bytes
Hello,

On 17/11/2026 23:29, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issue(s) to consider.
> 
> Critical: 0 · High: 0 · Medium: 2 · Low: 0
> 
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.

Please see below.

(...)

>> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
>> index 011e73d04ee60..7d226ee38315d 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)) {
> 
> [Severity: Medium]
> With this change, the subflow FIN is deferred while new data is still
> pending, and mptcp_check_send_data_fin() is expected to send it once
> that data has been pushed. check_fully_established() now calls
> __mptcp_check_push() after a successful fallback, so that path is
> covered. What about the other mptcp_try_fallback() callers?
> 
> subflow_check_data_avail() falls back on MAPPING_NODSS and
> MAPPING_DUMMY:
> 
> net/mptcp/subflow.c:subflow_check_data_avail() {
>     ...
> 		if (!mptcp_try_fallback(ssk, MPTCP_MIB_DSSFALLBACK)) {
>     ...
> }
> 
> mptcp_dss_corruption() does the same on a corrupted mapping:
> 
> net/mptcp/protocol.c:mptcp_dss_corruption() {
>     ...
> 	if (!mptcp_try_fallback(ssk, MPTCP_MIB_DSSCORRUPTIONFALLBACK)) {
>     ...
> }
> 
> In both cases, mptcp_incoming_options() has already run for this packet
> while MPTCP_FALLBACK_DONE was still clear. Without a DSS option, it
> returns early, before ack_update_msk() and __mptcp_check_push() are
> reached. Neither caller pushes the pending data once the fallback has
> succeeded.
> 
> Before this patch, the FIN was sent here unconditionally. The data was
> lost, but the connection could still be closed. Now the FIN is skipped.
> If the peer doesn't send anything else, what pushes the data from
> msk->first_pending and then calls mptcp_check_send_data_fin()?
> 
> The retransmit timer doesn't seem to help either. If there is unacked
> data at the head of the rtx_queue, __mptcp_push_retrans() returns -1
> on a fallen-back msk, and __mptcp_retrans() jumps to clear_scheduled:
> 
> net/mptcp/protocol.c:__mptcp_retrans() {
>     ...
> 		/* Can fail only in case of fallback. */
> 		len = __mptcp_push_retrans(sk, dfrag, retrans_seq);
> 		if (len < 0)
> 			goto clear_scheduled;
>     ...
> }
> 
> This skips mptcp_check_and_set_pending(sk), so the pending data isn't
> scheduled from there either.
> 
> Couldn't the connection then be left with both the pending data and
> the deferred FIN stuck, so the shutdown never completes? Should
> subflow_check_data_avail() and mptcp_dss_corruption() also trigger a
> push after a successful fallback, like check_fully_established() does?
> Or is another path expected to flush this data?

Somehow pre-existing: Before this patch, this pending data was lost: the
peer silently got a truncated stream. Now, the data and the FIN are sent
at the next push, e.g. on the next ACK or window update from the peer.
This is the same as for pending data without shutdown, which was already
not pushed after these fallbacks: this is a pre-existing issue, not a
regression. It can be handled in a follow-up, if a stall can be
reproduced, but I didn't manage to reproduce it so far.

> [Severity: Medium]
> Is this lockless check ordered against the writer?
> 
> mptcp_try_fallback() can run in BH context with only the ssk lock held.
> One example is check_fully_established(), when the 3rd ACK arrives without
> MPTCP options:
> 
> net/mptcp/options.c:check_fully_established() {
>     ...
> 	if (!mptcp_try_fallback(ssk, MPTCP_MIB_MPCAPABLEDATAFALLBACK)) {
>     ...
> }
> 
> The writer is __mptcp_wr_shutdown(), called from mptcp_shutdown() and
> mptcp_close(). It holds only the msk socket lock, not the ssk lock or
> msk->fallback_lock:
> 
> net/mptcp/protocol.c:__mptcp_wr_shutdown() {
>     ...
> 	WRITE_ONCE(msk->write_seq, msk->write_seq + 1);
> 	WRITE_ONCE(msk->snd_data_fin_enable, 1);
>     ...
> }
> 
> Nothing orders these two stores. Nothing orders the three READ_ONCE()
> loads in mptcp_try_fallback() either. The spin_lock_bh() on
> msk->fallback_lock in __mptcp_try_fallback() doesn't help, because the
> writer never takes that lock.
> 
> On a weakly ordered CPU such as arm64 or POWER, could the BH reader see
> snd_data_fin_enable == 1 together with the old write_seq?
> 
> Suppose exactly one byte of new data is still unsent, so snd_nxt + 1
> equals the old write_seq. The new check then evaluates to true, and
> tcp_shutdown(ssk) sends the FIN before that byte.
> 
> After that, mptcp_check_send_data_fin() returns early on the writer side:
> 
> net/mptcp/protocol.c:mptcp_check_send_data_fin() {
>     ...
> 	if (!msk->snd_data_fin_enable || msk->snd_nxt + 1 != msk->write_seq ||
> 	    mptcp_send_head(sk))
> 		return;
>     ...
> }
> 
> The byte can't be pushed later either. The subflow is now in FIN_WAIT1 or
> LAST_ACK, so __tcp_can_send() fails in __mptcp_subflow_active().
> 
> Wouldn't this truncate the stream in the same way this patch is meant to
> prevent, only within a narrower window?

This is theoretical: it needs a weakly ordered CPU, a shutdown racing
with a fallback, and exactly one byte left unsent. Without this patch,
the stream is always truncated in this case, so not a regression, and I
don't think it is worth blocking this patch for this theoretical reason.

> Would it close the window to publish snd_data_fin_enable with
> smp_store_release() after the write_seq update, and read it with
> smp_load_acquire() in mptcp_try_fallback()? An smp_wmb()/smp_rmb() pair
> would also work.

A release/acquire pair is cheap: I can send a follow-up later on.

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads