All of lore.kernel.org
 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 v4 17/20] mptcp: report errors as TCP does when closing
Date: Fri, 27 Nov 2026 20:39:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-238268@kernel.org> (raw)
In-Reply-To: <20261127-mptcp-cmason-fixes-v4-17-3f393ea8c48d@kernel.org>

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

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

mptcp: report errors as TCP does when closing

This commit updates MPTCP socket closure on close timeouts and last-subflow
closure outside TCP_ESTABLISHED to set SHUTDOWN_MASK and report errors based
on the last subflow error and MPTCP socket state, matching TCP behavior.

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

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 64fc04ea997c8..d8661fba643a9 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c

[ ... ]

> @@ -2818,7 +2868,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
>  {
>  	struct mptcp_sock *msk = mptcp_sk(sk);
>  	bool dispose_it, need_push = false;
> -	int fwd_remaining;
> +	int fwd_remaining, ssk_err;
>  
>  	/* Do not pass RX data to the msk, even if the subflow socket is not
>  	 * going to be freed (i.e. even for the first subflow on graceful
> @@ -2826,6 +2876,8 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
>  	 */
>  	lock_sock_nested(ssk, SINGLE_DEPTH_NESTING);
>  	subflow->closing = 1;
> +	/* in case it is the last subflow: before its disconnect or dispose */
> +	ssk_err = READ_ONCE(ssk->sk_err);

[Severity: Medium]
On a fallback socket, if msk->first is closed by a TCP RST without a prior
FIN while mptcp_worker() holds lock_sock(sk), can this report EPIPE instead
of ECONNRESET and then report the error a second time on release_sock(sk)?

When the reset arrives in softirq while sk is owned, subflow_error_report()
defers MPTCP_ERROR_REPORT to mptcp_release_cb() (leaving ssk->sk_err set to
ECONNRESET), and subflow_sched_work_if_closed() emulates a dummy DATA_FIN
because ssk->sk_state is TCP_CLOSE.  Before __mptcp_close_ssk() runs,
mptcp_check_data_fin() processes that dummy rcv_data_fin and moves
sk->sk_state from TCP_ESTABLISHED to TCP_CLOSE_WAIT (or from TCP_FIN_WAIT2
to TCP_CLOSE) even when SOCK_DONE is not set on msk->first:

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;
    ...
}

In __mptcp_close_ssk(), dispose_it is false for msk->first, so it jumps to
out: without calling __mptcp_subflow_error_report().  In TCP_CLOSE_WAIT,
mptcp_close_last_err(sk, ECONNRESET) then maps ECONNRESET through
mptcp_reset_err(sk) to EPIPE (or in TCP_FIN_WAIT2 finds sk->sk_state
already in TCP_CLOSE and wakes waiters with sk_err == 0).  Because
ssk->sk_err was only read with READ_ONCE() and not consumed,
mptcp_release_cb() later runs __mptcp_error_report(sk), which consumes
ssk->sk_err, overwrites sk->sk_err with ECONNRESET, and calls
sk_error_report(sk) a second time.

[ ... ]

> @@ -2914,13 +2966,17 @@ 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) {
>  			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);
> +			/* the ack of our DATA_FIN might not be processed yet */
> +			mptcp_check_data_fin_ack(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]
Does gating mptcp_check_rcv_close(sk) behind sk->sk_state != TCP_ESTABLISHED
miss a pending DATA_FIN or MP_FASTCLOSE when the last subflow of an
accepted, non-fallback socket closes?

If final data with DATA_FIN and a subflow close arrive in softirq while
mptcp_worker() holds lock_sock(sk), the data sits in msk->backlog_list, so
mptcp_check_data_fin() in mptcp_worker() cannot advance msk->ack_seq to
msk->rcv_data_fin_seq and sk->sk_state stays TCP_ESTABLISHED (the same
happens if DATA_FIN or MP_FASTCLOSE arrives after mptcp_worker() has
already run mptcp_check_fastclose() and mptcp_check_data_fin()).  Because
mptcp_close_ssk() only spools the backlog beforehand when
__mptcp_check_fallback(msk) is true, __mptcp_close_ssk() sees
sk->sk_state == TCP_ESTABLISHED, skips mptcp_check_rcv_close(sk) and
mptcp_close_last_err(), and starts the close timeout timer instead.  When
release_sock(sk) subsequently drains msk->backlog_list via
mptcp_release_cb() -> __mptcp_move_skbs(), mptcp_check_data_fin() moves
sk->sk_state to TCP_CLOSE_WAIT after subflow->close_event_done is already
set, leaving the socket stranded in TCP_CLOSE_WAIT with no subflows until
the close timeout expires and reports ETIMEDOUT instead of EPIPE.

