From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381756; b=4o33ANxdj20ON4b2bka96lpRhG8jG2rr9A+SPitRKCO2Pz02/9MCIpKM1OaUbsql0ILH 5JTbEBtzV1s7aHHQ+npkVfoUQ0SjIlFQeLohzutHyt9Z6pCHeJ2bpkvHMjxKAY8u9k1Z1 qhw1bReodDcS2h9lDpZ5HE99P1CiOw19ispOt82tI9nc0IO2U7cfWr4ftDQ7ws4f8wfZ0 mmJgdMZSS6I8EwS2ON7oJnK8ZXo4bnvtIcAiKF7ai9jf/ITcMvOF7GTsjK49JmofI+JHu oROi60kwvLxo9Kal+yVu+3Xq6ZqGpa+GH53Qqx/pocmUyledkIONBhNP+rwFmCSpE5A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381756; h=Received:DKIM-Signature:Message-ID:Subject:From:To:Date:In-Reply-To: References:Content-Type:User-Agent:MIME-Version: Content-Transfer-Encoding; bh=oqNHsvJ4jdbP+GYzMi6pKMqBelT0VkDP94S1EC1xIRo=; b=Xpg2iR006o+E3RY7b/ZzrE8AAuQdRXTJMGz/19KdM9kj9dsMwvMG8wEvmDNY+b9YLzUq QLtm7hsArBLTSWD/1j6lTb3oqlchaRWLuuOMPiGI8gU/zUfNfB0N2I+ItHByGLiFvTr+o 4NoBpIs906xiNSTtKBWiGbtfKyFDYuOE7hplHFYrSzP9txwc+kv/gAHkgg1VN66weyL2l ky/tdFjdtqvh/ZFmW2ghX40eJjodI9j9cTePeuKAzKV0mp/ULdrfe7MI2t+SB1SbVau94 woJUVOSgYpJxwSGiD5qqVFvHuzo8llwOCVI8S0n3iOfG11/tsts5xeOdeWnQvPhyq7g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=P0tZNcmV; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A93C5606A33F; Fri, 4 Dec 2026 10:55:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=P0tZNcmV Received: by smtp.kernel.org (Postfix) with ESMTPSA id 678DF1F00897; Fri, 4 Dec 2026 10:55:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796381756; bh=oqNHsvJ4jdbP+GYzMi6pKMqBelT0VkDP94S1EC1xIRo=; h=Subject:From:To:Date:In-Reply-To:References; b=P0tZNcmVFxjwdlW7IDEJwbdmkvMPHnBmTmucJi3WEQ8I9fDqZ3/cxZh49JfmZ2pKb R5WM/Temo49fZ5R8IAoH//GvwqMXnhTfHysyXegHXzTEmfH/Ug/ilxNF2qbiMIDzP3 9MXPbk5YMV5aHAV4t4uU5KxnDkQhz+Y56Zj0Z4qXuGmeFx+rf5Z+PcUwn7KoD2VuY+ W04Q9NreLxJ92B1duf1eDNFyOqbxQ+VJt8ejcBDGZsAWe68xWEF3O2a7/bMCR+Glgu qfFp8f56FRuu6SvZ/6J8XqhTkr/iTDTgcYT4fsCYM+o2pI/Dd5h1Q7wzGZ1ScVv8U5 s+M/MDGm1a2SA== Message-ID: <0ac04e420bb265f1f57e8ecf0961a309ace105ff.camel@kernel.org> Subject: Re: [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN in mptcp_inq_hint From: Geliang Tang To: sashiko-reviews@lists.linux.dev, "Matthieu Baerts (NGI0)" , MPTCP Linux Date: Fri, 04 Dec 2026 18:55:52 +0800 In-Reply-To: References: <20261203-mptcp-fixes-for-siocinq-v7-0-e6d589de9cf8@kernel.org> <20261203-mptcp-fixes-for-siocinq-v7-6-e6d589de9cf8@kernel.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.56.2-10build1 X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Hi Matt, Thank you very much for helping me send this v7. On Thu, 2026-12-03 at 18:50 +0000, sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 3 potential > issues to consider: > - [Medium] mptcp: mptcp_inq_hint() omits pending FIN byte on fallback > sockets > - [Medium] mptcp: race in mptcp_inq_hint() counts spurious FIN on > fallback RST > - [Low] mptcp: mptcp_inq_hint() omits TCP_CLOSE check for rcv_data_fin > -- I plan to address all three points by replacing the open-coded check in mptcp_inq_hint() with a new helper: static bool mptcp_pending_eof(const struct sock *sk, u64 *seq) { const struct mptcp_sock *msk = mptcp_sk(sk); if (!mptcp_pending_data_fin(sk, seq)) return false; return !__mptcp_check_fallback(msk) || (msk->first && sock_flag(msk->first, SOCK_DONE)); } and calling it from mptcp_inq_hint(): if (sock_flag(sk, SOCK_DONE) || mptcp_pending_eof(sk, NULL)) hint_val += 1; Also, the mptcp_rcv_data_fin_in_seq helper can be deleted. > > commit 3d490bb2690ae1fefdf4a528196f8efa6be2b028 > Author: Geliang Tang > > mptcp: count the DATA_FIN in mptcp_inq_hint > > This commit updates mptcp_inq_hint() to add the FIN byte to the available > data count when SOCK_DONE is set or when a non-fallback connection has an > in-sequence DATA_FIN pending. > > > diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c > > index 1d330c5d09f42..e0e6266e11c85 100644 > > --- a/net/mptcp/protocol.c > > +++ b/net/mptcp/protocol.c > > @@ -2487,22 +2487,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 = mptcp_data_avail(msk); > > - > > - if (hint_val >= INT_MAX) > > - return INT_MAX; > > - > > - return (unsigned int)hint_val; > > - } > > + if (hint_val >= INT_MAX) > > + return INT_MAX; > > > > - if (sock_flag(sk, SOCK_DONE)) > > - return 1; > > + if (sock_flag(sk, SOCK_DONE) || > > + (!__mptcp_check_fallback(msk) && > > + mptcp_rcv_data_fin_in_seq(sk, NULL))) > > + hint_val += 1; > > [Severity: Medium] > Can excluding __mptcp_check_fallback(msk) here omit the pending FIN byte > on fallback sockets before mptcp_worker() sets SOCK_DONE on sk? > > When a fallen-back socket receives data and a TCP FIN in softirq, > tcp_fin() sets SOCK_DONE on msk->first, move_skbs_to_msk() queues the > data directly on sk->sk_receive_queue, and mptcp_data_ready() wakes > userspace while SOCK_DONE propagation waits on mptcp_worker(): > > CPU0 (softirq / kworker) CPU1 (userspace) > tcp_fin() > sock_set_flag(ssk, SOCK_DONE) > mptcp_data_ready() > move_skbs_to_msk() > sk->sk_data_ready(sk) > subflow_sched_work_if_closed() > mptcp_update_rcv_data_fin() > mptcp_schedule_work(sk) > mptcp_recvmsg() > lock_sock(sk) > ... (backlog_list empty) > mptcp_worker() > lock_sock(sk) (blocks) > mptcp_inq_hint() <-- omits +1 > > With msk->backlog_list empty, mptcp_recvmsg() skips mptcp_move_skbs() > and mptcp_check_data_fin(), so TCP_CM_INQ under-reports by 1 byte (or > returns 0 instead of 1 after draining the last data bytes). > > Since callers of mptcp_inq_hint() hold lock_sock(sk), this could mirror > mptcp_check_data_fin() and check (!__mptcp_check_fallback(msk) || > (msk->first && sock_flag(msk->first, SOCK_DONE))) to count fallback FINs > while still excluding fallback RSTs. The helper counts the fallback FIN once msk->first has SOCK_DONE set, as in mptcp_check_data_fin(), without waiting for mptcp_worker(). > > [Severity: Medium] > Does testing !__mptcp_check_fallback(msk) before > mptcp_rcv_data_fin_in_seq(sk, NULL) race with a concurrent fallback and > TCP RST and count a spurious FIN byte? > > mptcp_inq_hint() runs under lock_sock(sk) without msk->fallback_lock or > the subflow lock. Concurrently in softirq, a non-MP_CAPABLE RST before > fully_established (or a fallback followed by RST) sets > MPTCP_FALLBACK_DONE before smp_wmb() and msk->rcv_data_fin = 1: > > CPU0 (userspace) CPU1 (softirq) > mptcp_inq_hint() > !__mptcp_check_fallback(msk) > (true) > tcp_reset() > __mptcp_try_fallback() > set_bit(MPTCP_FALLBACK_DONE, ...) > subflow_sched_work_if_closed() > mptcp_update_rcv_data_fin() > smp_wmb() > msk->rcv_data_fin = 1 > mptcp_rcv_data_fin_in_seq() > (true -> hint_val += 1) <-- spurious FIN > > Because the reader checks MPTCP_FALLBACK_DONE before msk->rcv_data_fin > with no barrier in between, it can observe the emulated DATA_FIN from > the RST and report an unread FIN byte on a reset connection. > > Calling mptcp_rcv_data_fin_in_seq(sk, NULL) first, which executes the > pairing smp_rmb() after reading msk->rcv_data_fin, and checking > __mptcp_check_fallback(msk) afterward closes both the race window and > load reordering. The pending DATA_FIN is observed before the fallback flag; the smp_rmb() in mptcp_pending_data_fin() pairs with the smp_wmb() in mptcp_update_rcv_data_fin(), so a RST-induced DATA_FIN is excluded. > > [Severity: Low] > Should this check the socket state (like mptcp_pending_data_fin() does) > so a stale rcv_data_fin on a TCP_CLOSE socket is not counted? > > In mptcp_check_fastclose(), mptcp_check_data_fin(sk) runs before locking > and closing the subflows. A zero-length in-sequence DATA_FIN arriving on > an open subflow in that window sets msk->rcv_data_fin = 1 just before sk > transitions to TCP_CLOSE with ECONNRESET and SOCK_DONE unset: > > CPU0 (kworker) CPU1 (softirq) > mptcp_check_fastclose() > mptcp_check_data_fin(sk) > mptcp_incoming_options() > mptcp_update_rcv_data_fin() > msk->rcv_data_fin = 1 > sk->sk_err = ECONNRESET > mptcp_set_state(sk, TCP_CLOSE) <-- rcv_data_fin left stale > > Once sk is in TCP_CLOSE, mptcp_pending_data_fin() returns false and > mptcp_worker() exits early, leaving msk->rcv_data_fin permanently set > without SOCK_DONE. When userspace drains queued data, mptcp_inq_hint() > still adds +1 to TCP_CM_INQ even though the next recvmsg() will return > -ECONNRESET rather than EOF. > > Using mptcp_pending_data_fin() (or excluding TCP_CLOSE) avoids counting > an unprocessable DATA_FIN. The ESTABLISHED/FIN_WAIT1/FIN_WAIT2 state check in mptcp_pending_data_fin() keeps a stale rcv_data_fin on TCP_CLOSE from being counted. If you think this is okay, I'll send a v8. Thanks, -Geliang