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 v2 61/62] mptcp: report errors as TCP does when closing
Date: Sat, 21 Nov 2026 10:30:12 +0000	[thread overview]
Message-ID: <sashiko-outbox-226941@kernel.org> (raw)
In-Reply-To: <20261121-mptcp-cmason-fixes-v2-61-00327fd1de1f@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: tcp_disconnect() clears SOCK_DONE before
  mptcp_check_rcv_close()
- [Medium] mptcp: dummy fallback DATA_FIN changes state before
  mptcp_close_last_err()
- [Medium] mptcp: missing mptcp_check_data_fin_ack() before
  mptcp_close_last_err()
--

commit 0c5fc2bb3f82340912e87636cc6d5fef891b87cb
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 to set SHUTDOWN_MASK and populate sk_err based on the subflow error
or MPTCP socket state, 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 1088caa788f60..5733ab548d12d 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c

[ ... ]

> @@ -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) {
>  			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]
Can a fallback socket closed by a clean FIN report EPIPE or ECONNRESET
from recv() instead of EOF here?

When ssk is msk->first and dispose_it is false, earlier in
__mptcp_close_ssk() the call to __mptcp_subflow_disconnect() ->
tcp_disconnect() clears SOCK_DONE on msk->first.  When
mptcp_check_rcv_close() then drains the backlog and calls
mptcp_check_data_fin(), sock_flag(msk->first, SOCK_DONE) is already false:

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

Because SOCK_DONE is not copied to sk, and mptcp_close_last_err() then sets
sk->sk_err to EPIPE or ECONNRESET (when sk transitions to TCP_CLOSE_WAIT or
TCP_CLOSING), mptcp_recvmsg() sees !sock_flag(sk, SOCK_DONE) and returns
the error instead of 0.

[Severity: Medium]
Does calling mptcp_check_rcv_close() without also checking
mptcp_check_data_fin_ack() cause a cleanly closed connection to report
ECONNRESET?

If sk is in TCP_LAST_ACK, TCP_CLOSING, or TCP_FIN_WAIT1 and the peer's
DATA_ACK acknowledging our DATA_FIN has already updated msk->snd_una in
softirq before __mptcp_close_ssk() runs, mptcp_check_rcv_close() only
checks rcv_data_fin and rcv_fastclose.  Without mptcp_check_data_fin_ack()
advancing sk->sk_state to TCP_CLOSE (or to TCP_FIN_WAIT2 before
mptcp_check_data_fin() moves it to TCP_CLOSE), sk->sk_state != TCP_CLOSE
remains true and mptcp_close_last_err() sets sk->sk_err to ECONNRESET even
though the DATA_FIN handshake completed cleanly.

Also, because this branch is skipped when sk->sk_state == TCP_ESTABLISHED,
an accepted socket in TCP_ESTABLISHED that receives final data, DATA_FIN
(or MP_FASTCLOSE), and subflow close in its backlog while locked by
mptcp_worker() will skip mptcp_check_rcv_close() and start the close
timeout timer instead of processing the backlog and closing immediately.

> @@ -3085,20 +3139,10 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)
>  		unlock_sock_fast(tcp_sk, slow);
>  	}
>  
> -	/* Mirror the tcp_reset() error propagation */
> -	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:
> +	if (sk->sk_state == TCP_CLOSE)
>  		return;
> -	default:
> -		WRITE_ONCE(sk->sk_err, ECONNRESET);
> -	}
>  
> +	WRITE_ONCE(sk->sk_err, mptcp_reset_err(sk));
>  	mptcp_set_state(sk, TCP_CLOSE);
>  	WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
>  	smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
> @@ -3416,8 +3460,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]
Can a thread in mptcp_poll() or getsockopt(SO_ERROR) be woken on close
timeout before mptcp_close_err() publishes ETIMEDOUT and SHUTDOWN_MASK?

kworker                               CPU1
mptcp_worker()
  mptcp_do_fastclose(sk)
    mptcp_set_state(sk, TCP_CLOSE)
  __mptcp_close_ssk(sk, ...)
    if (sk->sk_state == TCP_CLOSE)
      mptcp_close_wake_up(sk)
                                      mptcp_poll()
                                        state == TCP_CLOSE
                                        sk_shutdown == 0, sk_err == 0
                                        <-- misses EPOLLERR/EPOLLIN/EPOLLOUT
  mptcp_close_err(sk, ETIMEDOUT)

