Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: matttbe@kernel.org
Cc: martineau@kernel.org, geliang@kernel.org, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	willemb@google.com, horms@kernel.org, dcaratti@redhat.com,
	netdev@vger.kernel.org, mptcp@lists.linux.dev, mason@kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH net 5/9] mptcp: return EOF after a DATA_FIN, as TCP does
Date: Thu, 03 Dec 2026 21:51:53 +0000	[thread overview]
Message-ID: <179633471320.3146.5929327584163174012@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 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

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] This patch's fix (EOF after a DATA_FIN even when a reset
  follows) does not cover the passive side when accept() gets the msk…
- [Low] mptcp_close_ssk() (net/mptcp/protocol.c:2787-2788) reads
  msk->rcv_data_fin with READ_ONCE() before it takes the first subflow's…

--

mptcp: return EOF after a DATA_FIN, as TCP does

Once a DATA_FIN has been processed, this patch sets SOCK_DONE on the msk.
mptcp_recvmsg() now checks that flag before the socket error, so recv()
returns EOF after the data even if a reset or MP_FASTCLOSE follows. After
a fallback, the emulated DATA_FIN is now set before the subflow close is
scheduled, and mptcp_close_ssk() processes it before the first subflow is
disconnected.

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

[ ... ]

> @@ -2763,12 +2775,21 @@ void mptcp_close_ssk(struct sock *sk, struct sock *ssk,

[ ... ]

> +	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);
> +	}

[Severity: Medium]
Is the passive side covered when accept() takes the msk lock before
mptcp_worker() has handled the emulated DATA_FIN?

When the first subflow is already closed and is the only subflow,
mptcp_stream_accept() moves newsk to TCP_CLOSE before it calls
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));
		}
    ...
}

The new block above then matches. This is the first subflow, the msk has
fallen back, subflow_sched_work_if_closed() has set rcv_data_fin, and the
msk is not SOCK_DEAD.

But mptcp_check_data_fin() does nothing here. mptcp_pending_data_fin()
only accepts TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2, so the
msk gets neither RCV_SHUTDOWN nor SOCK_DONE.

Next, __mptcp_close_ssk()->__mptcp_subflow_disconnect()->tcp_disconnect()
clears SOCK_DONE on the subflow. It keeps sk_err, which tcp_reset() set
to EPIPE in CLOSE_WAIT.

The accept() caller owns the msk, so the error report is deferred as
MPTCP_ERROR_REPORT. Then at release_sock():

mptcp_release_cb()
  __mptcp_error_report()
    __mptcp_subflow_error_report()

This skips the new SOCK_DONE propagation, because the subflow flag is
already cleared, and sets sk_err = EPIPE on the msk.

mptcp_worker() then bails out on TCPF_CLOSE, so nothing corrects this
later. Doesn't mptcp_recvmsg() then return the data followed by -EPIPE
instead of EOF? The commit message says this case is fixed.

The non-fallback case looks similar. Data, a DATA_FIN and an MP_FASTCLOSE
can all arrive before accept(), with the worker not yet run. In that case
mptcp_check_fastclose() and mptcp_check_data_fin() are never called, and
recv() returns -ENOTCONN after the data instead of EOF.

Could the pending DATA_FIN be processed before mptcp_set_state(newsk,
TCP_CLOSE) in mptcp_stream_accept()?

>  
>  	__mptcp_close_ssk(sk, ssk, subflow, MPTCP_CF_PUSH);
>  }

[Severity: Low]
Can the lockless READ_ONCE(msk->rcv_data_fin) check in mptcp_close_ssk()
race with the subflow side?

The check runs before lock_sock_nested() in __mptcp_close_ssk() takes the
first subflow's lock. The emulated DATA_FIN is written from the subflow's
softirq / state_change context:

subflow_sched_work_if_closed()
  mptcp_update_rcv_data_fin()

and the msk lock does not exclude that path.

mptcp_pm_nl_subflow_destroy_doit() in net/mptcp/pm_userspace.c holds only
the msk lock and has no fallback check. It can select msk->first and
does:

	mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN);
	mptcp_close_ssk(sk, ssk, mptcp_subflow_ctx(ssk));

Consider this interleaving:

1. mptcp_close_ssk() reads rcv_data_fin == 0 and is then preempted.

2. The subflow receives a FIN (tcp_fin() sets SOCK_DONE), then a RST.
   sk_err is set and the error report is deferred as MPTCP_ERROR_REPORT.
   tcp_done() moves the subflow to TCP_CLOSE, and
   subflow_sched_work_if_closed() sets the dummy rcv_data_fin.

3. __mptcp_close_ssk() locks the subflow, sees TCP_CLOSE and calls
   tcp_disconnect(), which clears SOCK_DONE.

4. At release_sock(msk), __mptcp_subflow_error_report() finds no
   SOCK_DONE on the subflow. It moves the msk to TCP_CLOSE and sets
   sk_err.

mptcp_check_data_fin() never runs on this path, so recv() would return
the error instead of EOF.

Moving the MPTCP_WORK_CLOSE_SUBFLOW bit after the dummy DATA_FIN in
subflow_sched_work_if_closed() only orders the worker runs that the bit
triggers, so it does not help this caller.

This is a rare corner case. It needs a userspace PM (CAP_NET_ADMIN)
tearing down the only subflow of a fallback connection, plus precisely
timed peer packets.

Would it make sense to re-check rcv_data_fin under the subflow lock
before disconnecting, or to stop relying on SOCK_DONE surviving on the
subflow?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-net-mptcp-misc-fixes-7-4-rc7-v1-0-9f03efcb1a17%40kernel.org

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

Thread overview: 16+ 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-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-02 21:29 ` [PATCH net 4/9] mptcp: count orphans as TCP does Matthieu Baerts (NGI0)
2026-12-03 21:51   ` netdev-bot+sashiko
2026-12-02 21:29 ` [PATCH net 5/9] mptcp: return EOF after a DATA_FIN, " Matthieu Baerts (NGI0)
2026-12-03 21:51   ` netdev-bot+sashiko [this message]
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-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-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)

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=179633471320.3146.5929327584163174012@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dcaratti@redhat.com \
    --cc=edumazet@kernel.org \
    --cc=geliang@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=martineau@kernel.org \
    --cc=mason@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=willemb@google.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox