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 v4 19/20] mptcp: set ECONNRESET on disconnect, as TCP does
Date: Fri, 27 Nov 2026 20:24:16 +0000	[thread overview]
Message-ID: <sashiko-outbox-238235@kernel.org> (raw)
In-Reply-To: <20261127-mptcp-cmason-fixes-v4-19-3f393ea8c48d@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mptcp: sk_err set after TCP_CLOSE and wakeup in
  mptcp_disconnect()
--

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

mptcp: set ECONNRESET on disconnect, as TCP does

This commit sets sk->sk_err to ECONNRESET in mptcp_disconnect() when an
active or partially closed MPTCP connection is aborted, matching
tcp_disconnect().

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index d8661fba643a9..fd6a72d375aac 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -3957,6 +3957,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)
>  {
>  	struct inet_connection_sock *icsk = inet_csk(sk);
>  	struct mptcp_sock *msk = mptcp_sk(sk);
> +	bool aborted;
>  
>  	/* We are on the fastopen error path. We can't call straight into the
>  	 * subflows cleanup code due to lock nesting (we are already under
> @@ -3965,6 +3966,13 @@ static int mptcp_disconnect(struct sock *sk, int flags)
>  	if (msk->fastopening)
>  		return -EBUSY;
>  
> +	/* as tcp_disconnect() */
> +	aborted = ((1 << sk->sk_state) &
> +		   (TCPF_SYN_SENT | TCPF_ESTABLISHED | TCPF_CLOSE_WAIT |
> +		    TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2)) ||
> +		  (((1 << sk->sk_state) & (TCPF_CLOSING | TCPF_LAST_ACK)) &&
> +		   msk->snd_nxt != msk->write_seq);
> +
>  	mptcp_check_listen_stop(sk);
>  	mptcp_set_state(sk, TCP_CLOSE);
>  	inet_clear_bit(DEFER_CONNECT, sk);
> @@ -4020,6 +4028,8 @@ static int mptcp_disconnect(struct sock *sk, int flags)
>  
>  	WRITE_ONCE(sk->sk_shutdown, 0);
>  	sock_reset_flag(sk, SOCK_DONE);
> +	if (aborted)
> +		WRITE_ONCE(sk->sk_err, ECONNRESET);
>  	sk_error_report(sk);
>  	return 0;
>  }

[Severity: Medium]
Can setting sk->sk_err at the end of mptcp_disconnect() cause concurrent
pollers to miss EPOLLERR?

mptcp_poll() runs locklessly: it loads sk->sk_state (setting EPOLLHUP on
TCP_CLOSE), executes smp_rmb(), and then reads sk->sk_err to set EPOLLERR.
Because mptcp_disconnect() sets TCP_CLOSE first and then calls
mptcp_destroy_common() -> __mptcp_close_ssk(), closing the last subflow
sees sk->sk_state == TCP_CLOSE and calls mptcp_close_wake_up(sk) before
sk->sk_err is written:

CPU0                                  CPU1
mptcp_disconnect(sk)
  mptcp_set_state(sk, TCP_CLOSE)
  ...
  mptcp_destroy_common(msk)
    __mptcp_close_ssk(...)
      if (sk->sk_state == TCP_CLOSE)
        mptcp_close_wake_up(sk)
          sk->sk_state_change(sk)
                                      /* woken in poll() / epoll_wait() */
                                      mptcp_poll()
                                        state = inet_sk_state_load(sk)
                                        /* state == TCP_CLOSE -> EPOLLHUP */
                                        smp_rmb()
                                        READ_ONCE(sk->sk_err) == 0
                                        /* returns without EPOLLERR */
  ...
  WRITE_ONCE(sk->sk_err, ECONNRESET)
  sk_error_report(sk)

A thread sleeping in poll(), select(), or epoll_wait() can wake up on
mptcp_close_wake_up(), observe TCP_CLOSE with sk->sk_err == 0, and return
EPOLLHUP without EPOLLERR.  Should WRITE_ONCE(sk->sk_err, ECONNRESET) (with
smp_wmb(), as in mptcp_close_err() and __mptcp_subflow_error_report())
happen before mptcp_set_state(sk, TCP_CLOSE)?

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

  reply	other threads:[~2026-11-27 20:24 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
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 [this message]
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-238235@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