All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
Cc: mptcp@lists.linux.dev
Subject: Re: [PATCH net 5/9] mptcp: return EOF after a DATA_FIN, as TCP does
Date: Thu, 03 Dec 2026 21:32:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-248694@kernel.org> (raw)
In-Reply-To: <20261202-net-mptcp-misc-fixes-7-4-rc7-v1-5-9f03efcb1a17@kernel.org>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] mptcp: incomplete DATA_FIN state in
  __mptcp_subflow_error_report()
- [Medium] mptcp: setting TCP_CLOSE before mptcp_close_ssk() in
  mptcp_stream_accept()
- [Medium] mptcp: early return in mptcp_check_fastclose() skips subflow
  cleanup
--

commit 6fb285f716a7250c7468727d6c38e6ff75defbfa
Author: Matthieu Baerts (NGI0) <matttbe@kernel.org>

mptcp: return EOF after a DATA_FIN, as TCP does

This commit sets SOCK_DONE on the MPTCP socket when processing a DATA_FIN
(or an emulated DATA_FIN after a TCP fallback FIN) and checks SOCK_DONE
before sock_error() in mptcp_recvmsg() so that recv() returns EOF even if
the connection is subsequently reset.

Link: https://github.com/multipath-tcp/mptcp_net-next/issues/647

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index fc8aad7e2fde9..1f045348764ad 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
[ ... ]
> @@ -934,6 +938,9 @@ static bool __mptcp_subflow_error_report(struct sock *sk, struct sock *ssk)
>  	 * destroy the msk as needed.
>  	 */
>  	ssk_state = inet_sk_state_load(ssk);
> +	/* a FIN received before still leads to EOF, as with TCP */
> +	if (sock_flag(ssk, SOCK_DONE) && mptcp_pending_data_fin(sk, NULL))
> +		sock_set_flag(sk, SOCK_DONE);
>  	if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD))
>  		mptcp_set_state(sk, ssk_state);
>  	WRITE_ONCE(sk->sk_err, -err);

[Severity: Medium]
When a fallback subflow receives a FIN followed by a RST before
mptcp_worker() runs, does setting SOCK_DONE and moving sk->sk_state to
TCP_CLOSE here skip the rest of the DATA_FIN and subflow close handling?

Once sk->sk_state is set to TCP_CLOSE, mptcp_worker() bails out at its
TCPF_CLOSE check before reaching mptcp_check_data_fin() and
__mptcp_close_subflow().  As a result, RCV_SHUTDOWN is never set on
sk->sk_shutdown (so mptcp_poll() does not report EPOLLIN | EPOLLRDNORM |
EPOLLRDHUP once queued data is drained), msk->ack_seq is not incremented
for the DATA_FIN (leaving mptcp_inq_hint() off by one while data is
queued), and mptcp_close_ssk() is skipped until the socket is closed.

[ ... ]

> @@ -2763,12 +2775,21 @@ void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
>  	subflow->close_event_done = true;
>  
>  	if (sk->sk_state == TCP_ESTABLISHED)
> -		mptcp_event(MPTCP_EVENT_SUB_CLOSED, mptcp_sk(sk), ssk, GFP_KERNEL);
> +		mptcp_event(MPTCP_EVENT_SUB_CLOSED, msk, ssk, GFP_KERNEL);
>  
>  	/* subflow aborted before reaching the fully_established status
>  	 * attempt the creation of the next subflow
>  	 */
> -	mptcp_pm_subflow_check_next(mptcp_sk(sk), subflow);
> +	mptcp_pm_subflow_check_next(msk, subflow);
> +
> +	/* On fallback, the FIN of the first subflow is cleared when it is
> +	 * disconnected: process the DATA_FIN emulated from it before.
> +	 */
> +	if (ssk == msk->first && __mptcp_check_fallback(msk) &&
> +	    READ_ONCE(msk->rcv_data_fin) && !sock_flag(sk, SOCK_DEAD)) {
> +		mptcp_move_skbs(sk);
> +		mptcp_check_data_fin(sk);
> +	}
>  
>  	__mptcp_close_ssk(sk, ssk, subflow, MPTCP_CF_PUSH);
>  }

[Severity: Medium]
Can mptcp_check_data_fin() here fail to set SOCK_DONE when a passive
fallback socket receives a FIN and a RST before accept() and before
mptcp_worker() runs?

In mptcp_stream_accept(), newsk->sk_state is set to TCP_CLOSE before
calling mptcp_close_ssk():

net/mptcp/protocol.c:mptcp_stream_accept() {
	...
		if (unlikely(inet_sk_state_load(msk->first) == TCP_CLOSE)) {
			if (unlikely(list_is_singular(&msk->conn_list)))
				mptcp_set_state(newsk, TCP_CLOSE);
			mptcp_close_ssk(newsk, msk->first,
					mptcp_subflow_ctx(msk->first));
		}
	...
}

