MPTCP Linux Development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>,
	"MPTCP Linux" <mptcp@lists.linux.dev>
Subject: Re: [PATCH mptcp-next mptcp-net v3 48/50] mptcp: report errors as TCP does when closing
Date: Tue, 24 Nov 2026 22:52:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-232164@kernel.org> (raw)
In-Reply-To: <20261124-mptcp-cmason-fixes-v3-48-416c0920c73f@kernel.org>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] mptcp: premature TCP_CLOSE and wakeup before
  mptcp_close_err() on timeout
- [Medium] mptcp: emulated fallback DATA_FIN on reset causes EPIPE in
  mptcp_close_last_err()
- [Medium] mptcp: missing mptcp_check_data_fin_ack() call in
  mptcp_check_rcv_close()
- [Medium] mptcp: skipped mptcp_check_rcv_close() in __mptcp_close_ssk()
  when ESTABLISHED
--

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

mptcp: report errors as TCP does when closing

This commit updates MPTCP socket closing paths to set SHUTDOWN_MASK and
propagate subflow or state-dependent socket errors when the last subflow
closes or the close timeout expires, matching tcp_done_with_error().

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

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 016b16b3cc925..0a7600aea181e 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -518,6 +518,56 @@ static void mptcp_close_wake_up(struct sock *sk)
>  		sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
>  }
>  
> +/* Mirror the tcp_reset() error propagation */
> +static int mptcp_reset_err(const struct sock *sk)
> +{
> +	int err;
> +
> +	switch (sk->sk_state) {
> +	case TCP_SYN_SENT:
> +		err = ECONNREFUSED;
> +		break;
> +	case TCP_CLOSE_WAIT:
> +		err = EPIPE;
> +		break;
> +	default:
> +		err = ECONNRESET;
> +	}
> +
> +	return err;
> +}
> +
> +/* No more data can be exchanged: report it, as tcp_done_with_error() does */
> +static void mptcp_close_err(struct sock *sk, int err)
> +{
> +	WRITE_ONCE(sk->sk_err, err);
> +	/* This barrier is coupled with smp_rmb() in mptcp_poll() */
> +	smp_wmb();
> +	WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
> +	mptcp_set_state(sk, TCP_CLOSE);
> +	if (sock_flag(sk, SOCK_DEAD))
> +		return;
> +
> +	mptcp_close_wake_up(sk);
> +	sk_error_report(sk);
> +}
> +
> +/* As TCP: the error of the last subflow, e.g. ETIMEDOUT, but after a reset
> + * (EBADMSG: by MPTCP) or without error, it depends on the msk state
> + */
> +static void mptcp_close_last_err(struct sock *sk, int err)
> +{
> +	switch (err) {
> +	case 0:
> +	case ECONNREFUSED:
> +	case ECONNRESET:
> +	case EPIPE:
> +	case EBADMSG:
> +		err = mptcp_reset_err(sk);
> +	}
> +	mptcp_close_err(sk, err);
> +}

[Severity: Medium]
Can mptcp_close_last_err() report EPIPE instead of ECONNRESET when a
fallen-back subflow is reset while mptcp_worker() holds the msk socket
lock?

When msk->first receives a TCP RST in TCP_ESTABLISHED while mptcp_worker()
holds lock_sock(sk), subflow_error_report() defers __mptcp_error_report()
via MPTCP_ERROR_REPORT, and subflow_sched_work_if_closed() sets
msk->rcv_data_fin = 1 and MPTCP_WORK_CLOSE_SUBFLOW because
subflow_is_done(ssk) is true on TCP_CLOSE:

