From: netdev-bot+sashiko@kernel.org
To: geliang@kernel.org
Cc: mptcp@lists.linux.dev, kuba@kernel.org
Subject: Re: [PATCH mptcp-net v2 3/4] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
Date: Tue, 24 Nov 2026 01:05:28 +0000 [thread overview]
Message-ID: <179548232859.3133.11411610594175565373@kernel.org> (raw)
In-Reply-To: <692168c4f75bdb59bc8a9ec9ed116674747c3898.1795348666.git.tanggeliang@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The FIN-byte guard in mptcp_inq_hint() (net/mptcp/protocol.c)
is wrong.
--
mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
This patch changes mptcp_inq_hint() to compute the available bytes with
mptcp_data_avail(), instead of ack_seq minus the head skb's map_seq. The old
calculation overflowed on passive TFO connections. The patch also moves the
DATA_FIN sequence check into a new mptcp_data_fin() helper, adds one byte
for the FIN, and resets rcv_data_fin_seq in mptcp_disconnect().
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 259a16068afad..7ef37f978f5b1 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -558,6 +558,21 @@ static void mptcp_check_data_fin_ack(struct sock *sk)
> }
> }
>
> +static bool mptcp_data_fin(const struct mptcp_sock *msk, u64 *seq)
> +{
> + u64 rcv_data_fin_seq;
> +
> + smp_rmb(); /* pair with smp_wmb() in mptcp_update_rcv_data_fin() */
> + rcv_data_fin_seq = READ_ONCE(msk->rcv_data_fin_seq);
> + if (!before64(READ_ONCE(msk->ack_seq), rcv_data_fin_seq)) {
> + if (seq)
> + *seq = rcv_data_fin_seq;
> +
> + return true;
> + }
> + return false;
> +}
> +
[ ... ]
> @@ -2364,22 +2370,18 @@ static bool mptcp_move_skbs(struct sock *sk)
> static unsigned int mptcp_inq_hint(const struct sock *sk)
> {
> const struct mptcp_sock *msk = mptcp_sk(sk);
> - const struct sk_buff *skb;
> -
> - skb = skb_peek(&sk->sk_receive_queue);
> - if (skb) {
> - u64 hint_val = READ_ONCE(msk->ack_seq) - MPTCP_SKB_CB(skb)->map_seq;
> + u64 hint_val = mptcp_data_avail(msk);
>
> - if (hint_val >= INT_MAX)
> - return INT_MAX;
> + if (hint_val >= INT_MAX)
> + return INT_MAX;
>
> - return (unsigned int)hint_val;
> + if (READ_ONCE(msk->rcv_data_fin) ||
> + sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN)) {
> + if (mptcp_data_fin(msk, NULL))
> + hint_val += 1;
> }
>
> - if (sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN))
> - return 1;
> -
> - return 0;
> + return (unsigned int)hint_val;
> }
[Severity: Medium]
Can the TCP_CLOSE and RCV_SHUTDOWN arms of this condition add a FIN byte
that was never received?
The only function that writes a real value to rcv_data_fin_seq is
mptcp_update_rcv_data_fin() in net/mptcp/options.c. It sets the field
together with rcv_data_fin:
WRITE_ONCE(msk->rcv_data_fin_seq,
mptcp_expand_seq(READ_ONCE(msk->ack_seq), data_fin_seq, use_64bit));
smp_wmb(); /* ensure rcv_data_fin_seq is visible before rcv_data_fin */
WRITE_ONCE(msk->rcv_data_fin, 1);
The msk can reach TCP_CLOSE or RCV_SHUTDOWN without any DATA_FIN. One
example is mptcp_check_fastclose() after the peer sends MP_FASTCLOSE:
mptcp_set_state(sk, TCP_CLOSE);
WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
A subflow reset or error propagation, or a local shutdown(SHUT_RD), leads
to the same state.
In these cases rcv_data_fin_seq is still 0, so mptcp_data_fin() evaluates
!before64(ack_seq, 0). That reduces to (s64)ack_seq >= 0.
subflow_set_remote_key() sets msk->ack_seq to subflow->iasn, which is
derived from a hash of the peer's key. The result therefore looks random
per connection. Fallback connections start with ack_seq at 0, so for them
the check is always true.
There seem to be two possible outcomes:
- top bit of ack_seq clear: N queued bytes are reported as N + 1
- top bit set: an empty queue in TCP_CLOSE or RCV_SHUTDOWN reports 0,
where the old code returned 1
The commit message says:
The FIN byte (+1) is guarded by checking rcv_data_fin, TCP_CLOSE, or
RCV_SHUTDOWN before calling mptcp_data_fin().
Only the rcv_data_fin arm seems to guarantee that rcv_data_fin_seq holds a
valid value.
The new reset in mptcp_disconnect() has the same problem:
WRITE_ONCE(msk->rcv_data_fin_seq, 0);
0 doesn't work as a "no FIN" marker here, because the comparison is
modular against ack_seq.
The TCP_CLOSE and RCV_SHUTDOWN arms also skip the rcv_data_fin read that
the smp_rmb() in mptcp_data_fin() is meant to pair with. Subflow context
writes rcv_data_fin_seq without holding the msk lock. A concurrent or torn
(on 32-bit) value could therefore feed the same comparison.
This still seems to be present at the end of the series. The later patch
"mptcp: add mptcp_inq() for SIOCINQ" moves SIOCINQ to mptcp_inq(). However,
mptcp_inq_hint() still feeds the TCP_CM_INQ cmsg in mptcp_recvmsg():
unsigned int inq = mptcp_inq_hint(sk);
It also feeds the receive buffer autotuning in mptcp_rcv_space_adjust():
copied -= mptcp_inq_hint(sk);
Should the +1 only be added when rcv_data_fin is set?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795348666.git.tanggeliang%40kylinos.cn
next prev parent reply other threads:[~2026-11-24 1:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 12:07 [PATCH mptcp-net v2 0/4] mptcp: fixes for SIOCINQ Geliang Tang
2026-11-22 12:07 ` [PATCH mptcp-net v2 1/4] mptcp: handle ack_seq advancing past rcv_data_fin_seq Geliang Tang
2026-11-24 1:05 ` netdev-bot+sashiko
2026-11-22 12:07 ` [PATCH mptcp-net v2 2/4] mptcp: add missing memory barriers for rcv_data_fin_seq Geliang Tang
2026-11-24 1:05 ` netdev-bot+sashiko
2026-11-22 12:07 ` [PATCH mptcp-net v2 3/4] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Geliang Tang
2026-11-22 12:21 ` sashiko-bot
2026-11-24 1:05 ` netdev-bot+sashiko [this message]
2026-11-22 12:07 ` [PATCH mptcp-net v2 4/4] mptcp: add mptcp_inq() for SIOCINQ Geliang Tang
2026-11-24 1:05 ` netdev-bot+sashiko
2026-11-22 14:26 ` [PATCH mptcp-net v2 0/4] mptcp: fixes " 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=179548232859.3133.11411610594175565373@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=geliang@kernel.org \
--cc=kuba@kernel.org \
--cc=mptcp@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.