Because mptcp_pending_data_fin() requires sk->sk_state to be in
TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2, mptcp_check_data_fin()
does nothing when called from mptcp_close_ssk().  __mptcp_close_ssk() then
disconnects msk->first (clearing SOCK_DONE on the subflow) and propagates
EPIPE to newsk->sk_err without SOCK_DONE set on newsk, so recv() returns
-EPIPE instead of EOF after draining the received data.

> @@ -2881,6 +2902,11 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)
>  	if (likely(!READ_ONCE(msk->rcv_fastclose)))
>  		return;
>  
> +	/* a DATA_FIN received before still leads to EOF, as with TCP */
> +	if (READ_ONCE(msk->rcv_data_fin))
> +		mptcp_move_skbs(sk);
> +	mptcp_check_data_fin(sk);
> +
>  	mptcp_token_destroy(msk);
>  
>  	mptcp_for_each_subflow_safe(msk, subflow, tmp) {

[Severity: Medium]
If sk is in TCP_FIN_WAIT2 when DATA_FIN and MP_FASTCLOSE are processed,
does calling mptcp_check_data_fin() here cause mptcp_check_fastclose() to
return early without scheduling subflow cleanup?

In TCP_FIN_WAIT2, mptcp_check_data_fin() calls mptcp_shutdown_subflows()
and sets sk->sk_state to TCP_CLOSE.  mptcp_check_fastclose() then sends
active resets and sets each subflow to TCP_CLOSE via tcp_set_state(), but
hits case TCP_CLOSE: return; in switch (sk->sk_state) before reaching
set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags):

net/mptcp/protocol.c:mptcp_check_fastclose() {
	...
	switch (sk->sk_state) {
	case TCP_SYN_SENT:
		WRITE_ONCE(sk->sk_err, ECONNREFUSED);
		break;
	case TCP_CLOSE_WAIT:
		WRITE_ONCE(sk->sk_err, EPIPE);
		break;
	case TCP_CLOSE:
		return;
	default:
		WRITE_ONCE(sk->sk_err, ECONNRESET);
	}

	mptcp_set_state(sk, TCP_CLOSE);
	WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
	smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
	set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags);
	...
}

Because tcp_set_state() does not trigger subflow_state_change(),
__mptcp_close_subflow() will not run in mptcp_worker(), leaving the
subflows unclosed until the application closes the MPTCP socket.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-net-mptcp-misc-fixes-7-4-rc7-v1-0-9f03efcb1a17@kernel.org?part=5

  reply	other threads:[~2026-12-03 21:32 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 21:29 [PATCH net 0/9] mptcp: misc fixes for v7.4-rc7 Matthieu Baerts (NGI0)
2026-12-02 21:29 ` [PATCH net 1/9] mptcp: pm: kernel: c-flag: keep local_addr_used in sync Matthieu Baerts (NGI0)
2026-12-02 21:29 ` [PATCH net 2/9] mptcp: keep an orphan while it can send its data Matthieu Baerts (NGI0)
2026-12-03 21:51   ` netdev-bot+sashiko
2026-12-04 12:04     ` Matthieu Baerts
2026-12-02 21:29 ` [PATCH net 3/9] mptcp: limit an orphan probing a zero window Matthieu Baerts (NGI0)
2026-12-03 21:51   ` netdev-bot+sashiko
2026-12-04 12:04     ` Matthieu Baerts
2026-12-02 21:29 ` [PATCH net 4/9] mptcp: count orphans as TCP does Matthieu Baerts (NGI0)
2026-12-03 21:32   ` sashiko-bot
2026-12-03 21:51   ` netdev-bot+sashiko
2026-12-04 12:04     ` Matthieu Baerts
2026-12-02 21:29 ` [PATCH net 5/9] mptcp: return EOF after a DATA_FIN, " Matthieu Baerts (NGI0)
2026-12-03 21:32   ` sashiko-bot [this message]
2026-12-03 21:51   ` netdev-bot+sashiko
2026-12-04 12:04     ` Matthieu Baerts
2026-12-02 21:29 ` [PATCH net 6/9] mptcp: wake up blocked senders when no sf left Matthieu Baerts (NGI0)
2026-12-03 21:51   ` netdev-bot+sashiko
2026-12-04 12:05     ` Matthieu Baerts
2026-12-02 21:29 ` [PATCH net 7/9] mptcp: reclaim forward memory after coalescing skbs Matthieu Baerts (NGI0)
2026-12-03 21:51   ` netdev-bot+sashiko
2026-12-04 12:05     ` Matthieu Baerts
2026-12-02 21:29 ` [PATCH net 8/9] mptcp: don't charge a shared page twice at accept() Matthieu Baerts (NGI0)
2026-12-02 21:29 ` [PATCH net 9/9] mptcp: don't charge the backlog " Matthieu Baerts (NGI0)
2026-12-04 12:05 ` [PATCH net 0/9] mptcp: misc fixes for v7.4-rc7 Matthieu Baerts

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-248694@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.