net/mptcp/protocol.c:mptcp_check_data_fin() {
    ...
		/* on fallback, also emulated after a reset: check for a FIN */
		if (!__mptcp_check_fallback(msk) ||
		    (msk->first && sock_flag(msk->first, SOCK_DONE)))
			sock_set_flag(sk, SOCK_DONE);
		smp_mb__before_atomic(); /* SHUTDOWN must be visible first */

		switch (sk->sk_state) {
		case TCP_ESTABLISHED:
			mptcp_set_state(sk, TCP_CLOSE_WAIT);
			break;
    ...
}

Although mptcp_check_data_fin() avoids setting SOCK_DONE when the fallback
subflow was reset without a FIN, it still advances sk->sk_state from
TCP_ESTABLISHED to TCP_CLOSE_WAIT (or from TCP_FIN_WAIT2 to TCP_CLOSE)
before __mptcp_close_ssk() runs.  In __mptcp_close_ssk(), msk->first is
disconnected rather than disposed, so __mptcp_subflow_error_report() is
skipped and mptcp_close_last_err(sk, ECONNRESET) overwrites ECONNRESET
with mptcp_reset_err(sk) (EPIPE in TCP_CLOSE_WAIT) and wakes waiters
before release_sock(sk) runs __mptcp_error_report().  If sk was in
TCP_FIN_WAIT2, mptcp_check_data_fin() moves sk to TCP_CLOSE and wakes
waiters while sk->sk_err is still 0, and __mptcp_close_ssk() then skips
mptcp_close_last_err().

[ ... ]

> @@ -2905,13 +2957,15 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
>  			mptcp_set_close_tout(sk, tcp_jiffies32 -
>  					     (mptcp_close_timeout(sk) + 1));
>  			mptcp_schedule_work(sk);
> +		} else if (sk->sk_state == TCP_CLOSE) {
> +			mptcp_close_wake_up(sk);
>  		} else if (sk->sk_state != TCP_ESTABLISHED ||
>  			   msk->in_accept_queue) {

[Severity: Medium]
Does gating mptcp_check_rcv_close(sk) on sk->sk_state != TCP_ESTABLISHED
miss a pending DATA_FIN in msk->backlog_list (or a pending MP_FASTCLOSE)
when the last subflow closes on an accepted socket?

If the peer sends final data with DATA_FIN and closes or resets the only
subflow while mptcp_worker() holds lock_sock(sk), the incoming data sits
in msk->backlog_list while msk->rcv_data_fin is set, so
mptcp_check_data_fin() in mptcp_worker() cannot advance msk->ack_seq to
msk->rcv_data_fin_seq and leaves sk->sk_state in TCP_ESTABLISHED.  When
__mptcp_close_subflow() -> __mptcp_close_ssk() then runs on a non-fallback
socket, it skips this branch and starts the close timeout timer instead of
calling mptcp_check_rcv_close(sk) to spool the backlog, move sk to
TCP_CLOSE_WAIT, and close immediately via mptcp_close_last_err();
mptcp_release_cb() then transitions sk to TCP_CLOSE_WAIT with no subflows
left, leaving the socket to wait for the close timeout and fail with
ETIMEDOUT.

>  			mptcp_check_rcv_close(sk);
> -			mptcp_set_state(sk, TCP_CLOSE);
> -			WRITE_ONCE(sk->sk_shutdown,
> -				   sk->sk_shutdown | SEND_SHUTDOWN);
> -			mptcp_close_wake_up(sk);
> +			if (sk->sk_state == TCP_CLOSE)
> +				mptcp_close_wake_up(sk);
> +			else
> +				mptcp_close_last_err(sk, ssk_err);
>  		} else {
>  			mptcp_start_tout_timer(sk);
>  		}

[Severity: Medium]
Should mptcp_check_rcv_close(sk) also call mptcp_check_data_fin_ack(sk)
before __mptcp_close_ssk() checks whether sk->sk_state reached TCP_CLOSE?

When an incoming DATA_ACK acknowledges our outgoing DATA_FIN in softirq,
ack_update_msk() updates msk->snd_una and schedules mptcp_worker(), which
is the only caller of mptcp_check_data_fin_ack(sk).  If __mptcp_close_ssk()
runs on the last subflow while mptcp_pending_data_fin_ack(sk) is true in
TCP_LAST_ACK, TCP_CLOSING, or TCP_FIN_WAIT1 (for example, during
mptcp_pm_worker() or when the DATA_ACK and subflow close arrive after
mptcp_check_data_fin_ack() in mptcp_worker()), mptcp_check_rcv_close(sk)
only checks rcv_data_fin and rcv_fastclose, leaving sk->sk_state !=
TCP_CLOSE so mptcp_close_last_err() sets ECONNRESET on a cleanly closed
connection.