mptcp_close_err() writes sk_err and SHUTDOWN_MASK before setting TCP_CLOSE
and waking waiters so lockless pollers see a consistent state.  However, on
close timeout, mptcp_do_fastclose() already sets TCP_CLOSE, and
__mptcp_close_ssk() then hits the new sk->sk_state == TCP_CLOSE branch and
calls mptcp_close_wake_up() while sk_err and sk_shutdown are still 0.  In
mptcp_check_fastclose() above, mptcp_set_state(sk, TCP_CLOSE) is likewise
called before WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK).

> @@ -4768,8 +4811,11 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
>  		 */
>  		if (unlikely(inet_sk_state_load(msk->first) == TCP_CLOSE)) {
>  			if (unlikely(list_is_singular(&msk->conn_list))) {
> +				int err = READ_ONCE(msk->first->sk_err);
> +
>  				mptcp_check_rcv_close(newsk);
> -				mptcp_set_state(newsk, TCP_CLOSE);
> +				if (newsk->sk_state != TCP_CLOSE)
> +					mptcp_close_last_err(newsk, err);
>  			}
>  			mptcp_close_ssk(newsk, msk->first,
>  					mptcp_subflow_ctx(msk->first));

[Severity: Medium]
On a fallback socket closed by a TCP reset or timeout without a FIN, does
mptcp_check_rcv_close() corrupt the state before mptcp_close_last_err()
maps the error?

When a fallback subflow reaches TCP_CLOSE, subflow_sched_work_if_closed()
emulates a dummy rcv_data_fin = 1 even if no FIN was received:

net/mptcp/subflow.c:subflow_sched_work_if_closed() {
    ...
	if (__mptcp_check_fallback(msk) && subflow_is_done(ssk) &&
	    msk->first == ssk &&
	    mptcp_update_rcv_data_fin(msk, subflow->map_seq +
				      subflow->map_data_len, true))
		mptcp_schedule_work(sk);
    ...
}

When mptcp_check_data_fin() processes that dummy rcv_data_fin (here in
mptcp_stream_accept(), in __mptcp_close_ssk(), or earlier in
mptcp_worker()), it leaves SOCK_DONE unset on sk because msk->first lacks
SOCK_DONE, yet it still advances sk->sk_state from TCP_ESTABLISHED to
TCP_CLOSE_WAIT, or from TCP_FIN_WAIT2 to TCP_CLOSE.  As a result, a TCP RST
in TCP_ESTABLISHED sees TCP_CLOSE_WAIT in mptcp_close_last_err() and
reports EPIPE instead of ECONNRESET, and a reset or timeout in
TCP_FIN_WAIT2 sees sk->sk_state == TCP_CLOSE and skips
mptcp_close_last_err() completely.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f@kernel.org?part=61

  reply	other threads:[~2026-11-21 10:30 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21  9:40 [PATCH mptcp-net v2 00/62] mptcp: misc fixes Matthieu Baerts (NGI0)
2026-11-21  9:40 ` [PATCH mptcp-net v2 01/62] tcp: drain the queues of a listen() that fails Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 02/62] mptcp: " Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 03/62] mptcp: clear inet_opt in the child of an IPv6 listener Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 04/62] mptcp: pm: work on a copy of the received RM_ADDR list Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 05/62] mptcp: pm: don't drop an RM_ADDR behind a pending one Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 06/62] mptcp: pm: don't drop an RM_ADDR because of an ADD_ADDR Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 07/62] mptcp: pm: keep an RM_ADDR when computing the MSS Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 08/62] mptcp: arm the rtx timer if a push leaves data behind Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 09/62] mptcp: force the charge for the first skb of a subflow Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 10/62] mptcp: leave an orphan's DATA_FIN to the worker Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 11/62] mptcp: don't leak an orphan when the PM closes its last subflow Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 12/62] mptcp: keep an orphan while it can send its data Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 13/62] mptcp: limit an orphan probing a zero window Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 14/62] mptcp: count orphans as TCP does Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 15/62] mptcp: return EOF after a DATA_FIN, " Matthieu Baerts (NGI0)
2026-11-21 10:25   ` sashiko-bot
2026-11-21  9:41 ` [PATCH mptcp-net v2 16/62] mptcp: let TCP send orphan data after fallback Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 17/62] mptcp: reset the subflow on abort " Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 18/62] mptcp: wake up blocked senders when no sf left Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 19/62] mptcp: set SEND_SHUTDOWN on close by an sf error Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 20/62] mptcp: start close timeout on initial sf shutdown Matthieu Baerts (NGI0)
2026-11-21 10:20   ` sashiko-bot
2026-11-21  9:41 ` [PATCH mptcp-net v2 21/62] mptcp: process a DATA_FIN received with old data Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 22/62] mptcp: no sf left: process pending MP_FASTCLOSE Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 23/62] mptcp: no sf left: process pending DATA_FIN Matthieu Baerts (NGI0)
2026-11-21 10:17   ` sashiko-bot
2026-11-21  9:41 ` [PATCH mptcp-net v2 24/62] mptcp: process pending close events at accept() Matthieu Baerts (NGI0)
2026-11-21 10:13   ` sashiko-bot
2026-11-21  9:41 ` [PATCH mptcp-net v2 25/62] mptcp: clear sk_err on connect(), as TCP does Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 26/62] mptcp: clear DEFER_CONNECT on disconnect Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 27/62] mptcp: report sf aborts during deferred connect Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 28/62] mptcp: no fastclose reset from SYN_SENT subflows Matthieu Baerts (NGI0)
2026-11-21 10:11   ` sashiko-bot
2026-11-21  9:41 ` [PATCH mptcp-net v2 29/62] mptcp: keep listening after MSG_FASTOPEN errors Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 30/62] mptcp: don't inherit fastopening from a listener Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 31/62] mptcp: drop non-MP_JOIN cookie ACKs on PM listeners Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 32/62] net: add __sk_net_refcnt_upgrade() with a GFP mask Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 33/62] mptcp: pm: don't let listeners pin their netns Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 34/62] mptcp: close a subflow reset for a bad mapping Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 35/62] mptcp: initialize drop_req in subflow_init_req() Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 36/62] mptcp: pm: kernel: count endpoint listeners as sockets in use Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 37/62] mptcp: count a listener once when listen() is called again Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 38/62] mptcp: send the infinite map in a single segment Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 39/62] mptcp: keep room for infinite map after fallback Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 40/62] mptcp: do not fallback while old data is in flight Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 41/62] mptcp: stop resending data to a peer that fell back Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 42/62] mptcp: don't resend data acked without MPTCP opts Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 43/62] mptcp: pm: kernel: don't count signal+subflow ID 0 endp Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 44/62] selftests: mptcp: join: check re-adding " Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 45/62] tcp: do not pass a BPF reqsk to an MPTCP listener Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 46/62] mptcp: reclaim forward memory after coalescing skbs Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 47/62] mptcp: don't charge a shared page twice at accept() Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 48/62] mptcp: don't charge the backlog " Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 49/62] mptcp: don't charge a subflow twice when it joins during accept() Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 50/62] mptcp: continue the last mapping after a fallback Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 51/62] mptcp: keep the first byte after a simult connect Matthieu Baerts (NGI0)
2026-11-21 10:31   ` sashiko-bot
2026-11-21  9:41 ` [PATCH mptcp-net v2 52/62] mptcp: move to ESTABLISHED " Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 53/62] mptcp: fix MSG_PEEK after a partly peeked skb Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 54/62] mptcp: send the DATA_ACK after moving the backlog Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 55/62] selftests: mptcp: join: infinite map: no spurious rtx Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 56/62] selftests: mptcp: connect: trunc: wait for acks Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 57/62] mptcp: order write_seq and DATA_FIN flag for fallback Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 58/62] Squash to "bpf: Add mptcp packet scheduler struct_ops" Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-net v2 59/62] Squash to "bpf: Export mptcp packet scheduler helpers" Matthieu Baerts (NGI0)
2026-11-21 10:21   ` sashiko-bot
2026-11-21  9:41 ` [PATCH mptcp-next mptcp-net v2 60/62] mptcp: push pending data after a fallback on reception Matthieu Baerts (NGI0)
2026-11-21  9:41 ` [PATCH mptcp-next mptcp-net v2 61/62] mptcp: report errors as TCP does when closing Matthieu Baerts (NGI0)
2026-11-21 10:30   ` sashiko-bot [this message]
2026-11-21  9:42 ` [PATCH RFC mptcp-next mptcp-net v2 62/62] mptcp: reset when the DSS disappears after a DATA_ACK Matthieu Baerts (NGI0)
2026-11-21 10:20   ` sashiko-bot

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-226941@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.