MPTCP Linux Development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Geliang Tang" <geliang@kernel.org>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-net 3/4] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
Date: Sun, 22 Nov 2026 03:54:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-227687@kernel.org> (raw)
In-Reply-To: <05dcaa680dcd6cdf91aa1204a20c2c754aa28cc5.1795318567.git.tanggeliang@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mptcp: premature FIN byte accounting in mptcp_data_fin_seq()
- [Medium] mptcp: zero rcv_data_fin_seq missed in mptcp_inq_hint() on
  TCP fallback
--

commit 7f3583a035d8da6607d3d80aed0de39c52b747e0
Author: Geliang Tang <geliang@kernel.org>

mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint

This commit updates mptcp_inq_hint() to compute available bytes via
mptcp_data_avail() and adds mptcp_data_fin_seq() to account for the
received DATA_FIN byte.

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 259a16068afad..0ac762fc6210c 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2154,6 +2154,18 @@ static void mptcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb)
>  	skb_attempt_defer_free(skb);
>  }
>  
> +static u64 mptcp_data_fin_seq(const struct sock *sk)
> +{
> +	const struct mptcp_sock *msk = mptcp_sk(sk);
> +
> +	if (!(READ_ONCE(msk->rcv_data_fin) ||
> +	      sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN)))
> +		return 0;
> +
> +	smp_rmb(); /* pair with smp_wmb() in mptcp_update_rcv_data_fin() */
> +	return READ_ONCE(msk->rcv_data_fin_seq);
> +}

[Severity: Medium]
Does mptcp_data_fin_seq() report the FIN before all preceding data has
arrived in order?

get_mapping_status() calls mptcp_update_rcv_data_fin() as soon as a
subflow skb carrying DATA_FIN reaches the head of ssk->sk_receive_queue,
even if that mapping arrived out of order while earlier DSN data is still
in flight on another subflow (or on the first segment of a multi-segment
DSS mapping carrying DATA_FIN).  Unlike mptcp_pending_data_fin(),
mptcp_data_fin_seq() does not check !before64(READ_ONCE(msk->ack_seq),
rcv_data_fin_seq).

While msk->ack_seq is still behind msk->rcv_data_fin_seq, mptcp_inq_hint()
adds 1 for the FIN before RCV_SHUTDOWN is set, so SIOCINQ and TCP_CM_INQ
report N + 1 when only N in-order bytes are readable before the gap (or 1
when a non-blocking recvmsg() will return -EAGAIN).

> @@ -2364,22 +2376,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;
> -
> -	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 (mptcp_data_fin_seq(sk))
> +		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 mptcp_inq_hint() miss the FIN byte when msk->rcv_data_fin_seq is 0 on
a TCP fallback connection?

When an active connection falls back to plain TCP in
subflow_finish_connect(), subflow_set_remote_key() is not called, leaving
subflow->iasn, subflow->map_seq and msk->ack_seq at 0.  If the peer closes
the connection without sending any payload, subflow_sched_work_if_closed()
records the dummy DATA_FIN with sequence 0:

net/mptcp/subflow.c:subflow_sched_work_if_closed() {
	...
	if (__mptcp_check_fallback(msk) && subflow_is_done(ssk) &&
	    msk->first == ssk &&
	    mptcp_update_rcv_data_fin(msk, subflow->map_seq +
				      subflow->map_data_len, true))
		mptcp_schedule_work(sk);
}

Because msk->rcv_data_fin_seq is 0, mptcp_data_fin_seq(sk) returns 0 and
mptcp_inq_hint() returns 0 instead of 1 after the peer's FIN.

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

  reply	other threads:[~2026-11-22  3:54 UTC|newest]

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