[ ... ]

> @@ -3441,8 +3485,7 @@ static void mptcp_worker(struct work_struct *work)
>  		mptcp_do_fastclose(sk);
>  		mptcp_for_each_subflow_safe(msk, subflow, tmp)
>  			__mptcp_close_ssk(sk, subflow->tcp_sock, subflow, 0);
> -		WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | SEND_SHUTDOWN);
> -		mptcp_close_wake_up(sk);
> +		mptcp_close_err(sk, ETIMEDOUT);
>  	}

[Severity: Medium]
Does calling mptcp_do_fastclose(sk) and __mptcp_close_ssk() before
mptcp_close_err(sk, ETIMEDOUT) wake lockless pollers and SO_ERROR readers
with sk->sk_state == TCP_CLOSE before sk->sk_err and SHUTDOWN_MASK are set?

mptcp_do_fastclose(sk) sets sk->sk_state to TCP_CLOSE while sk->sk_err is
still 0 and sk->sk_shutdown does not have SHUTDOWN_MASK, and
__mptcp_close_ssk() then hits the new sk->sk_state == TCP_CLOSE branch and
calls mptcp_close_wake_up(sk):

kworker                           CPU1
mptcp_worker()
  mptcp_do_fastclose(sk)
    mptcp_set_state(sk, TCP_CLOSE)
  __mptcp_close_ssk(sk, ...)
    mptcp_close_wake_up(sk)
                                  mptcp_poll() / getsockopt(SO_ERROR)
                                    state == TCP_CLOSE
                                    sk_shutdown == 0
                                    sk_err == 0  <-- misses ETIMEDOUT
  mptcp_close_err(sk, ETIMEDOUT)

A thread woken from poll() or calling getsockopt(SO_ERROR) before
mptcp_close_err() runs can observe TCP_CLOSE with sk_err == 0 and
sk_shutdown == 0, reporting EPOLLHUP without EPOLLERR, EPOLLIN, or
EPOLLOUT and returning 0 from SO_ERROR instead of ETIMEDOUT.
mptcp_check_fastclose() similarly calls mptcp_set_state(sk, TCP_CLOSE)
before WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK) and without the
smp_wmb() after writing sk->sk_err that mptcp_close_err() uses.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f@kernel.org?part=48

  reply	other threads:[~2026-11-24 22:52 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 01/50] mptcp: keep an orphan while it can send its data Matthieu Baerts (NGI0)
