From: netdev-bot+sashiko@kernel.org
To: geliang@kernel.org
Cc: mptcp@lists.linux.dev, kuba@kernel.org
Subject: Re: [PATCH mptcp-net v8 1/7] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
Date: Wed, 18 Nov 2026 01:05:43 +0000 [thread overview]
Message-ID: <179496394384.3133.8877510786925164911@kernel.org> (raw)
In-Reply-To: <2aa50a4b4f9ed4833a91e791918e02ec206876e0.1794826541.git.geliang@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · 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] This is a regression the patch introduces in
net/mptcp/protocol.c:mptcp_inq_hint().
- [Medium] The commit message says the new code "ensures SIOCINQ reports
N+1 when N bytes are unread with DATA_FIN pending, matching TCP…
--
mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
This commit changes mptcp_inq_hint() to take the readable byte count from
mptcp_data_avail() instead of ack_seq minus the map_seq of the head skb.
The old calculation overflowed to INT_MAX on passive TFO connections. The
commit also adds one byte to the hint when RCV_SHUTDOWN is set or the
socket is in TCP_CLOSE.
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 50de5cedfd0fb..574eba9989a8d 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2404,22 +2404,15 @@ 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;
> + u64 hint_val = mptcp_data_avail(msk);
>
> - skb = skb_peek(&sk->sk_receive_queue);
> - if (skb) {
> - u64 hint_val = READ_ONCE(msk->ack_seq) - MPTCP_SKB_CB(skb)->map_seq;
> -
> - if (hint_val >= INT_MAX)
> - return INT_MAX;
> -
> - return (unsigned int)hint_val;
> - }
> + if (hint_val >= INT_MAX)
> + return INT_MAX;
>
> if (sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN))
> - return 1;
> + hint_val += 1;
[Severity: Medium]
Does RCV_SHUTDOWN here always mean that a DATA_FIN is pending? The commit
message treats the two as the same thing. However, the +1 is now added on
top of a non-zero mptcp_data_avail() whenever RCV_SHUTDOWN or TCP_CLOSE is
set, even if no DATA_FIN ever used up a sequence number.
Before this patch, with a non-empty receive queue the hint was
ack_seq - head->map_seq. That is exactly the N unread bytes, because
__mptcp_recvmsg_mskq() advances map_seq on partial reads:
MPTCP_SKB_CB(skb)->map_seq += count;
The value only became N+1 after mptcp_check_data_fin() accounted for a
real DATA_FIN:
WRITE_ONCE(msk->ack_seq, msk->ack_seq + 1);
The old "return 1" only ran when the queue was empty.
There seem to be two cases where the new code reports N+1 and the old code
reported N.
The first is a local shutdown(fd, SHUT_RD). inet_shutdown() sets
RCV_SHUTDOWN, but mptcp_shutdown() only handles SEND_SHUTDOWN, so no
DATA_FIN exists.
The second is an MP_FASTCLOSE from the peer, handled in
mptcp_check_fastclose():
mptcp_set_state(sk, TCP_CLOSE);
WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
This path does not touch ack_seq and does not purge sk_receive_queue.
The inflated value then reaches userspace through mptcp_ioctl(SIOCINQ) and
through the TCP_CM_INQ cmsg in mptcp_recvmsg(). It also feeds the
"copied -= mptcp_inq_hint(sk)" step in mptcp_rcv_space_adjust().
For comparison, tcp_inq() and tcp_inq_hint() only count a FIN that was
actually received (SOCK_DONE is set by tcp_fin()). tcp_inq_hint() also
only forces 1 when inq is 0.
Could the FIN byte be added only when a DATA_FIN was actually accounted
for, or only when mptcp_data_avail() returns 0? As far as I can tell,
mptcp_inq_hint() stays unchanged through the end of the series.
[Severity: Medium]
The commit message says:
This ensures SIOCINQ reports N+1 when N bytes are unread with DATA_FIN
pending, matching TCP behavior where FIN consumes a sequence number.
Is that right for SIOCINQ? On TCP, SIOCINQ goes through
tcp_ioctl()->tcp_inq(), which subtracts the FIN byte:
answ = tp->rcv_nxt - tp->copied_seq;
/* Subtract 1, if FIN was received */
if (answ && sock_flag(sk, SOCK_DONE))
answ--;
So TCP reports N while a FIN is pending and 0 at EOF. Only TCP_CM_INQ, via
tcp_inq_hint(), counts the FIN.
mptcp_ioctl(SIOCINQ) returns mptcp_inq_hint(), the same helper that
TCP_CM_INQ uses. As a result, FIONREAD on an MPTCP socket returns N+1 after
a DATA_FIN and 1 after EOF, where TCP returns N and 0.
The old ack_seq based calculation already produced N+1, and 1 at EOF.
This patch, though, rewrites the helper and makes the +1 explicit based on
the TCP parity claim above.
A later patch in the series ("mptcp: implement peek_len for proto_ops")
adds mptcp_inq(), which returns mptcp_data_avail() without the FIN.
However, SIOCINQ still calls mptcp_inq_hint() at the end of the series.
Should mptcp_ioctl() use a helper that leaves out the FIN, as tcp_inq()
does for TCP?
The FIONREAD check in process_one_client() in
tools/testing/selftests/net/mptcp/mptcp_inq.c only runs before the peer
sends its DATA_FIN, so this case does not seem to be covered by the
selftest.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794826541.git.geliang%40kernel.org
next prev parent reply other threads:[~2026-11-18 1:05 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 10:57 [PATCH mptcp-next v8 0/7] prepare interfaces for kTLS and sockmap support Geliang Tang
2026-11-16 10:57 ` [PATCH mptcp-net v8 1/7] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Geliang Tang
2026-11-18 1:05 ` netdev-bot+sashiko [this message]
2026-11-16 10:57 ` [PATCH mptcp-next v8 2/7] selftests: mptcp: connect: check TFO SIOCINQ overflow Geliang Tang
2026-11-18 1:05 ` netdev-bot+sashiko
2026-11-16 10:57 ` [PATCH mptcp-next v8 3/7] mptcp: implement peek_len for proto_ops Geliang Tang
2026-11-18 1:05 ` netdev-bot+sashiko
2026-11-16 10:57 ` [PATCH mptcp-next v8 4/7] mptcp: add sendmsg_locked to proto_ops Geliang Tang
2026-11-18 1:05 ` netdev-bot+sashiko
2026-11-16 10:57 ` [PATCH mptcp-next v8 5/7] mptcp: track app-limited state in mptcp_sendmsg Geliang Tang
2026-11-18 1:05 ` netdev-bot+sashiko
2026-11-16 10:57 ` [PATCH mptcp-next v8 6/7] selftests: mptcp: sockopt: check app_limited Geliang Tang
2026-11-18 1:05 ` netdev-bot+sashiko
2026-11-16 10:57 ` [PATCH mptcp-next v8 7/7] mptcp: update mptcp_check_readable Geliang Tang
2026-11-16 13:38 ` [PATCH mptcp-next v8 0/7] prepare interfaces for kTLS and sockmap support 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=179496394384.3133.8877510786925164911@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.