All of lore.kernel.org
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: geliang@kernel.org
Cc: mptcp@lists.linux.dev, kuba@kernel.org
Subject: Re: [PATCH mptcp-net v3 3/4] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
Date: Tue, 24 Nov 2026 15:26:35 +0000	[thread overview]
Message-ID: <179553399520.3133.15503954558196190617@kernel.org> (raw)
In-Reply-To: <d0fb9716397cd64ea82aa674e8314a7225a26ceb.1795396910.git.tanggeliang@kylinos.cn>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] mptcp_inq_hint() (net/mptcp/protocol.c:2384-2398) now adds a
  phantom FIN byte when no FIN or DATA_FIN was ever received.

--

mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint

This patch changes mptcp_inq_hint() to compute the available bytes as
bytes_received - bytes_consumed instead of ack_seq minus the head skb's
map_seq. That avoids a bogus INT_MAX hint on passive TFO connections. It
also adds a mptcp_data_fin() helper, adds a FIN byte under certain
conditions, and resets rcv_data_fin_seq in mptcp_disconnect().

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index e827b4fe8354a..8292e0db0b00a 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c

[ ... ]

> @@ -2378,22 +2384,17 @@ 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;
>  
> -		if (hint_val >= INT_MAX)
> -			return INT_MAX;
> +	if (((sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN)) &&
> +	     !READ_ONCE(msk->rcv_fastclose)) ||
> +	    (READ_ONCE(msk->rcv_data_fin) && mptcp_data_fin(msk, NULL)))
> +		hint_val += 1;

[Severity: Low]
Can this add a FIN byte when no FIN or DATA_FIN was ever received?

The first half of the condition looks only at local socket state. It now
adds 1 on top of unread data, where the old code only returned 1 when
the queue was empty.

One way to hit this is a local shutdown(fd, SHUT_RD) with data still
queued. inet_shutdown() sets RCV_SHUTDOWN:

net/ipv4/af_inet.c:inet_shutdown() {
    ...
	WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | how);
    ...
}

and mptcp_shutdown() only handles SEND_SHUTDOWN:

static void mptcp_shutdown(struct sock *sk, int how)
{
	...
	if ((how & SEND_SHUTDOWN) && mptcp_close_state(sk))
		__mptcp_wr_shutdown(sk);
}

bytes_received, bytes_consumed and ack_seq are left as they were, so with
D unread bytes the hint becomes D + 1.

Another way is a TCP RST on a fallen-back msk. In that case
__mptcp_subflow_error_report() moves the msk to TCP_CLOSE without setting
rcv_fastclose or purging the receive queue:

	if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD))
		mptcp_set_state(sk, ssk_state);
	WRITE_ONCE(sk->sk_err, -err);

Before this patch, a non-empty queue gave ack_seq - map_seq. ack_seq only
includes the FIN byte after mptcp_check_data_fin() advances it for a real
DATA_FIN, so neither case above reported the extra byte.

For comparison, tcp_inq_hint() only forces the extra byte when the queue
is empty and a FIN was actually received:

	if (inq == 0 && sock_flag(sk, SOCK_DONE))
		inq = 1;

A fallen-back MPTCP socket would therefore report a different TCP_CM_INQ
value than plain TCP in the same situation.

The later commit "mptcp: add mptcp_inq() for SIOCINQ" moves
SIOCINQ/FIONREAD to a new mptcp_inq() that leaves out the FIN byte, so
the SIOCINQ side goes away there. The TCP_CM_INQ cmsg in mptcp_recvmsg()
still calls mptcp_inq_hint(), and so does the autotuning measurement in
mptcp_rcv_space_adjust():

	copied -= mptcp_inq_hint(sk);

Both would still see the extra byte.

The changelog describes the +1 rule, but it doesn't say that the rule
now applies with data queued and no FIN received. Should the
TCP_CLOSE/RCV_SHUTDOWN branch only apply when mptcp_data_avail() is
zero, to match the old behaviour and tcp_inq_hint()?

>  
> -		return (unsigned int)hint_val;
> -	}
> -
> -	if (sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN))
> -		return 1;
> -
> -	return 0;
> +	return (unsigned int)hint_val;
>  }

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795396910.git.tanggeliang%40kylinos.cn

  reply	other threads:[~2026-11-24 15:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  1:27 [PATCH mptcp-net v3 0/4] mptcp: fixes for SIOCINQ Geliang Tang
2026-11-23  1:27 ` [PATCH mptcp-net v3 1/4] mptcp: handle ack_seq advancing past rcv_data_fin_seq Geliang Tang
2026-11-24 15:26   ` netdev-bot+sashiko
2026-11-23  1:27 ` [PATCH mptcp-net v3 2/4] mptcp: add missing memory barriers for rcv_data_fin_seq Geliang Tang
2026-11-24 15:26   ` netdev-bot+sashiko
2026-11-23  1:27 ` [PATCH mptcp-net v3 3/4] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Geliang Tang
2026-11-24 15:26   ` netdev-bot+sashiko [this message]
2026-11-23  1:27 ` [PATCH mptcp-net v3 4/4] mptcp: add mptcp_inq() for SIOCINQ Geliang Tang
2026-11-24 15:26   ` netdev-bot+sashiko
2026-11-23  3:34 ` [PATCH mptcp-net v3 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=179553399520.3133.15503954558196190617@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.