MPTCP Linux Development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Geliang Tang" <geliang@kernel.org>
Cc: mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v9 04/11] mptcp: remove CB offset field
Date: Thu, 27 Aug 2026 11:13:32 +0000	[thread overview]
Message-ID: <20260827111332.B40E61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <abfb5ca3767e390206d6ad4056818a61263a8d33.1787827525.git.tanggeliang@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Lockless check of MPTCP_SYNC_SEQ in mptcp_inq_hint() leads to a TOCTOU race condition that can incorrectly return a bogus TCP_CM_INQ value (often INT_MAX).
--

commit 6c708b896ef73852cc85c2a1debeca40b8a72f1c
Author: Paolo Abeni <pabeni@redhat.com>

mptcp: remove CB offset field

This commit replaces the offset field in MPTCP's skb control block with a
socket-level copied_seq field. This mirrors TCP's approach for tracking
bytes consumed and delegating IASN synchronization to the msk release CB
during Fastopen.

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 7d1422518aada..4cf7ad97ae0af 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
[ ... ]
> @@ -2414,27 +2397,27 @@ static bool mptcp_move_skbs(struct sock *sk)
>  	return enqueued;
>  }
>  
> -static unsigned int mptcp_inq_hint(const struct sock *sk)
> +static unsigned int mptcp_inq_hint(struct sock *sk)
>  {
>  	const struct mptcp_sock *msk = mptcp_sk(sk);
> -	const struct sk_buff *skb;
>  	u64 hint_val, ack_seq;
>  
> -	skb = skb_peek(&sk->sk_receive_queue);
> -	if (skb) {
> -		ack_seq = atomic64_read(&msk->ack_seq);
> -		hint_val = ack_seq - MPTCP_SKB_CB(skb)->map_seq;
> -
> -		if (hint_val >= INT_MAX)
> -			return INT_MAX;
> +	if (test_bit(MPTCP_SYNC_SEQ, &msk->cb_flags))
> +		return 0;
>  
> -		return (unsigned int)hint_val;
> -	}
> +	/* Avoid races vs ack_seq updates. */
> +	mptcp_data_lock(sk);
> +	ack_seq = atomic64_read(&msk->ack_seq);
> +	hint_val = ack_seq - msk->copied_seq;
> +	mptcp_data_unlock(sk);

[Severity: Medium]
Could this lockless check of MPTCP_SYNC_SEQ lead to a Time-of-Check to
Time-of-Use (TOCTOU) race condition?

If an application calls recvmsg() with msg_control to read TCP_CM_INQ, and
concurrent to mptcp_inq_hint() executing, a softirq updates the socket's
ack_seq to the remote key (iasn) and sets the MPTCP_SYNC_SEQ flag:

mptcp_inq_hint() could test MPTCP_SYNC_SEQ outside of mptcp_data_lock(sk),
read 0 (false), wait for the lock, and then calculate hint_val using the
newly updated ack_seq but a stale copied_seq.

Since the new ack_seq is an absolute cryptographic sequence number and the
stale copied_seq is relative (negative), the difference could be larger
than INT_MAX, causing the function to incorrectly return INT_MAX.

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

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

  reply	other threads:[~2026-08-27 11:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27 10:57 [PATCH mptcp-next v9 00/11] Reduce the differences between TCP and MPTCP for TLS usage Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 01/11] mptcp: use atomic64_t for locklessly accessed u64 fields Geliang Tang
2026-08-27 11:15   ` sashiko-bot
2026-08-27 10:57 ` [PATCH mptcp-next v9 02/11] mptcp: drop the mptcp_ooo_try_coalesce() helper Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 03/11] mptcp: drop the cant_coalesce CB field Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 04/11] mptcp: remove CB offset field Geliang Tang
2026-08-27 11:13   ` sashiko-bot [this message]
2026-08-27 10:57 ` [PATCH mptcp-next v9 05/11] mptcp: sync mptcp skb cb layout with tcp one Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 06/11] mptcp: defer read_sock cleanup to mptcp_worker Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 07/11] mptcp: implement peek_len for proto_ops Geliang Tang
2026-08-27 11:10   ` sashiko-bot
2026-08-27 10:57 ` [PATCH mptcp-next v9 08/11] mptcp: add sendmsg_locked to proto_ops Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 09/11] mptcp: track app-limited state in mptcp_sendmsg Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 10/11] selftests: mptcp: sockopt: check app_limited Geliang Tang
2026-08-27 10:57 ` [PATCH mptcp-next v9 11/11] Squash to "selftests/bpf: Add bpf_burst scheduler & test" Geliang Tang
2026-08-27 11:17   ` sashiko-bot
2026-08-27 12:13 ` [PATCH mptcp-next v9 00/11] Reduce the differences between TCP and MPTCP for TLS usage 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=20260827111332.B40E61F000E9@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