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=1796334714; b=S19q+F5ed7iSgZZZBlvcmJwvYEgWz1wcndIJErhFcdsN+WxGCIoKsS3rC4s0KlPWztJb jXvswX1GHh3LYvufimDuOlvm3YMIsxWxJ1VlaMl1lXTkC4rPe+3dMp5nLoUjifIts+Z7/ vGbWlvLhU94iarXyS1TWfwhu78f/9kVoJpg3BLqlf04P0AtULpUbGeK2WwBzjreQLsITB rhlV4Mcqh4ZHm0UcWnZ1gWbSnNRidH8VhjYD50d4rMzrQz7DXCcFWVvQzX2XQ8s21kqPC FMVtit+jp41NF5eclPtIq0kn1QZZDhhSkstbtdrsFm6hYclADS9mxQ2QLK4Bu15vrtg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796334714; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=3cs9IyuyTh0WU6CriC3CXNce117vgtDwWeMIzbzEWyc=; b=sa+Lc50yRuBJUE2iVEarvk2WxZo9ltLwzw1muA4A3+tHT0Rx11HJMVWsOyvtc8nnZUpA 0OSRA4ChF3M/XJgZ+kpqyyUIfGyvd8ZNzPWRQqaOgApx8smbx+4cruMV5C9qvuc87hnzZ erjkLRPHKjkUyvQw0Aw7f4jM6N+o3GIeFJ7qncDXY0HwaeI/IrmebwcbPjCN9rF5Q+cEw lJy8JnAcUgBkZbIuxXRwVkxD7wfqZQ0sLV0yohpuA/Ryv+o9KImYd6tPirwnU5HvnIFFU LwecqNhNbztSipbvCK7gS6x6t0vatDDRId6efSC0+ZnRGmV+02GEPjbk/MCQweK2PDQ== 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=J01dUiYZ; 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 89951606A697; Thu, 3 Dec 2026 21:51:54 +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=J01dUiYZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id A20F81F00933; Thu, 3 Dec 2026 21:51:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796334714; bh=3cs9IyuyTh0WU6CriC3CXNce117vgtDwWeMIzbzEWyc=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=J01dUiYZCOkJ8waYXb/+xx7u/rR8vj8037wYegG8VUeipi58AkBIDBrXISNy2eqC1 quhcws6HdYp+VEpxbQFKWHFAohiGI8zHsuySnqcB+oVCFTq+74Ctcv68NhjzKwmuU1 y4uoJwlvUmEAlNukWzKqAekWU+WiNrwNIOPPdkg2fdfGOBrd12pI/zVVtoK0NSDYzZ q0vHRZ63tVQi9zGDGTOAac07oeQxRdSmYCUnfffcG3bp9mEn4kFakTO2W1wJ2ejDdw GgEQjTCxLPMpeWaIpHLCCtghYxQuL3SHMpnAUgpM1fhfhA+0L0Qu2hvn6AFsjBJrgY PF0023FueZAeg== Subject: Re: [PATCH net 5/9] mptcp: return EOF after a DATA_FIN, as TCP does From: netdev-bot+sashiko@kernel.org To: matttbe@kernel.org Cc: martineau@kernel.org, geliang@kernel.org, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, horms@kernel.org, dcaratti@redhat.com, netdev@vger.kernel.org, mptcp@lists.linux.dev, mason@kernel.org, stable@vger.kernel.org Date: Thu, 03 Dec 2026 21:51:53 +0000 Message-ID: <179633471320.3146.5929327584163174012@kernel.org> In-Reply-To: <20261202-net-mptcp-misc-fixes-7-4-rc7-v1-5-9f03efcb1a17@kernel.org> References: <20261202-net-mptcp-misc-fixes-7-4-rc7-v1-5-9f03efcb1a17@kernel.org> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 1 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 patch's fix (EOF after a DATA_FIN even when a reset follows) does not cover the passive side when accept() gets the msk… - [Low] mptcp_close_ssk() (net/mptcp/protocol.c:2787-2788) reads msk->rcv_data_fin with READ_ONCE() before it takes the first subflow's… -- mptcp: return EOF after a DATA_FIN, as TCP does Once a DATA_FIN has been processed, this patch sets SOCK_DONE on the msk. mptcp_recvmsg() now checks that flag before the socket error, so recv() returns EOF after the data even if a reset or MP_FASTCLOSE follows. After a fallback, the emulated DATA_FIN is now set before the subflow close is scheduled, and mptcp_close_ssk() processes it before the first subflow is disconnected. Link: https://github.com/multipath-tcp/mptcp_net-next/issues/647 > diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c > index fc8aad7e2fde9..1f045348764ad 100644 > --- a/net/mptcp/protocol.c > +++ b/net/mptcp/protocol.c [ ... ] > @@ -2763,12 +2775,21 @@ void mptcp_close_ssk(struct sock *sk, struct sock *ssk, [ ... ] > + mptcp_pm_subflow_check_next(msk, subflow); > + > + /* On fallback, the FIN of the first subflow is cleared when it is > + * disconnected: process the DATA_FIN emulated from it before. > + */ > + if (ssk == msk->first && __mptcp_check_fallback(msk) && > + READ_ONCE(msk->rcv_data_fin) && !sock_flag(sk, SOCK_DEAD)) { > + mptcp_move_skbs(sk); > + mptcp_check_data_fin(sk); > + } [Severity: Medium] Is the passive side covered when accept() takes the msk lock before mptcp_worker() has handled the emulated DATA_FIN? When the first subflow is already closed and is the only subflow, mptcp_stream_accept() moves newsk to TCP_CLOSE before it calls mptcp_close_ssk(): net/mptcp/protocol.c:mptcp_stream_accept() { ... if (unlikely(inet_sk_state_load(msk->first) == TCP_CLOSE)) { if (unlikely(list_is_singular(&msk->conn_list))) mptcp_set_state(newsk, TCP_CLOSE); mptcp_close_ssk(newsk, msk->first, mptcp_subflow_ctx(msk->first)); } ... } The new block above then matches. This is the first subflow, the msk has fallen back, subflow_sched_work_if_closed() has set rcv_data_fin, and the msk is not SOCK_DEAD. But mptcp_check_data_fin() does nothing here. mptcp_pending_data_fin() only accepts TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2, so the msk gets neither RCV_SHUTDOWN nor SOCK_DONE. Next, __mptcp_close_ssk()->__mptcp_subflow_disconnect()->tcp_disconnect() clears SOCK_DONE on the subflow. It keeps sk_err, which tcp_reset() set to EPIPE in CLOSE_WAIT. The accept() caller owns the msk, so the error report is deferred as MPTCP_ERROR_REPORT. Then at release_sock(): mptcp_release_cb() __mptcp_error_report() __mptcp_subflow_error_report() This skips the new SOCK_DONE propagation, because the subflow flag is already cleared, and sets sk_err = EPIPE on the msk. mptcp_worker() then bails out on TCPF_CLOSE, so nothing corrects this later. Doesn't mptcp_recvmsg() then return the data followed by -EPIPE instead of EOF? The commit message says this case is fixed. The non-fallback case looks similar. Data, a DATA_FIN and an MP_FASTCLOSE can all arrive before accept(), with the worker not yet run. In that case mptcp_check_fastclose() and mptcp_check_data_fin() are never called, and recv() returns -ENOTCONN after the data instead of EOF. Could the pending DATA_FIN be processed before mptcp_set_state(newsk, TCP_CLOSE) in mptcp_stream_accept()? > > __mptcp_close_ssk(sk, ssk, subflow, MPTCP_CF_PUSH); > } [Severity: Low] Can the lockless READ_ONCE(msk->rcv_data_fin) check in mptcp_close_ssk() race with the subflow side? The check runs before lock_sock_nested() in __mptcp_close_ssk() takes the first subflow's lock. The emulated DATA_FIN is written from the subflow's softirq / state_change context: subflow_sched_work_if_closed() mptcp_update_rcv_data_fin() and the msk lock does not exclude that path. mptcp_pm_nl_subflow_destroy_doit() in net/mptcp/pm_userspace.c holds only the msk lock and has no fallback check. It can select msk->first and does: mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); mptcp_close_ssk(sk, ssk, mptcp_subflow_ctx(ssk)); Consider this interleaving: 1. mptcp_close_ssk() reads rcv_data_fin == 0 and is then preempted. 2. The subflow receives a FIN (tcp_fin() sets SOCK_DONE), then a RST. sk_err is set and the error report is deferred as MPTCP_ERROR_REPORT. tcp_done() moves the subflow to TCP_CLOSE, and subflow_sched_work_if_closed() sets the dummy rcv_data_fin. 3. __mptcp_close_ssk() locks the subflow, sees TCP_CLOSE and calls tcp_disconnect(), which clears SOCK_DONE. 4. At release_sock(msk), __mptcp_subflow_error_report() finds no SOCK_DONE on the subflow. It moves the msk to TCP_CLOSE and sets sk_err. mptcp_check_data_fin() never runs on this path, so recv() would return the error instead of EOF. Moving the MPTCP_WORK_CLOSE_SUBFLOW bit after the dummy DATA_FIN in subflow_sched_work_if_closed() only orders the worker runs that the bit triggers, so it does not help this caller. This is a rare corner case. It needs a userspace PM (CAP_NET_ADMIN) tearing down the only subflow of a fallback connection, plus precisely timed peer packets. Would it make sense to re-check rcv_data_fin under the subflow lock before disconnecting, or to stop relying on SOCK_DONE surviving on the subflow? [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-net-mptcp-misc-fixes-7-4-rc7-v1-0-9f03efcb1a17%40kernel.org