MPTCP Linux Development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Geliang Tang" <geliang@kernel.org>
Cc: mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v8 1/8] mptcp: use atomic64_t for msk->ack_seq
Date: Tue, 25 Aug 2026 08:14:54 +0000	[thread overview]
Message-ID: <20260825081455.1BA301F000E9@smtp.kernel.org> (raw)
In-Reply-To: <1d4ae9189eece66deaf4e7c47ff2e705341e31ff.1787644449.git.tanggeliang@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Torn reads on locklessly accessed `u64` variables (`bytes_received`, `bytes_consumed`, `write_seq`, `snd_nxt`) on 32-bit architectures.
--

--- Patch [1]: [PATCH mptcp-next v8 1/8] mptcp: use atomic64_t for msk->ack_seq ---
commit 6ecb7c718880f7f40ce17752ce61e7a9dfad9bea
Author: Geliang Tang <geliang@kernel.org>

mptcp: use atomic64_t for msk->ack_seq

This commit converts msk->ack_seq from u64 to atomic64_t to guarantee
tear-free accesses on all architectures. It also caches the atomic64_read()
value in local variables in __mptcp_move_skb() and __mptcp_ofo_queue()
to avoid inconsistent repeated reads.

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index f22d64ab1c53b..88bdb65a9e87e 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -464,7 +466,7 @@ static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb)
>  		}
>  
>  		msk->bytes_received += copy_len;
> -		WRITE_ONCE(msk->ack_seq, msk->ack_seq + copy_len);
> +		atomic64_add(copy_len, &msk->ack_seq);

[Severity: High]
This isn't a bug introduced by this patch, but since it explicitly sets out
to fix 32-bit torn reads for msk->ack_seq, should the other 64-bit socket
state variables also be converted?

For example, msk->bytes_received is updated here using a plain non-atomic +=
operation, and it is read locklessly in mptcp_data_avail():

net/mptcp/protocol.h:mptcp_data_avail() {
	...
	return READ_ONCE(msk->bytes_received) - READ_ONCE(msk->bytes_consumed);
}

Similarly, write_seq and snd_nxt are read locklessly:

net/mptcp/protocol.h:mptcp_stream_memory_free() {
	...
	notsent_bytes = READ_ONCE(msk->write_seq) - READ_ONCE(msk->snd_nxt);
}

A torn read on these 64-bit variables can produce a massively incorrect
value. When a counter crosses a 4GB boundary (e.g., transitioning from
0x00000000FFFFFFFF to 0x0000000100000000), a concurrent 32-bit read might see
0x00000001FFFFFFFF. In mptcp_poll(), this could lead to incorrectly
calculated data_avail or notsent_bytes, causing spurious EPOLLIN/EPOLLOUT
events or missing events that permanently stall the connection.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1787644449.git.tanggeliang@kylinos.cn?part=1

  reply	other threads:[~2026-08-25  8:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25  7:57 [PATCH mptcp-next v8 0/8] Reduce the differences between TCP and MPTCP for TLS usage Geliang Tang
2026-08-25  7:57 ` [PATCH mptcp-next v8 1/8] mptcp: use atomic64_t for msk->ack_seq Geliang Tang
2026-08-25  8:14   ` sashiko-bot [this message]
2026-08-25  7:57 ` [PATCH mptcp-next v8 2/8] mptcp: drop the mptcp_ooo_try_coalesce() helper Geliang Tang
2026-08-25  7:57 ` [PATCH mptcp-next v8 3/8] mptcp: drop the cant_coalesce CB field Geliang Tang
2026-08-25  7:57 ` [PATCH mptcp-next v8 4/8] mptcp: remove CB offset field Geliang Tang
2026-08-25  8:17   ` sashiko-bot
2026-08-25  7:57 ` [PATCH mptcp-next v8 5/8] mptcp: sync mptcp skb cb layout with tcp one Geliang Tang
2026-08-25  7:57 ` [PATCH mptcp-next v8 6/8] mptcp: defer read_sock cleanup to mptcp_worker Geliang Tang
2026-08-25  8:14   ` sashiko-bot
2026-08-25  7:57 ` [PATCH mptcp-next v8 7/8] mptcp: track app-limited state in mptcp_sendmsg Geliang Tang
2026-08-25  7:57 ` [PATCH mptcp-next v8 8/8] selftests: mptcp: sockopt: check app_limited Geliang Tang
2026-08-25  9:05 ` [PATCH mptcp-next v8 0/8] Reduce the differences between TCP and MPTCP for TLS usage 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=20260825081455.1BA301F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=geliang@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