From: sashiko-bot@kernel.org
To: "Geliang Tang" <geliang@kernel.org>
Cc: mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v11 07/10] mptcp: implement peek_len for proto_ops
Date: Sun, 30 Aug 2026 14:50:05 +0000 [thread overview]
Message-ID: <20260830145006.4A8DD1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <5333db5976d6a9fbfd18fb33eb017d7ab30d0f45.1788099847.git.tanggeliang@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing memory barriers between `ack_seq` and `SOCK_DONE` updates in `mptcp_check_data_fin()` and their lockless reads in `mptcp_inq()` allow `mptcp_inq()` to observe `SOCK_DONE` without observing the `ack_seq` increment, leading to an under-reporting of available data.
--
commit 3b3f825ecdc0054e45c6ee37b3404a7c1aeaead3
Author: Geliang Tang <geliang@kernel.org>
mptcp: implement peek_len for proto_ops
This commit introduces mptcp_inq() to compute readable bytes at the MPTCP
level using ack_seq and copied_seq. It returns 0 during handshakes and
subtracts 1 if a FIN is received (SOCK_DONE flag is set), mirroring
tcp_inq(). It is wired up as the .peek_len proto_op.
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 2c0822ef4ae3b..81452a2b6fd0c 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
[ ... ]
> @@ -4809,6 +4809,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 = READ_ONCE(msk->ack_seq) - READ_ONCE(msk->copied_seq);
> + if (hint_val >= INT_MAX)
> + hint_val = INT_MAX;
> +
> + answ = (unsigned int)hint_val;
> +
> + /* Subtract 1, if FIN was received. Mirror tcp_inq() */
> + if (answ && sock_flag(sk, SOCK_DONE))
> + answ--;
[Severity: High]
Could this lockless read observe SOCK_DONE without observing the updated
ack_seq?
In net/mptcp/protocol.c:mptcp_check_data_fin(), the write side updates
ack_seq and SOCK_DONE without a separating memory barrier:
WRITE_ONCE(msk->ack_seq, msk->ack_seq + 1);
WRITE_ONCE(msk->rcv_data_fin, 0);
WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | RCV_SHUTDOWN);
sock_set_flag(sk, SOCK_DONE);
smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
If mptcp_inq() is called locklessly (e.g., from strp_data_ready) concurrently
with mptcp_check_data_fin(), could the lack of an smp_wmb() on the write side
and an smp_rmb() on this read side allow the CPU to reorder operations?
If mptcp_inq() reads SOCK_DONE as true but reads the old, un-incremented
ack_seq, it would calculate the available bytes and erroneously subtract 1.
If only 1 byte of payload remains, returning 1 byte less causes it to return
0. This could cause the upper layer (like TLS or BPF sockmap/strparser) to
skip waking up the process, resulting in an infinite wait for data that will
never arrive. This could be triggered remotely by network traffic (a data FIN
packet) on an MPTCP socket, leading to a denial of service.
Should there be an smp_rmb() added here before checking SOCK_DONE, and an
smp_wmb() added to mptcp_check_data_fin() after incrementing ack_seq?
> + }
> +
> + return answ;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1788099847.git.tanggeliang@kylinos.cn?part=7
next prev parent reply other threads:[~2026-08-30 14:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-30 14:32 [PATCH mptcp-next v11 00/10] Reduce the differences between TCP and MPTCP for TLS usage Geliang Tang
2026-08-30 14:32 ` [PATCH mptcp-next v11 01/10] mptcp: drop the mptcp_ooo_try_coalesce() helper Geliang Tang
2026-08-30 14:32 ` [PATCH mptcp-next v11 02/10] mptcp: drop the cant_coalesce CB field Geliang Tang
2026-08-30 14:32 ` [PATCH mptcp-next v11 03/10] mptcp: remove CB offset field Geliang Tang
2026-08-30 14:32 ` [PATCH mptcp-next v11 04/10] mptcp: sync mptcp skb cb layout with tcp one Geliang Tang
2026-08-30 14:32 ` [PATCH mptcp-next v11 05/10] mptcp: defer read_sock cleanup to mptcp_worker Geliang Tang
2026-08-30 14:32 ` [PATCH mptcp-next v11 06/10] mptcp: align FIN handling with TCP via SOCK_DONE Geliang Tang
2026-08-30 14:32 ` [PATCH mptcp-next v11 07/10] mptcp: implement peek_len for proto_ops Geliang Tang
2026-08-30 14:50 ` sashiko-bot [this message]
2026-08-30 14:32 ` [PATCH mptcp-next v11 08/10] mptcp: add sendmsg_locked to proto_ops Geliang Tang
2026-08-30 14:32 ` [PATCH mptcp-next v11 09/10] mptcp: track app-limited state in mptcp_sendmsg Geliang Tang
2026-08-30 14:32 ` [PATCH mptcp-next v11 10/10] selftests: mptcp: sockopt: check app_limited Geliang Tang
2026-08-30 15:33 ` [PATCH mptcp-next v11 00/10] Reduce the differences between TCP and MPTCP for TLS usage MPTCP CI
2026-08-31 8:50 ` Geliang Tang
2026-09-01 0:20 ` Matthieu Baerts
2026-08-31 3:54 ` Geliang Tang
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=20260830145006.4A8DD1F000E9@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;
as well as URLs for NNTP newsgroup(s).