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 v9 07/11] mptcp: implement peek_len for proto_ops
Date: Thu, 27 Aug 2026 11:10:30 +0000	[thread overview]
Message-ID: <20260827111030.BE0091F000E9@smtp.kernel.org> (raw)
In-Reply-To: <72dfb12c36ea32e58f8f85f55c94101fca02702e.1787827525.git.tanggeliang@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Lockless read of 64-bit `copied_seq` causes torn reads on 32-bit systems and concurrent update races, leading to spurious INT_MAX return values.
- [High] Subtracting 1 for a FIN flag breaks EOF detection for stream consumers by reporting 0 instead of 1.
--

commit 7df02914f0a616d203067af77b84f00d4f6bc119
Author: Geliang Tang <geliang@kernel.org>
mptcp: implement peek_len for proto_ops

This commit adds mptcp_inq() to compute the readable bytes at the MPTCP
level and derives the count from mptcp_inq_hint(). It wires mptcp_inq()
into mptcp_peek_len() and assigns .peek_len in the stream operations
so upper layers get the in-queue byte count.

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index cc8747162cca9..9b9ace7cb977d 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -4814,6 +4814,37 @@ static ssize_t mptcp_splice_read(struct socket *sock, loff_t *ppos,
>  	return ret;
>  }
>  
> +static int mptcp_inq(struct sock *sk)
> +{
> +	const struct mptcp_sock *msk = mptcp_sk(sk);
> +	int answ;
> +
> +	if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) {
> +		answ = 0;
> +	} else if (test_bit(MPTCP_SYNC_SEQ, &msk->cb_flags)) {
> +		answ = 0;
> +	} else {
> +		u64 hint_val;
> +
> +		hint_val = atomic64_read(&msk->ack_seq) - msk->copied_seq;
> +		if (hint_val >= INT_MAX)
> +			hint_val = INT_MAX;

[Severity: High]
Could this unprotected 64-bit read of copied_seq cause torn reads on 32-bit
systems?

If a concurrent caller invokes poll or a vhost loop calls .peek_len while
another thread is calling recvmsg(), the unsynchronized read of ack_seq and
copied_seq can result in an inconsistent state and cause an underflow.

This would then trigger the INT_MAX clamp, leading .peek_len to incorrectly
report a massive amount of queued data (up to 2GB). Is there a risk that this
causes stream consumers to allocate excessive memory or loop endlessly
expecting data?

> +
> +		answ = (unsigned int)hint_val;
> +		if (answ &&
> +		    (sk->sk_state == TCP_CLOSE ||
> +		     (sk->sk_shutdown & RCV_SHUTDOWN)))
> +			answ--;

[Severity: High]
Does subtracting 1 here break EOF detection for stream consumers?

When the peer sends a FIN and the local MPTCP stack sets RCV_SHUTDOWN, this
logic actively suppresses the 1-byte EOF signal by reporting 0 instead of 1.

Callers relying on .peek_len for stream parsing (like strparser or KCM) might
enter an infinite wait or hang because they will see 0 data available and
wait for more data that will never arrive, instead of issuing the final
recvmsg() to observe EOF.

[ ... ]

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

  reply	other threads:[~2026-08-27 11:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27 10:57 [PATCH mptcp-next v9 00/11] Reduce the differences between TCP and MPTCP for TLS usage Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 01/11] mptcp: use atomic64_t for locklessly accessed u64 fields Geliang Tang
2026-08-27 11:15   ` sashiko-bot
2026-08-27 10:57 ` [PATCH mptcp-next v9 02/11] mptcp: drop the mptcp_ooo_try_coalesce() helper Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 03/11] mptcp: drop the cant_coalesce CB field Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 04/11] mptcp: remove CB offset field Geliang Tang
2026-08-27 11:13   ` sashiko-bot
2026-08-27 10:57 ` [PATCH mptcp-next v9 05/11] mptcp: sync mptcp skb cb layout with tcp one Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 06/11] mptcp: defer read_sock cleanup to mptcp_worker Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 07/11] mptcp: implement peek_len for proto_ops Geliang Tang
2026-08-27 11:10   ` sashiko-bot [this message]
2026-08-27 10:57 ` [PATCH mptcp-next v9 08/11] mptcp: add sendmsg_locked to proto_ops Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 09/11] mptcp: track app-limited state in mptcp_sendmsg Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 10/11] selftests: mptcp: sockopt: check app_limited Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 11/11] Squash to "selftests/bpf: Add bpf_burst scheduler & test" Geliang Tang
2026-08-27 11:17   ` sashiko-bot
2026-08-27 12:13 ` [PATCH mptcp-next v9 00/11] 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=20260827111030.BE0091F000E9@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