Calling mptcp_check_rcv_close(sk) before checking sk->sk_state in the
all-subflows-closed block would process the queued DATA_FIN or fastclose
first.

[ ... ]

> @@ -3450,8 +3496,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]
When the close timeout expires here, doesn't __mptcp_close_ssk() wake
pollers after mptcp_do_fastclose() sets TCP_CLOSE but before
mptcp_close_err() publishes ETIMEDOUT and SHUTDOWN_MASK?

kworker (mptcp_worker)            CPU1
----------------------            ----
mptcp_do_fastclose(sk)
  mptcp_set_state(sk, TCP_CLOSE)
__mptcp_close_ssk(...)
  if (sk->sk_state == TCP_CLOSE)
    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)
  WRITE_ONCE(sk->sk_err, ETIMEDOUT)
  smp_wmb()
  WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK)

Because mptcp_poll() and sk_getsockopt(SO_ERROR) run without locking sk,
a waiter woken by __mptcp_close_ssk() can see EPOLLHUP without EPOLLERR,
EPOLLIN or EPOLLOUT, and read SO_ERROR == 0 instead of ETIMEDOUT.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-mptcp-cmason-fixes-v4-0-3f393ea8c48d@kernel.org?part=17

  reply	other threads:[~2026-11-27 20:39 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 20:01 [PATCH mptcp-net v4 00/20] mptcp: misc fixes Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-net v4 01/20] mptcp: reset MP_JOIN subflows on simult connect Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-net v4 02/20] mptcp: keep the first byte after a " Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-net v4 03/20] mptcp: move to ESTABLISHED " Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-net v4 04/20] mptcp: fix MSG_PEEK after a partly peeked skb Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-net v4 05/20] mptcp: send the DATA_ACK after moving the backlog Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-net v4 06/20] selftests: mptcp: join: infinite map: no spurious rtx Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-net v4 07/20] selftests: mptcp: connect: trunc: wait for acks Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-net v4 08/20] selftests: mptcp: connect: splice: handle MPTFO Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-net v4 09/20] selftests: mptcp: diag: wait longer before closing Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-net v4 10/20] mptcp: order write_seq and DATA_FIN flag Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-net v4 11/20] mptcp: order write_seq and DATA_FIN flag for fallback Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-net v4 12/20] mptcp: reset the rtx interval to the min RTO Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-net v4 13/20] mptcp: sched: avoid truncating the pacing rate in the scheduler Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-net v4 14/20] Squash to "bpf: Add mptcp packet scheduler struct_ops" Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-net v4 15/20] Squash to "bpf: Export mptcp packet scheduler helpers" Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-next mptcp-net v4 16/20] mptcp: push pending data after a fallback on reception Matthieu Baerts (NGI0)
2026-11-27 20:29   ` sashiko-bot
2026-11-27 20:01 ` [PATCH mptcp-next mptcp-net v4 17/20] mptcp: report errors as TCP does when closing Matthieu Baerts (NGI0)
2026-11-27 20:39   ` sashiko-bot [this message]
2026-11-27 20:01 ` [PATCH mptcp-next mptcp-net v4 18/20] mptcp: trace: name all the mapping statuses Matthieu Baerts (NGI0)
2026-11-27 20:01 ` [PATCH mptcp-next mptcp-net v4 19/20] mptcp: set ECONNRESET on disconnect, as TCP does Matthieu Baerts (NGI0)
2026-11-27 20:24   ` sashiko-bot
2026-11-27 20:01 ` [PATCH RFC mptcp-next mptcp-net v4 20/20] mptcp: reset when the DSS disappears after a DATA_ACK 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=sashiko-outbox-238268@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.