2026-11-25  1:16   ` Mat Martineau
2026-11-25  1:17     ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 02/50] mptcp: limit an orphan probing a zero window Matthieu Baerts (NGI0)
2026-11-25  1:19   ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 03/50] mptcp: count orphans as TCP does Matthieu Baerts (NGI0)
2026-11-25  1:21   ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 04/50] mptcp: return EOF after a DATA_FIN, " Matthieu Baerts (NGI0)
2026-11-26  1:57   ` Mat Martineau
2026-11-26  2:59     ` Geliang Tang
2026-11-26  8:06       ` Matthieu Baerts
2026-11-24 21:59 ` [PATCH mptcp-net v3 05/50] mptcp: let TCP send orphan data after fallback Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 06/50] mptcp: reset the subflow on abort " Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 07/50] mptcp: wake up blocked senders when no sf left Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 08/50] mptcp: set SEND_SHUTDOWN on close by an sf error Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 09/50] mptcp: start close timeout on initial sf shutdown Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 10/50] mptcp: process a DATA_FIN received with old data Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 11/50] mptcp: no sf left: process pending MP_FASTCLOSE Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 12/50] mptcp: no sf left: process pending DATA_FIN Matthieu Baerts (NGI0)
2026-11-24 22:33   ` sashiko-bot
2026-11-24 21:59 ` [PATCH mptcp-net v3 13/50] mptcp: process pending close events at accept() Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 14/50] mptcp: report errors received before accept() Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 15/50] mptcp: clear sk_err on connect(), as TCP does Matthieu Baerts (NGI0)
2026-11-26  6:40   ` Geliang Tang
2026-11-26  8:15     ` Matthieu Baerts
2026-11-24 21:59 ` [PATCH mptcp-net v3 16/50] mptcp: clear DEFER_CONNECT on disconnect Matthieu Baerts (NGI0)
2026-11-26  6:41   ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 17/50] mptcp: report sf aborts during deferred connect Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 18/50] mptcp: no fastclose reset from SYN_SENT subflows Matthieu Baerts (NGI0)
2026-11-26  7:04   ` Geliang Tang
2026-11-26  7:35     ` Matthieu Baerts
2026-11-26  8:02       ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 19/50] mptcp: fastopen: keep listeners and connections Matthieu Baerts (NGI0)
2026-11-26  8:20   ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 20/50] mptcp: don't inherit fastopening from a listener Matthieu Baerts (NGI0)
2026-11-26  7:07   ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 21/50] mptcp: drop non-MP_JOIN cookie ACKs on PM listeners Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 22/50] mptcp: close a subflow reset for a bad mapping Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 23/50] mptcp: pm: kernel: count endpoint listeners as sockets in use Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 24/50] mptcp: count a listener once when listen() is called again Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 25/50] mptcp: send the infinite map in a single segment Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 26/50] mptcp: keep room for infinite map after fallback Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 27/50] mptcp: do not fallback while old data is in flight Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 28/50] mptcp: stop resending data to a peer that fell back Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 29/50] mptcp: don't resend data acked without MPTCP opts Matthieu Baerts (NGI0)
2026-11-24 22:36   ` sashiko-bot
2026-11-24 21:59 ` [PATCH mptcp-net v3 30/50] mptcp: pm: kernel: don't count signal+subflow ID 0 endp Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 31/50] selftests: mptcp: join: check re-adding " Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 32/50] mptcp: reclaim forward memory after coalescing skbs Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 33/50] mptcp: don't charge a shared page twice at accept() Matthieu Baerts (NGI0)
2026-11-26  2:20   ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 34/50] mptcp: don't charge the backlog " Matthieu Baerts (NGI0)
2026-11-26  2:43   ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 35/50] mptcp: don't charge a subflow twice when it joins during accept() Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 36/50] mptcp: continue the last mapping after a fallback Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 37/50] mptcp: keep the first byte after a simult connect Matthieu Baerts (NGI0)
2026-11-24 22:45   ` sashiko-bot
2026-11-24 21:59 ` [PATCH mptcp-net v3 38/50] mptcp: move to ESTABLISHED " Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 39/50] mptcp: fix MSG_PEEK after a partly peeked skb Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 40/50] mptcp: send the DATA_ACK after moving the backlog Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 41/50] selftests: mptcp: join: infinite map: no spurious rtx Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 42/50] selftests: mptcp: connect: trunc: wait for acks Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-net v3 43/50] mptcp: order write_seq and DATA_FIN flag Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-net v3 44/50] mptcp: order write_seq and DATA_FIN flag for fallback Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-net v3 45/50] Squash to "bpf: Add mptcp packet scheduler struct_ops" Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-net v3 46/50] Squash to "bpf: Export mptcp packet scheduler helpers" Matthieu Baerts (NGI0)
2026-11-24 22:45   ` sashiko-bot
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 47/50] mptcp: push pending data after a fallback on reception Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 48/50] mptcp: report errors as TCP does when closing Matthieu Baerts (NGI0)
2026-11-24 22:52   ` sashiko-bot [this message]
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 49/50] mptcp: trace: name all the mapping statuses Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH RFC mptcp-next mptcp-net v3 50/50] mptcp: reset when the DSS disappears after a DATA_ACK Matthieu Baerts (NGI0)
2026-11-24 22:36   ` sashiko-bot
2026-11-25  0:39 ` [PATCH mptcp-net v3 00/50] mptcp: misc fixes MPTCP CI

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-232164@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox