From nobody Mon Nov 23 20:27:01 2026 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=1794599664; b=OJA4Zu0vFFeetQ1DYAjybjtGzWn/Zsd4Bc+adO+myE3uG41iFijd7ydU7xJRiBvzw3b0 k2Oct1+FyXQfi+6bLZSTAAisbB6qcx+xEW40V+aoZqDsAL8aF7HXmC5RWplHd2GjfIEqu ZWi2Q9d/z+jd/BdnBVEWi44Qxqcu4mtx2IntSq6DMrkK+695PBNqTA5UzfS6iroUbTBQ5 nh2liu1aG9MxfpxQv5nze628SpjGlt4DyYxtK1tIAuFkxRPsOWDvQWPNdxhcPMWJarzb2 yjf392hw/JHtJAK0B0eNAR2NIbo+DjUYWKRqsjZVtnfcQJsVgbElEaCWUQJtMHEE3NA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599664; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=WlVoQwBOD98FsntzSXYjwcQNRhMCA32Z4TULn6kiQX4=; b=HElqvsxXF7ypku0QA9enNIoOkdZqHdveyGBFwf+YF6Ad+RW5kmKwMzIsttWlQnfQbSMG oOVRev+cw1Mq+8z4t36Wa07asChCgEQuNsXpzrbYlGAcNAc9BZt5DSLNWixf2BjOw1sK7 FZjNR/GEycRYedvbnfuD8Cjlumx6UyXoioJROjwCH6t3Pq3uBfhzbnYTBA+KPSqsSNOyW Y61fwMWcink5L9UtpGJ3X30kynBQpm7vDPNKo/h4PZVUAGoN+ShkGrUi2MrJPO7bht4Q7 qmmGxsz98PPq4TZaCvXjrQM14iyX6Umt14Ph7HntQq5tt3RMni8dEpYurSP3cdqfvmA== 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=YSLpblRr; 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 37ED760A6F5E for ; Fri, 13 Nov 2026 19:54:23 +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=YSLpblRr Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AADE1F000C4; Fri, 13 Nov 2026 19:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599663; bh=WlVoQwBOD98FsntzSXYjwcQNRhMCA32Z4TULn6kiQX4=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=YSLpblRrLQ8BLC/+sXbyQwTbEtr5BFndCGhVi7dT0d7gtkBLXTErtggBNdrONYSDj jcR0F624asOo04MTDLgu0Jb/fTJYhVUBDA5ebWXrxy5pEDrXuhX5VnY30vE8Ja7tMm Skzd800DLF4N+oMlxAVQj9vIxf09PNbZkd/Y7FGf0jsUuizwB1mLC64ptY6mOrDA4N HFT5BHTP5Dyfd4Lwmg9H1sg+G1Xg1L9L+rmiOzlbI9Ras5JjyxjI+gSCc/yYT5naYh KsIuRWaDZsLCeXBoDJnAr1rxPAoTlH3lQcxLR/B+yUEZkfczyAJ+N/Ubh45iQzcuGP fxVyB9TfBj/nQ== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:39 +0100 Subject: [PATCH mptcp-net 01/34] tcp: drain the queues of a listen() that fails 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-1-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3030; i=matttbe@kernel.org; h=from:subject:message-id; bh=ui59Jfi6boLWjAp+vVvjeH9o6lXzt/dtmY5zVvV9JUk=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z10yvx0RmPfIyKppp+b53d2N5ms5xHqZjy531T97O zhg14x1HaUsDGJcDLJiiizSbZH5M59X8ZZ4+VnAzGFlAhnCwMUpABc5zcjwKbD45wff730dNxnX 79Q6KXn7EqfPodNfSuN1D17qCiiPYWTY5nx768nXm97lb9yxf/1Ta4kb/zb1pZ+WlPK3/6XNu+Y MNwA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason If listen() fails on a TCP socket that has listened before, the sockets of connections from the earlier listen() can leak, together with their network namespace. inet_csk_listen_start() sets TCP_LISTEN before it calls get_port() and hash(), and its error path only sets TCP_CLOSE again, which relies on nothing reaching the socket before it is in the listener hash. But pending request socks outlive an earlier listen() and still point to the socket, so in TCP_LISTEN, inet_csk_reqsk_queue_add() adds them to the accept queue and reqsk_fastopen_remove() adds them to the RST queue. These entries, and the sockets that they hold, are never freed, since close() drains the two queues only in TCP_LISTEN and the next listen() stores NULL in both heads, rskq_accept_head and fastopenq.rskq_rst_head. The fix used here is to call inet_csk_listen_stop() after the error path sets TCP_CLOSE, except for an MPTCP subflow, which needs mptcp_subflow_queue_clean() first: mptcp_listen() has to drain it, which is done in the next patch, "mptcp: drain the queues of a listen() that fails". This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch, run as an unprivileged user: listen() failing with EADDRINUSE in a loop, while the connections of an earlier listen() complete. Without this patch, sockets were leaked, and network namespaces too when each round was in its own one, without any message from the kernel: result: request socks: 10000 made, 3025 left. Sockets: 33205 made, 6050 l= eft [...] result: namespaces: 1000 made, 735 taken down, 265 left Fixes: 8336886f786f ("tcp: TCP Fast Open Server - support TFO listeners") Signed-off-by: Chris Mason [ Shorter comments. Commit message: how the issue was found, and its symptoms. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/ipv4/inet_connection_sock.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_soc= k.c index 5807067083c9..3d9cc189c807 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1355,8 +1355,8 @@ int inet_csk_listen_start(struct sock *sk) =20 /* There is race window here: we announce ourselves listening, * but this transition is still not validated by get_port(). - * It is OK, because this socket enters to hash table only - * after validation is complete. + * This socket enters to hash table only after validation is + * complete, but reqs of an earlier listen() may queue children. */ inet_sk_state_store(sk, TCP_LISTEN); err =3D sk->sk_prot->get_port(sk, inet->inet_num); @@ -1371,6 +1371,10 @@ int inet_csk_listen_start(struct sock *sk) } =20 inet_sk_set_state(sk, TCP_CLOSE); + + /* MPTCP subflows are drained by mptcp_listen() */ + if (!sk_is_mptcp(sk)) + inet_csk_listen_stop(sk); return err; } =20 --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599665; b=kte+2t1rpKNxn7d8YQhZIPTGyvhXpLp+/KIMu660R+qTc7cq5xZQstKzG0ARitUD4uTS AmEutc9W2UfsVuATLHE+RO/SUvP9cC/NfiV9tMHVHCuJNQoV5eXsK5dJm4IJF/tphC0yR L3KNiTOSvdOUY5s1ICKqYBCsQ2+c/ZgD0wHxY6OafukissAK/4b6i5k5vzJUihSp8EzjW 2IGeOdHOhRoYkgKyX7IfLg7GYOoI0wSTMSaIhqeGZ25u7PcMSP6wFeF/yZnW/VbiuIAIG +vC9kqlRAzavAmoDXNFqdAs3Lx6+DfKA66bFDt9m9nB6OpvcuOs4XWorrC/RPHJY+CA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599665; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=XNrmfjZiaB6NkyhG5fiXM+iL/tqpZkpvhMu0Sz63ox8=; b=VTBoPX3j7WcIWJi3bvEewns+lP88PZa3NmMr6dQcYFIYkNurTq/gVs9H8b2HHs4zbPRo X+DOb2HEhZXPVIvP+RW20CnMk1st6foS84N4Ex38Js0tIm0n660dB9yu7ODQP5mw6tcUC jEtRakRsdUoszEiiH+CjytjsbnqXDqhYiqDh+FKa0SsPM6M6oALCkhUtwgBg1zPrO6xY6 GXg+xN6njCkT5ZIh4vpp9/3awna3SeuL1SFFL8B8HtUTUe5QH0Q+XzXBrBRE5+BuAdi4v 6lhEx0kEnCMZ8pDKO8cOiUpm64jMkI9cD/pRcgqxBpO6eBdxyyLNotsBdPll3yf5uOA== 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=Tu9Qthix; 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 1E62060A6F69 for ; Fri, 13 Nov 2026 19:54:25 +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=Tu9Qthix Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38C2A1F000C5; Fri, 13 Nov 2026 19:54:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599665; bh=XNrmfjZiaB6NkyhG5fiXM+iL/tqpZkpvhMu0Sz63ox8=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Tu9Qthix8Mv1tm61Cwt19l1pwOr3lCFPOfVdqsp74OKsH6snoNEnFspcMOTgxDDHG qFp/YhMMnbAj1JFD3R9ITiTuH5+jZIJE0hachupvuphDmMdDJwjT8wm/kElFc9BW+e 4GlsjmrVVSfozYqjc2rum5sAxSILFepRrd0DNO37OnAVioZe/8+i3pCt/pDaLnflij 97TzZfku95SJ0bMrNTlIfsyOCnRGdxpvr81wbWWnOG3YZUoRs4q2fxGUcNdZooNmeS cj9JkggP/OK3PkgSwKYPo8hi9YW19iQaUKxsVX6gu3sRzN4OEQ8GmOq6RuJh5cqWcO WraWsJDsuQhIA== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:40 +0100 Subject: [PATCH mptcp-net 02/34] mptcp: drain the queues of a listen() that fails 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-2-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2209; i=matttbe@kernel.org; h=from:subject:message-id; bh=FyhXXk17aUixRyn+l+SOX/PtJtKBYobZnYhfU6yRSNQ=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z13++vnsmivna7ND/1/RLPDp+HRw9p2XMrMYL1hM2 n7nRwrb4Y5SFgYxLgZZMUUW6bbI/JnPq3hLvPwsYOawMoEMYeDiFICJPN3LyLBnF9PbZHsXf81n mf0lzEaWE5Y41F5pTPkjGaXx6Pf52R8Z/vDfUA5Yxfs/6MCtzk/3UzQa26y2VJW28dad+3VjR3b lQQYA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason Sockets and their network namespace can leak, if a handshake completes while listen() fails on an MPTCP socket that has listened before. mptcp_listen() passes the first subflow through __inet_listen_sk() to inet_csk_listen_start(), which sets TCP_LISTEN, then calls get_port() and hash(), and sets TCP_CLOSE again if either fails. Until then the subflow is in TCP_LISTEN, so a request sock of a previous listen() that still points to it can be added to its Fast Open RST queue, or can get a new child and be added to the subflow's accept queue. But neither close() nor the next listen() frees what is queued, and the earlier commit "tcp: drain the queues of a listen() that fails" skips an MPTCP subflow, which needs mptcp_subflow_queue_clean() before a drain. The fix used here is to call mptcp_subflow_queue_clean() and then inet_csk_listen_stop() on the subflow in mptcp_listen(), if __inet_listen_sk() returns an error with the subflow in TCP_CLOSE. This issue has been found with the help of an LLM. It has not been reproduced: the reproducer of the previous commit only uses TCP sockets. This fix is based on code inspection only, which is acceptable here: the issue is similar to the one fixed by the previous commit, and the fix is simple. Fixes: 76e2a55d1625 ("mptcp: better msk-level shutdown.") Signed-off-by: Chris Mason [ Shorter comment. Add a Fixes tag. Commit message: how the issue was found, and why it is fine without a reproducer. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 50de5cedfd0f..dd9fb803cad5 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -4381,6 +4381,11 @@ static int mptcp_listen(struct socket *sock, int bac= klog) =20 lock_sock(ssk); err =3D __inet_listen_sk(ssk, backlog); + if (err && ssk->sk_state =3D=3D TCP_CLOSE) { + /* inet_csk_listen_start() leaves this drain to MPTCP */ + mptcp_subflow_queue_clean(sk, ssk); + inet_csk_listen_stop(ssk); + } release_sock(ssk); mptcp_set_state(sk, inet_sk_state_load(ssk)); =20 --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599666; b=1g7aXPs6hPXwXWkjAGQKL1E3BlCDuesB+vHieozX1ujFhqs6VngC2WBTrhhKK3Ot/Q64 4TM78Uwuq/zFQ6riz9/2vgsq9/t59bUPUTyW3/rUCRJg41s56K70tpdU6ORYBoN8GzDUu JF3vFh/JK1fht4FelqMCla19HYwsca0pY5DKWwkelqOohQcZljpNaQ+SL7f0EDxLYpogW rwRHLofAz4l76BeNK6EhFpQwIl1ZJDdkAKdkFjAmf/b6g+mCDFJaI0GrW1mjzFzud7KCc ls7TOzwvuR3YeFUFRcyO6xmRfMYzarm0+GWovfeLPB4WizJyvQvfZiBevBeQCyeNFUw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599666; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=6T6vAM/UYYNAG/KfBhyUtGdv9jtMFIL9SqqzO9sTaos=; b=F6xdmL+SuZ1Z2zpZ6qhY0eyUKc69NRwMuCfzq8btqXQC9vh9zge59s3bcN1RvuZc3w39 t4WnoLm22+Bo+KRn8wnxhRo7HJ9qaWARhIJluyIO18D8HS/yQrmSRPOtgn73+eITG/G+M SqE3iNpA1kM5llb/l5ckEKCnQCUh99eMZlk8D+sic6IlyMaotLEGXYmoImAA8qZMoUTsu tPWr80hb8FDS8CXHoRHDdi2e6AEe4riMp7Eadagu1Tbt5BR2QU+CjsyqcjtZTOqmizMO/ LjP/50TN+sgbZV71xcv5K6ntr1ZatFb2oHbeg0Y7EV1z2uoyOiETzJ/bpctaM4KPGiA== 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=lnqX98it; 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 387D160A6F6D for ; Fri, 13 Nov 2026 19:54:26 +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=lnqX98it Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57FEA1F000C5; Fri, 13 Nov 2026 19:54:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599666; bh=6T6vAM/UYYNAG/KfBhyUtGdv9jtMFIL9SqqzO9sTaos=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=lnqX98it6T623KEG9NZr5w5J0885tRbtoDRrkcxzou/15GTSWgXxP6ImsS4saTSBV pSTWhgF3ewNdEzOwdw4znUmZjcd7m+Lpv7FsR0XFcZL7T6lUChkFDk4i5Fhzp6VPIN sLeLZm5V78JYG18W0oCj3fyKZd7GVZEwA8THJFiJJ9AstqBVGnG2nK81Hoy4UxciVu 0DunIxzvQpgE1eI7tQ6gA1YRkR7yl6P5fvo7rTxRQFTZ9logPEQ17kNVLN0q/9TBfL tegiPWH/f0DKTdA/eMF7U5kiDbaOJrJFGYfdDWnzWO08rKSz7zm6IFoc0/BjPV4g0E dN8N5jM4TpuOg== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:41 +0100 Subject: [PATCH mptcp-net 03/34] mptcp: clear inet_opt in the child of an IPv6 listener 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-3-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4179; i=matttbe@kernel.org; h=from:subject:message-id; bh=Rzcn4x0uv7194O3/3ueVGB7t+tIsqSmBs3iIC4u/oSI=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z112YvWX1DqwJZi/ZOuEb1lmS/ocROb4ydhZh81T/ cd21+dJRykLgxgXg6yYIot0W2T+zOdVvCVefhYwc1iZQIYwcHEKwERMQhgZvq7dL3f3/2KvlTMP ik/ma9ihOXF/hBV3TcqH46cMMpd952L4Z5PFcqek+GLb1qY1qn5XWuMPam+Y9iFYnHHfQ9vrAR6 xzAA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason With SELinux, an IPv6 MPTCP listener and its children can cause a double free of one CIPSO option, and then a use-after-free read of it, if NetLabel uses CIPSO for IPv4 and selects the IPv6 labels by address. mptcp_sk_clone_init() creates the child of a listener with sk_clone_lock(), as a byte copy of the listener, so each pointer in the copy that the socket destructor frees has to be replaced or cleared. mptcp_copy_ip_options() duplicates inet_opt, the IPv4 options, for AF_INET, and mptcp_copy_ip6_options() duplicates the IPv6 options for AF_INET6. But an AF_INET6 socket has an inet_opt pointer too, and its child keeps the listener's pointer. MPTCP does not support setsockopt(IP_OPTIONS), so that pointer is usually NULL. But if connect() gets a struct sockaddr_in, netlbl_conn_setattr() does not look at the family of the socket, so the connect() hook of SELinux can store a CIPSO option in inet_opt of an AF_INET6 MPTCP listener. inet_sock_destruct() then passes that option to kfree_rcu() for each child and again for the listener, and after a child has freed it, another such connect() on the listener reads it in cipso_v4_sock_setattr(). The fix used here is to clear inet_opt of the child in mptcp_copy_ip6_options(). This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch, with SELinux, NetLabel -- CIPSO for some IPv4 addresses, and the address-based selection used for IPv6 too -- and KASAN: an unprivileged user calls connect() with an IPv4 address on an IPv6 MPTCP listener. Without this patch, an object is freed twice: BUG: KASAN: double-free in rcu_free_sheaf+0x23/0x100 Free of addr ffff888012c27a80 by task kworker/1:1/50 CPU: 1 UID: 0 PID: 50 Comm: kworker/1:1 Not tainted 7.4.0-rc1+ #1 PREEMPT= (full) Workqueue: events mptcp_worker Call Trace: kasan_report_invalid_free+0xd4/0x1b0 check_slab_allocation+0xc2/0xf0 __rcu_free_sheaf_prepare+0x102/0x2a0 rcu_free_sheaf+0x23/0x100 rcu_do_batch+0x29a/0xf80 rcu_core+0x33c/0x830 handle_softirqs+0x212/0x980 do_softirq+0xb4/0xf0 __local_bh_enable_ip+0x11c/0x150 mptcp_token_destroy+0x1c9/0x360 mptcp_destroy_common+0x2d9/0x430 mptcp_destroy+0x86/0x110 __mptcp_destroy_sock+0x176/0x350 mptcp_worker+0xbb5/0xf80 [...] Allocated by task 176: [...] cipso_v4_sock_setattr+0x9b/0x3d0 netlbl_conn_setattr+0x3ac/0x500 selinux_netlbl_socket_connect_locked+0x102/0x210 selinux_netlbl_socket_connect+0x23/0x40 security_socket_connect+0x2e/0x60 __sys_connect_file+0xcb/0x200 [...] In another case, the CIPSO option is used after having been freed: BUG: KASAN: slab-use-after-free in cipso_v4_sock_setattr+0x3c7/0x3d0 Read of size 1 at addr ffff8880161c2f18 by task python3/177 CPU: 1 UID: 65534 PID: 177 Comm: python3 Not tainted 7.4.0-rc1+ #1 PREEMP= T(full) Call Trace: kasan_report+0x101/0x140 cipso_v4_sock_setattr+0x3c7/0x3d0 netlbl_conn_setattr+0x3ac/0x500 selinux_netlbl_socket_connect_locked+0x102/0x210 selinux_netlbl_socket_connect+0x23/0x40 security_socket_connect+0x2e/0x60 __sys_connect_file+0xcb/0x200 __sys_connect+0xfd/0x130 __x64_sys_connect+0x72/0xd0 [...] Fixes: cf7da0d66cc1 ("mptcp: Create SUBFLOW socket for incoming connections= ") Signed-off-by: Chris Mason [ Commit message: how the issue was found, and its symptoms ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index dd9fb803cad5..e484f7edad49 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3718,6 +3718,9 @@ static void mptcp_copy_ip6_options(struct sock *newsk= , const struct sock *sk) =20 newnp =3D inet6_sk(newsk); =20 + /* The IPv4 options belong to the listener, which frees them */ + RCU_INIT_POINTER(inet_sk(newsk)->inet_opt, NULL); + rcu_read_lock(); opt =3D rcu_dereference(np->opt); if (opt) { --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599667; b=hBLJvXPKUHtkPXgQu44ij6VOUglwRxb3VELmWi8pqtyk4Mf9EGO+lUqpLknQRROzWZA2 seUoPUwO1rIErUfAlPKrNJUlor5wKRIfZspKNaRmvq+y67Xn8LLFB8afUc7vqCbw5XrUo 1UFBIUhnHBsN8jfoubiMXn+nHTf29RvKoae2W0nBfR/WiShk9sfwDvRoKn+6GP+02JZfR se1WDeE4Ca63o/ctX/3uJdwLnr/uOcIbIuPwUx9kubKDdcUshWQyq9emzjqecpPRxyW8s e7w8G1B5/Ho04Df/IK4tOEje9ago9DYKYmUhm6ms+p0NZ8dWDTJQqrwXrEDi7EVuACw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599667; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=hVd6hiqFUCnHcgLi3LbAmEYhmx6SH1ijyBmtPpgPEq0=; b=O9lAvPiBFCOH3v17CAWSfcsvBkY2FqYtwTf66DX7pNS3/4niw9IU4/QvJEtw7DcYWYLN 4itiY3Um2T23lZf/Q8HvHlh2ll6op217gOtGMLEZ/reeJOPNX0rDUzv75tke8ic+sYn7N nI0VU4cmCIxPH521U/N8C5uaVwkv5XZpliO1FuBJYhURHD8Kq5dHQ9gB9OBKST24wQwE2 JrSE/OxcSapEZekfsTovk+ilN+n88WgyxZgAE2KbhWDlo5FO944sNpGUiPKLNVT3cilob 8TnYtk/X9MYN41uMG1injhAQxOWWX8F+shadDiRVq2a7XUIInJ30zw1VUXX6+AYtBMw== 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=fS1+5VkN; 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 7D1C860A2627 for ; Fri, 13 Nov 2026 19:54:27 +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=fS1+5VkN Received: by smtp.kernel.org (Postfix) with ESMTPSA id 766B01F000C6; Fri, 13 Nov 2026 19:54:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599667; bh=hVd6hiqFUCnHcgLi3LbAmEYhmx6SH1ijyBmtPpgPEq0=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=fS1+5VkNbhHVEBybPw4PcaAa1tvQ+wvh7cEU6bDFltCDj2DMb6j9RBHRSfaQGEy+a Lw3Jcd+8KGEgxvy07SstS6kUBQkcdbh61kg9N72Db5XRcdqwXSymZXMMEcSjvY2HZr 7i5732POw0I54SuZK1OImx4iCiZ+uIUuPCYT75pUenUY+BDcsYvBc9rvkOvvJYsyPQ oh7wKhXAmNkMAMixNN8Da3eC1IF98tOzp6EyuBXRR7JOwvfjO6xXy5ao/ybDJxrZDU jtBF+keRygieI92gwUctcYmS574V5Y057LMa/6QdCQqUKQ21yNsSQ0fpSv7REolZRF /9rsCtZXqXFiQ== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:42 +0100 Subject: [PATCH mptcp-net 04/34] mptcp: pm: work on a copy of the received RM_ADDR list 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-4-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" , Josef Bacik X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1776; i=matttbe@kernel.org; h=from:subject:message-id; bh=H2fyBuEiMX3mZSO0V08Z9k1BTg37/v93dXMYAiWsMx8=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z12RMTuYs0Qub96PY95uU7XD7/26HsH/7PlBKY5d7 yuXPvNS7ChlYRDjYpAVU2SRbovMn/m8irfEy88CZg4rE8gQBi5OAZjIQVuG/xFvhX2OZMyctTGB v0Lkigjv98r6Ow0rumQDQ1KLQv+2BDAyHDX5PefxguxvJ0TsZKbe5lt510gwTeewk/00nS6m2MP dbAA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Josef Bacik The worker clears MPTCP_PM_RM_ADDR_RECEIVED and walks pm.rm_list_rx in place. For every subflow it closes, mptcp_pm_rm_addr_or_subflow() drops pm.lock. If the peer's next RM_ADDR arrives then, the flag is clear and mptcp_pm_rm_addr_received() overwrites the list. The walk goes on at its index in the new list: the ids of the first list that were still to come are never handled, and their subflows stay. Hand a copy of the list to the walk. This issue has been found with the help of an LLM. It has not been reproduced: the next RM_ADDR has to be processed while the worker has dropped pm.lock to close a subflow, a window that a Packetdrill script cannot target. This fix is based on code inspection only, which is acceptable here: it is simple, and the issue is clear from the code. Fixes: d0b698ca9a27 ("mptcp: remove multi addresses in PM") Signed-off-by: Josef Bacik [ Commit message: how the issue was found, and why it is fine without a reproducer. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index d7c5b50b34cc..cdc8bab0eaf8 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -827,7 +827,10 @@ static void mptcp_pm_rm_addr_or_subflow(struct mptcp_s= ock *msk, =20 static void mptcp_pm_rm_addr_recv(struct mptcp_sock *msk) { - mptcp_pm_rm_addr_or_subflow(msk, &msk->pm.rm_list_rx, MPTCP_MIB_RMADDR); + /* pm.lock is dropped on the way: the next RM_ADDR may come in */ + struct mptcp_rm_list rm_list =3D msk->pm.rm_list_rx; + + mptcp_pm_rm_addr_or_subflow(msk, &rm_list, MPTCP_MIB_RMADDR); } =20 void mptcp_pm_rm_subflow(struct mptcp_sock *msk, --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599669; b=UK9JI7hIfpSWPZ3dsBfHsfujUTGuQRXPpRMabW+LTBXRiPOFLQ49SzymiWNezDJRh05U 8dBN1/gPvZm3FRyjAhUATgO1mVsFdlDlUtWE12MQc5JP5vWWFnOk38axg1fGLclGJqYZU 052kFJ9yxSAF0nbmEyF3jECYlhTD2k5OTBYB5RCwNYucy47nW251dUS8aCEV+HxyID3fK b2Qqz16Nr3YBaiqyjBWztXy51WQkAjJZLk+NiXtaoIbMMczxabcHWNZOD7/8elPJcv/QQ Bh9W0kLIwYZlr1ojLL+UCQ+h5y+7+hMT5lTFnupON3ZFYnZVt6RK4gkKuSlE2B4mEnw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599669; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=pIJMHnRdCwVKIYsgFZ5T+kBxkxkkR38tgRiZu8o6Opg=; b=35Wd5lo74P+AkEr60lr7jhJXGEcU8QnHeR6yK9+OM2nryZYmUXum/xPeZ8XGAWPfb5Fh aUhsskbJQR0u2NYkZ+UUmnF2WRlZ7fu96gbd9uKyoNXvf69j0MuPv466TKwZUVVoEhkO7 pZJ5V0skBgDcXNBqKvl9hjSpGq3VJPPmymayWo5NWmZ2wOqTlpoToxWUJqRaqbDz2q0g6 9mI+sZPMZ0pKWKi7xaPSdLr2JzdVINDaPXIYfZLeiOgAdIiaNQDzWfblWo4QI3mCEYbY5 cIW5xnSDih4PcUJZ9YoLihTIps47uJZLHPQWkok6fzB8L9LuJV1/cxTPr6abpULhDCQ== 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=ENqb+V9G; 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 EB6B060A6F7C for ; Fri, 13 Nov 2026 19:54:28 +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=ENqb+V9G Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBB951F000C7; Fri, 13 Nov 2026 19:54:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599668; bh=pIJMHnRdCwVKIYsgFZ5T+kBxkxkkR38tgRiZu8o6Opg=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=ENqb+V9G2/lGhvHxdGZN3n7vnqfIS5HyE2+IloAeA/DHN77MCRhet4Q3788Gs8pxP eZSE/9JSBZ+dDwlKry4/OyZl/rRIfyZoXXkm+2TlxUzeZRLECZQ8oEtPvoteIs/q2A tWXVh+F/eyCQgxjzgxKapVTyquCj3T/cD9R/wVT9kjOZb/LqDMze9eL/y/k3kYkMMA TLfWQWLxgrL91bUcDYg8k/vitc5tzo5n6h+rHr75GMX62nchiknh9L3WhYY/VHAFD/ cPcnJCmKfR43+EFZdsu975pjqPGKKuGSGhdaQeKSwJEdM/a43Vm9IYFasvUzKnjlft fXwQ4QSwd08Ng== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:43 +0100 Subject: [PATCH mptcp-net 05/34] mptcp: pm: don't drop an RM_ADDR behind a pending one 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-5-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" , Josef Bacik X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2440; i=matttbe@kernel.org; h=from:subject:message-id; bh=C1VQzHk8uVoIp8Rzb5GCSvVci1o7UytyuySN6PWyaSU=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z129WXHr2WTZz0dZ/gptqfbds/rAb4HZnLr8D5zun nn9XmxBRkcpC4MYF4OsmCKLdFtk/sznVbwlXn4WMHNYmUCGMHBxCsBEToQwMrzln+JpVn7mxX77 td3GRnLTJDm2PLukumyj6mOJ4z9nf/7A8M8q+KGueebsDfz2SzL3Flic7nm9ZJfB5FaeQ5P9N79 dMJMDAA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Josef Bacik There is room for one received list of address ids. An RM_ADDR that arrives before the worker has taken the previous one is counted as RmAddrDrop and forgotten, although the netlink events for its ids have been sent already. Two options follow each other at once if, for instance, a path manager in user space removes two addresses of the peer. The subflows to the second address stay. Add the new ids to the pending list. Only the ids that do not fit in the list of MPTCP_RM_IDS_MAX ids are dropped, and the RM_ADDR is then counted as RmAddrDrop. This issue has been found with the help of an LLM. It has not been reproduced: the second RM_ADDR has to be processed before the PM worker gets to the first one, a window that a Packetdrill script cannot target. This fix is based on code inspection only, which is acceptable here: the issue is clear from the code, and the fix is simple. Fixes: d0876b2284cf ("mptcp: add the incoming RM_ADDR support") Signed-off-by: Josef Bacik [ Commit message: only the ids that do not fit are dropped + how the issue was found, and why it is fine without a reproducer. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index cdc8bab0eaf8..32885e80486e 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -843,6 +843,7 @@ void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list) { struct mptcp_pm_data *pm =3D &msk->pm; + bool drop =3D false; u8 i; =20 pr_debug("msk=3D%p remote_ids_nr=3D%d\n", msk, rm_list->nr); @@ -852,8 +853,20 @@ void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, =20 spin_lock_bh(&pm->lock); if (mptcp_pm_schedule_work(msk, MPTCP_PM_RM_ADDR_RECEIVED)) - pm->rm_list_rx =3D *rm_list; - else + pm->rm_list_rx.nr =3D 0; + + /* the worker may not have got to the previous RM_ADDR yet */ + for (i =3D 0; i < rm_list->nr; i++) { + if (memchr(pm->rm_list_rx.ids, rm_list->ids[i], + pm->rm_list_rx.nr)) + continue; + if (pm->rm_list_rx.nr =3D=3D MPTCP_RM_IDS_MAX) { + drop =3D true; + break; + } + pm->rm_list_rx.ids[pm->rm_list_rx.nr++] =3D rm_list->ids[i]; + } + if (drop) __MPTCP_INC_STATS(sock_net((struct sock *)msk), MPTCP_MIB_RMADDRDROP); spin_unlock_bh(&pm->lock); } --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599670; b=O6gL5kp+CdOWTsh9CXN0S8YVTT6+WNe6pXeq9Ae6qWWnG3ggpSKiumesGpur5tq7x1W3 zogWeVrv8S4gbKIXLOuo3O1JogoXe9z9pTFMbP0+gxqA3r69ZBrFeCLgLSUgFwvDj+b2p Da9soE7rsW9tSSEPJDwo50QFYtrYpy88uFI4Yt1/LveDdX57CQi3zuFQ4RKLfWuc/J+Qg Pw6a5UsdmuNANdRMXGmJ7I7hLhvD1VBrCtD3L8/++B09kKeCX8qrQfhEZTkM1OK8UaTGy 4Jqz2puu/aQZpJ5j3U9gpVgt8kTXErv9M3jxebth/0yZUBfU2OetfimtfltCGDDbNyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599670; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=FUvnrfoIrWP4sWFanNSiwxm5cYNY7XEqtjgBEaMWZs0=; b=Z3z2BWg8zWjOkbKJoFGmtABGCoMZtm1ZlR73qTwgFF7OZ7M5vdnrzFfhcfHzkv1z3G0l XixgkbfV3PqrQkc34woA4iusw4QLmWa6Xr9uL+l8Y3wmzcry8JiwnX6uO7myjskTydYBR 3hmgEVSjdLCKw6ECObT1xT6UJNKBVUscYo47BHHFgXaru1emYpAdks9eQyLvRFuNFO1K1 5itb2s8cmh3EqAINvQGZ9zk01yjlOrdeWvypuNUf+U+7YcPpWJPm07BhcwGwQQ6/LdIFc gVo7KgF/NmBErFfm15DIXP8DxwAbvD9cA5SUqaWOzcELb0TN3gdDxBLTdpsLhLsu0Qw== 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=iYnBfjmr; 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 4F70B606F340 for ; Fri, 13 Nov 2026 19:54:30 +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=iYnBfjmr Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B4F61F000C4; Fri, 13 Nov 2026 19:54:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599669; bh=FUvnrfoIrWP4sWFanNSiwxm5cYNY7XEqtjgBEaMWZs0=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=iYnBfjmroCHaA+tSYKncqbP1peJ2C4R+mQ3v01rWQcVqbMFE/8H7PTW5JT39y0fwZ 82XwD6DtdPpB8/Zm8vMEecQhYulBCOmkkmvq+cFJqVgvrL5fwZu7dDh4t31ZaYOdW3 A6vWGdsiAP/7at0JHQJYuZAx6kZzh+wIDkmJdVVEtMv9dnVEPdAjLjyUxVjoRi6FZd jk6jLzFzLBfZw9JpRMZXwf2rB+eocrDNViZc398m25kFi2BaTitX+nU4WzmTnSZEb6 UJihGsVz6BwANWiCtKyjaXyIxd8MiCufc5FPmZ1Ogs32wAGRSoDJzp2pOTsGWwqV99 sd1CKw1+Kc+YQ== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:44 +0100 Subject: [PATCH mptcp-net 06/34] mptcp: pm: don't drop an RM_ADDR because of an ADD_ADDR 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-6-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" , Josef Bacik X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2542; i=matttbe@kernel.org; h=from:subject:message-id; bh=do3Obgl9vpdsCRt/XgX/sgciaoCCsctSSJRHUxkkuHA=; b=kA0DAAoWfCLwwvNHCpcByyZiAGr3atWiQN4+wi3ktEgWa6EJqCiTXxvM90szw3kPiey0h+DNW oh1BAAWCgAdFiEEG4ZZb5nneg10Sk44fCLwwvNHCpcFAmr3atUACgkQfCLwwvNHCpeojwD+JDLi FkVtT+BKK7dBuo40kihyA78mlESztZ4MvMkxGvIBAMTt97mVTYSdB9hcPPfZcM5QC8hLtcoJToe LsPPyyoYL X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Josef Bacik mptcp_pm_remove_addr() gives up, and counts RmAddrTxDrop, if any bit of pm.addr_signal is set. That dates from the time when the byte was cleared as a whole after a signal had been sent. Since commit 119c022096f5 ("mptcp: fix ADD_ADDR and RM_ADDR maybe flush addr_signal each other") an ADD_ADDR, an echo and an RM_ADDR each clear their own bit, and they have storage of their own: pm.local, pm.remote and pm.rm_list_tx. mptcp_pm_announce_addr() looks at its own bit only. The callers have updated their state by then and ignore the result: the endpoint is gone, the announcement is forgotten, and the peer never learns that the address is not valid any more. When the bit of an echo is set at the arrival of the peer's ADD_ADDR, it stays set until the PM worker has sent the ACK. An endpoint that is removed in between loses its RM_ADDR. Only a pending RM_ADDR stands in the way, as rm_list_tx would be overwritten. The ACK that is sent at once carries the ADD_ADDR or the echo then, and the RM_ADDR goes with the next packet, e.g. the ACK that the PM worker sends for the pending echo. This issue has been found with the help of an LLM. It has not been reproduced: the endpoint has to be removed before the PM worker sends the pending ADD_ADDR or echo, a window that a Packetdrill script cannot target. This fix is based on code inspection only, which is acceptable here: the issue is clear from the code, and the fix is a one-liner. Fixes: 119c022096f5 ("mptcp: fix ADD_ADDR and RM_ADDR maybe flush addr_sign= al each other") Signed-off-by: Josef Bacik [ Use mptcp_pm_should_rm_signal() instead of a comment. Fixes tag: 119c022096f5 instead of 42842a425ad6. Commit message: remove the number of attempts, say which packet carries the RM_ADDR then, and when the echo bit is set + how the issue was found, and why it is fine without a reproducer. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 32885e80486e..5f844b9a32d8 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -529,7 +529,7 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, const = struct mptcp_rm_list *rm_ =20 pr_debug("msk=3D%p, rm_list_nr=3D%d\n", msk, rm_list->nr); =20 - if (rm_addr) { + if (mptcp_pm_should_rm_signal(msk)) { MPTCP_ADD_STATS(sock_net((struct sock *)msk), MPTCP_MIB_RMADDRTXDROP, rm_list->nr); return -EINVAL; --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599671; b=oeM7tbC0XeyVDVPZSeIqNpMmarVMrCrpq8ViR118zZiE1mK3Eph6uuAk06fnhpWCqDcG z0xLN3g/qC3O7ZSBGm+kJniiCppMZt/dLF6vzk9C1iOAceYBdA6/xLxGQuH4kWQwTA9AR wwU6DlP6x0brCUmf5Tjks/rPugOKOeeJ/EOgZlDjjxxLuaw79QDq2neOyEmB6uxrfmApA f7++FfgJgf2BvrhBeHuMxuX+DitoA3dfO4u01lwAuTEx7/paYC5z4rrK6mBk06nIdFijn y6YELtAkWPNZGeBzO1M4ZzE9zkiMRJhc+cvbpEYyu1+oLZ9ch/xwB8cKrG5+9x39I7g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599671; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=j4HmeUuNQnA4qL5jaOPeeDkBW1vR58287ymOw7+6L0U=; b=Efgh0x58nbuy2Ik0tw27XFMcOLa3aZ/CYNrUJzidYETNkeJ4/aFGTrPuJC117CqUyVyL PWq+EFC6TPmuxK1oFu57TMhK5z+exhdrHTsYC7N31us9IaosLGad202nlePMpLM8QGYdn qkbYAqc9Hk0cu7EABzgEw8tHDPDHhZYGTvHsNvVERxkbqxKVTzSJqosrKvVwIen4VDsC3 CsagZSF9UiIpkdy0L69SkEYjqxRSLBKRbotpqId5U2ubdWZmqCUR5+jr8wLwuOQAfJ46Z oiNvYwFpZl7CLA4YQdfMhxkxSp9YeAL2Hsd0Sik5F5zRQ1h0P8f3Ae1Fvzt8lvQt0fA== 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=TB53D8bh; 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 30852606F34A for ; Fri, 13 Nov 2026 19:54:31 +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=TB53D8bh Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F1511F000C9; Fri, 13 Nov 2026 19:54:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599671; bh=j4HmeUuNQnA4qL5jaOPeeDkBW1vR58287ymOw7+6L0U=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=TB53D8bhB/Q51lNPU8H2Jn5LsiZWX5oxZwqueUzUNmx/pD7aTP9dhOh076gwokuJ0 +5R5LXR9am+NPHY9oqecToDYgB+4t0ek1Hbcg/h/iX6jQg2HcwmUVewbGE74CVp+RW zirkB3p+3knfRp9KJRpcOZyVOknsXk8g4SlETxncWm+wIDhUB4Ij6EuF5bQrmn6g5E VJgkeiWI+DyOoj/7Kr+vXCSatzehh0R/Cc87GDNYXAMT1jNv6HTWPGxbrCvaX27zT+ lIF9KWDLxTYyKL/MR8Ef6gqJpELUvI36XMGM1hZOs5WqGEMB/4wktNjVJhezgQqoHs vulJvZ5ET0/QQ== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:45 +0100 Subject: [PATCH mptcp-net 07/34] mptcp: arm the rtx timer if a push leaves data behind 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-7-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3705; i=matttbe@kernel.org; h=from:subject:message-id; bh=4oOMglXua13HpL5PPzR7A1yA1MdsNmkJBBBLtc6om/I=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z117NT1f52lR+7tnPO0KAXcizRaX9Jw7HC7efaDk0 G6B3+7POkpZGMS4GGTFFFmk2yLzZz6v4i3x8rOAmcPKBDKEgYtTACbi28bI0HL7ySPX9TE3Lev1 TpYsFc3jZQ0stjFat9ot98eTkidpFxn+6cied+mRfXRU6/3C1/sX8f6fZ/xVn0HzmuHVvED+7T2 KHAA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason In a memory shortage, send() on an idle MPTCP socket can succeed but leave its data unsent, and the connection stays stalled after the shortage has ended. send() puts its data in the write queue of the MPTCP socket, and the push to a subflow leaves the data there if the memory charge to the subflow is refused or no skb can be allocated. A push that leaves data in the write queue has to be tried again, on the acknowledgment of data in flight or from the handler of the MPTCP retransmission (rtx) timer. But __mptcp_push_pending() and __mptcp_subflow_push_pending() arm that timer only if they have pushed data, so with no data in flight and no timer pending, the data waits for another event, such as the next send(). The fix used here is to also arm the timer, in both functions, if unsent data is left in the write queue. This does not help a socket that has fallen back to TCP, as its rtx timer is disabled since commit e2ab913f68c7 ("mptcp: do not reschedule the RTX timer for fallback sockets"). "mptcp: force the charge for the first skb of a subflow" avoids a refused charge in this case, but not a failed skb allocation. This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch, with fault injection: one skb allocation made to fail during a send(). Without this patch, the data accepted by this send() was only sent with the next one, 60 seconds later here: 3.007 s: CLIENT send() of 1,000 bytes returned 1000. Allocations that wer= e made to fail in it: 1 [...] 63.008 s: CLIENT the second send(), of 100 bytes, returned 100 63.008 s: SERVER has 1200 bytes RESULT-FAILSLAB [...] the_1000_bytes_at_the_server_at=3Dnever [...] [...] arrived_before_the_second_send=3Dno [...] Fixes: 2ea6190f42d0 ("mptcp: schedule rtx timer only after pushing data") Signed-off-by: Chris Mason [ Shorter comment. Commit message: sockets that fell back to TCP are not covered + how the issue was found, and its symptoms. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index e484f7edad49..dc8cdda31a98 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1850,14 +1850,11 @@ void __mptcp_push_pending(struct sock *sk, unsigned= int flags) if (ssk) mptcp_push_release(ssk, &info); =20 - /* Avoid scheduling the rtx timer if no data has been pushed; the timer - * will be updated on positive acks by __mptcp_cleanup_una(). - */ - if (copied) { - if (!mptcp_rtx_timer_pending(sk)) - mptcp_reset_rtx_timer(sk); + /* also retry later if unsent data is left: no ack may trigger it */ + if ((copied || mptcp_send_head(sk)) && !mptcp_rtx_timer_pending(sk)) + mptcp_reset_rtx_timer(sk); + if (copied) mptcp_check_send_data_fin(sk); - } } =20 static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk= , bool first) @@ -1919,13 +1916,15 @@ static void __mptcp_subflow_push_pending(struct soc= k *sk, struct sock *ssk, bool if (copied) { tcp_push(ssk, 0, info.mss_now, tcp_sk(ssk)->nonagle, info.size_goal); - if (!mptcp_rtx_timer_pending(sk)) - mptcp_reset_rtx_timer(sk); =20 if (msk->snd_data_fin_enable && msk->snd_nxt + 1 =3D=3D msk->write_seq) mptcp_schedule_work(sk); } + + /* see __mptcp_push_pending() */ + if ((copied || mptcp_send_head(sk)) && !mptcp_rtx_timer_pending(sk)) + mptcp_reset_rtx_timer(sk); } =20 static int mptcp_disconnect(struct sock *sk, int flags); --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599672; b=R/mq0DIAcEnP/THqt9gWgBJG6RAM2HjkOuvp/YGJqHxq1EArE84k+k0xPcN5jESCjAW8 Pihq5B2E2cVrAatUlgdwBaDMYDQ/JQEuvmPKu11o4r/Q19JuPnMs3WlMaVT7X79lZ4kat 86qkwXYxFXZvx26GEO+PQW/AnlDtyg2J8qTpTsUdH32z4wiyBS5d6HljXWk4lBM59JrW9 5QDWnXzXmGj/JiZDsiw7l6svQhWvZ8vvM/ghfie4v7kYQ27T+aXt78/6nHbKr+yrhPBV+ JrgRZfXhV1KAYdYGA/+GeuIg9SZUHxRawrk5PQIYz8WuWXUZ25dKRlilhfyzNYikmsA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599672; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=/G5+PMtTvr+Lji9tNex0mMGBnXcKq+n71breNybFLwI=; b=NcP6rBH/KBAGqs38/jdlH5EgFGN1zDHGyoUm6WT286PFnhv9miB+FxaT43/Cfssr5iCR GzjPE1H+UBt6UQNe8W63PwG1afS1rJAbb6/duL+VDkj5gf4epzJvsWfmzlxtyT7/jbqf2 /ZzfnusHTYuSm1jw1knT2LtnZxu6u5dt40rYVy9a3VOwBiw9MBo6PZQFBPwjAPYLwMgFG cadQtj20tEh9SKLwK5IamJIglGQGKcV7TWL3GrJgStDFiN1I/bg7s7U1enW7Sb5TvVjE/ 4Eou6Vuab0cist1fEBNBzzvfm2rtjBq1ZS8FNUBsvu86NG5Dr9QtTlMqdhUs/pgKPXg== 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=Z8SLv2IG; 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 7F11C606F35C for ; Fri, 13 Nov 2026 19:54:32 +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=Z8SLv2IG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EC881F000C4; Fri, 13 Nov 2026 19:54:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599672; bh=/G5+PMtTvr+Lji9tNex0mMGBnXcKq+n71breNybFLwI=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Z8SLv2IGmYK+uxrEcZ1z5VerYUGjZWI32XjyaYzM+sWtPuOuNnOl0BEqXqA6wvbbK puZJcxzws9JrmkOvq5VqOYbfBRoiV5RoKadUnXSyYH0Xh7aWvprQjl0zFU8nHEXvYV JfX/SpqmByscbLSJuMS5h9pG97DbQHOElPdYqrldqAkZzG1AmwPy8PbzA+qBSNwrIu mc7WB8NCtNjMaYYgUMlg73H9dVlY/LkQN1EGg1Xccwznvp9gtz/Eyyd6q0b8FviLit Cfh+CoBF+uWB43yc8vYQ8tSCmuXFPVUq5ahTGsQzEXeOdi1bWWe/a73zcRYz3eYIlv S3q8y0kwYdHAQ== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:46 +0100 Subject: [PATCH mptcp-net 08/34] mptcp: force the charge for the first skb of a subflow 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-8-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4156; i=matttbe@kernel.org; h=from:subject:message-id; bh=JV1b3vfWEhvSWda0MnQVjLNbR4EdsNIPeWXIobkd0Tw=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z13nOfPrc+/e78fz2pNZF5jxNH5Z/eTZpCcSgUx3p 7S2tc2a01HKwiDGxSArpsgi3RaZP/N5FW+Jl58FzBxWJpAhDFycAjARuZMMf0V3bF5zo2FdlX2x 3f446T9n407u388TLav1QcXlmL6urTLD/zJxJ1l1prk1SYcdT/Y/WPfp9JPiRIF7ywrdPkzIU1m 4lx0A X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason After a fallback to TCP, an MPTCP connection can stay stalled once TCP memory use is back below the hard limit of net.ipv4.tcp_mem, and above that limit send() on an idle MPTCP socket can leave its data unsent. A push moves data from the write queue of the MPTCP socket to a subflow, and charges the subflow twice: for a new skb in __mptcp_alloc_tx_skb() and for the payload in mptcp_sendmsg_frag(). On an idle socket, with nothing queued, TCP forces both charges past the limit, in tcp_stream_alloc_skb() and tcp_wmem_schedule(), since no ACK would ever restart such a socket. But a push forces neither, so above the hard limit both can be refused, and the push then moves no data. The earlier commit "mptcp: arm the rtx timer if a push leaves data behind" repeats such a push from the MPTCP retransmission (rtx) timer. But each attempt fails while memory use stays above the limit. After a fallback that timer is disabled, so the data stays unsent until another event, such as the next send(), repeats the push. The fix used here is to: - force the charge for the skb if the subflow has nothing queued - charge the payload with tcp_wmem_schedule() - send only the bytes that tcp_wmem_schedule() grants The first skb of an MPTCP-level reinjection is then forced too, as it is sent on a subflow with nothing queued. This is bounded the same way. This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch: a TCP memory shortage, for 30 seconds, during which each of ten idle MPTCP clients calls send() once. Without this patch, only 5 of them had their answer during the shortage, versus 8 with it: the 2 others are blocked in send() during the shortage, which is not fixed here. Some answers only came after the next send(), 300 seconds later, because of the issue fixed by the previous commit: IDLE label=3Dbehind-the-second-send t=3D338.9 conn=3D0 [...] answer_at=3D= 336.4 IDLE label=3Dbehind-the-second-send t=3D338.9 conn=3D1 [...] answer_at=3D= 4.2 Fixes: 724cfd2ee8aa ("mptcp: allocate TX skbs in msk context") Signed-off-by: Chris Mason [ Shorter comments. Commit message: the first skb of a reinjection is forced too + how the issue was found, and its symptoms. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index dc8cdda31a98..8d6ed293f6e5 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1387,13 +1387,17 @@ static struct sk_buff *__mptcp_alloc_tx_skb(struct = sock *sk, struct sock *ssk, g if (!skb) return NULL; =20 - if (likely(sk_wmem_schedule(ssk, skb->truesize))) { - tcp_skb_entail(ssk, skb); - return skb; + /* like TCP, force the charge if nothing is queued */ + if (tcp_rtx_and_write_queues_empty(ssk)) { + sk_forced_mem_schedule(ssk, skb->truesize); + } else if (unlikely(!sk_wmem_schedule(ssk, skb->truesize))) { + tcp_skb_tsorted_anchor_cleanup(skb); + kfree_skb(skb); + return NULL; } - tcp_skb_tsorted_anchor_cleanup(skb); - kfree_skb(skb); - return NULL; + + tcp_skb_entail(ssk, skb); + return skb; } =20 static struct sk_buff *mptcp_alloc_tx_skb(struct sock *sk, struct sock *ss= k, bool data_lock_held) @@ -1449,6 +1453,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct= sock *ssk, bool reuse_skb =3D true; struct sk_buff *skb; size_t copy; + int avail; int i; =20 pr_debug("msk=3D%p ssk=3D%p sending dfrag at seq=3D%llu len=3D%u already = sent=3D%u\n", @@ -1522,10 +1527,14 @@ static int mptcp_sendmsg_frag(struct sock *sk, stru= ct sock *ssk, } =20 copy =3D min_t(size_t, copy, info->limit - info->sent); - if (!sk_wmem_schedule(ssk, copy)) { + + /* like TCP, allow some progress up to tcp_wmem[0] */ + avail =3D tcp_wmem_schedule(ssk, copy); + if (avail <=3D 0) { tcp_remove_empty_skb(ssk); return -ENOMEM; } + copy =3D avail; =20 if (can_coalesce) { skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy); --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599673; b=IF7MiL/pcjtrVsU9BvM/jieRB3+ZQPC7zI8NNWJtEbcrkl9bL8Hr9KE8E3XDo174BiIF tf7JUC8rQFeh+iUojFugsuBwPVfkrCglVE4jwcWQglRNheil8PnJcV17tVwwQE3W+A08S j2QDCEAK/p8VKdjTE4/VnMLA1t9AvgJzLvwS3e+Emi8v9wLLUGxDKBDYGicUpSLWiG48y z2UXuqopZKqkjlkFikyO5PGVF02GtR1ev9opGCtu8RgcS6J64meN6Q/oFqRRM4t/VvwSa 9t0I1vTITNZj5b69b0NIhQaWIuqlysdKy1pseWIRaLWTEqd4Zpu0P5gdXKpWEQLbseg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599673; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=1xsih8J5PZwsEr5ofTOoK85D29iep0KBRC9JrtfExbg=; b=1VrsttJ2hv2KTSSgem3MJWQ9QzXNgL7TofAjl21sojscQp/PhiILqVHTViqsTzvAeqeG qj/2x6+/liUnAZkH5VoNda6TAq1lfWj34C8GJC//oUzRMIDoO9EznJuCgPrbOwiPSO9S2 VphirCU3OlLZJddkT8nHs3p2X4yE1L/WHbQvMc1vtV52Y1UGdLoQWOWovbcHfGrdx2bDA +IvWx9GtVk/BKcDcYUFLn01cLsuPUav0+vm9LqARoaGlJh9W0LI23+cbmTAQrA0ruWqZ3 ov/StxRMR20jkDrL7+Vda9D8tsdp1RHEUZ+fE0U8mqgyn22WvXuw6tdpLD1UkjNuiRw== 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="Tk1TjdE/"; 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 6D53C606A335 for ; Fri, 13 Nov 2026 19:54:33 +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=Tk1TjdE/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D2E81F000C5; Fri, 13 Nov 2026 19:54:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599673; bh=1xsih8J5PZwsEr5ofTOoK85D29iep0KBRC9JrtfExbg=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Tk1TjdE/tCXrZ84eT06y1Xwp/mrtbvopPS5e25MoguZfIlKxOa0l/hqREuJQ8a2Ed TXlfjxbCQPlMT0tYmHx5M6/ZxV7DS7jE82zhpGNPJr2k6LqbD8y6YknbQhVYJGRgS9 sd9haOzGxvQ8o3mSBCi6wpWgwUqKKs7vNPe6U3S9RN/nBGkUgmiXkPRYxcNZQMZ7kh YMuqmYpL04lY0qGVWwnUKgffRdBlUM5pvQiIxYRtnD+TRV62fkzZYuiF59ai0/VoBZ 9ov3n/vzJzJfSMLkORfSVPEnzl4AsdmMYCLCHp7yvguvs52WtZkTbKTxXrELBY4kT8 MSx2BKgckQezA== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:47 +0100 Subject: [PATCH mptcp-net 09/34] mptcp: leave an orphan's DATA_FIN to the worker 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-9-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3194; i=matttbe@kernel.org; h=from:subject:message-id; bh=JTWlyZr+lb1AF30QveWluMciOjPrBXiiZCI58AIGu24=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z934yi0rb7U+413P70kLubteGz66+tkk6cB+BZHSI /8WrNC36yhlYRDjYpAVU2SRbovMn/m8irfEy88CZg4rE8gQBi5OAZiIzg9Ghm83Luy53ydgdrhg 6421zxYs+aSuKqTKaH2N+cS3I1KnH81h+M3uqDvb/Urnn6LFHCf0fSdJKJz5riBr+bGDgbmqtXO 3KBMA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason Closed MPTCP sockets can leak until reboot, with the data in their receive queues, which can exhaust tcp_mem and stall other TCP connections. Once close() has returned, only mptcp_worker() destroys an orphaned msk, and only in the run that moves it to TCP_CLOSE: a later run returns at once, and mptcp_schedule_work() queues no work for an msk in that state. The receive path, in softirq, puts data on the backlog while the msk is owned, and release_sock() calls mptcp_release_cb(), which passes the backlog to __mptcp_move_skbs(). But __mptcp_move_skbs() calls mptcp_check_data_fin(), which can move the msk to TCP_CLOSE, and by then the lock owner, here the worker, no longer looks at the state: receive path, softirq mptcp_worker() =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D not in TCP_CLOSE: no destroy last data, with the DATA_FIN the msk is owned: backlog release_sock() mptcp_release_cb() __mptcp_move_skbs() mptcp_check_data_fin() TCP_CLOSE, never destroyed The fix used here is to queue the worker in __mptcp_move_skbs() if an orphaned msk has a DATA_FIN to handle, instead of calling mptcp_check_data_fin(). This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch: 200,000 connections in which the server accept()s and close()s, while the client reads the end of file, sends one byte, and closes. Without this patch, some MPTCP sockets of the server stayed in the CLOSE state for good, with their network namespace: =3D=3D=3D connections so far : MPTCP sockets of the server in the state C= LOSE: 200000:722, [...] RESULT [...] | left 300 s behind the end: slab_MPTCP=3D722 sockets_MPTCP= =3D722 [...] [...] | veth_end_left=3D1 slab_net_namespace_left=3D2 | [...] Fixes: bc68b0efa1bf ("mptcp: move the whole rx path under msk socket lock p= rotection") Signed-off-by: Chris Mason [ Shorter comment. Commit message: how the issue was found, and its symptoms. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 8d6ed293f6e5..16824bed85b4 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2363,9 +2363,15 @@ static bool __mptcp_move_skbs(struct sock *sk, struc= t list_head *skbs, u32 *delt } =20 __mptcp_ofo_queue(msk); - if (moved) - mptcp_check_data_fin((struct sock *)msk); - return moved; + if (!moved) + return false; + + /* Only the worker can close an orphan, as it must then destroy it */ + if (!sock_flag(sk, SOCK_DEAD)) + mptcp_check_data_fin(sk); + else if (mptcp_pending_data_fin(sk, NULL)) + mptcp_schedule_work(sk); + return true; } =20 static bool mptcp_can_spool_backlog(struct sock *sk, struct list_head *skb= s) --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599674; b=3eTl6nR9RcO8LTSP/P3TIGu4C8UQJJ9bWsAquoOSqC07p6eBjVE4QGCw+PpSZhnxo9do XsrCTml1NO6qz187iZ0bDvNR9uHv98++C7a/Slr28YxI22vlQZPQ+lFSzR8EmWboRlZXM KVpKAoZNcO6NkIxh2gruYfH6Dpt1dzlcI58K5qF9y585VBEJflZ/2mVSvIcMLOxFU2U9T TKR4e6kuKk1z71bqvA3Bc//y+dMZA50PvVqmUWYdS9bn+CCexFrUqU5Y524vt9Y3O9JQ/ HWny5A4KRDwcjDhXfYkj6GVG/dKDi+rfAu0HVw3nowgqgTbSoHbQF0b+sI1EAXwzAYw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599674; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=430RsdtDu/QEoIdJjfe0DmpeHGPaJFmwxePSN63kwmw=; b=JwXsmCcJzyPXLnywge55MuvWqlzwsXE2wr5ojhak572L2BzuVWoUENsY2+6BRNIxjt7y tWnVNcYxYq5CygFOjPhlmvWXAOc4EPFKXOVT4kwS6F+4a4vTQw7DwqYHyoS4t8rflQwwN tpgn81B1p9ug/axsecTcDIGicXLqrvzo4U0FfK0EuEve8wnV4T5U5bN1le4vC078XqNRP EADOXHrJPWCs4Wn8IQQFn7FzSuGsiYHOgKDeT6c/3fCHd6+jX2RO8ryIbfqODkG8w2CwU r8CDUHPjFGyOvDxWKaHcj3lgypvgCRiv32NNjkazgRm5zpmq1WDa5qsANPUNXe0WAmw== 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=OXs43PAn; 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 C2B4E606F373 for ; Fri, 13 Nov 2026 19:54:34 +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=OXs43PAn Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC2861F000C5; Fri, 13 Nov 2026 19:54:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599674; bh=430RsdtDu/QEoIdJjfe0DmpeHGPaJFmwxePSN63kwmw=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=OXs43PAnfHQhv2+BW2mPaOfjWtYhWV/n/+iT0K6bQ+BQof8GVyOVFrBMxTyIredJ9 1nY5uClHRCd/Eqqxg9KGZW3Jv1/eA6riH9O/VjEUNlqZMnQqUV/4k75Tpz47r13A7m uYqTYVOXAB3ALqihFlkSoGyeacImkmJaVd3+7tYm+48uxYD90H7MD5/KimVnTF8VUv ITXYyD6et+0EGGanH+H+iVZVp54eS5cPQK7OJhRgboxM3gm9SAnFPzXXZyBo+CWdDe h0GAPSGCWRnQ6HqdxYIdPPTw3lgF6a71l5JcoTnt0VLdP6eU1ZQr9lIPOKSJDXz4Si qNEEjykSAGPRQ== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:48 +0100 Subject: [PATCH mptcp-net 10/34] mptcp: don't leak an orphan when the PM closes its last subflow 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-10-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3150; i=matttbe@kernel.org; h=from:subject:message-id; bh=A1+RHb/uwhq+6tQZFUBnEU5KPZvenDGb9DWa57H0lDM=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z92IEw/oYFu5xPyJQfCcVhvjC7dsubZmPtc+MylY5 t3popgzHaUsDGJcDLJiiizSbZH5M59X8ZZ4+VnAzGFlAhnCwMUpABO51Mzwv26qeUHqIRe/YrXC s0WhPvuDC1Y3bHJnqq+IqyrsuDP/LcP/sBrNh5tu+p86eGjN4gQFT40JB2yz5VbsVX1+yOxxr6U fLwA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 Once close() has returned, an orphaned MPTCP socket is only destroyed by mptcp_worker(), in the run that sees it in TCP_CLOSE: later on, the worker returns at once for an msk in this state, and mptcp_schedule_work() no longer queues it. __mptcp_close_ssk() moves an orphan to TCP_CLOSE when, after the closure of a subflow, only the initial one remains, and it is closed. This function is not only called by the worker: path manager commands also close subflows of any msk of the netns, orphans included, under the msk lock: e.g. 'ip mptcp endpoint delete' or 'flush' with the in-kernel PM, or MPTCP_PM_CMD_SUBFLOW_DESTROY with the userspace one. In this case, nothing destroys the orphan: it stays in TCP_CLOSE until the reboot, with its token, its initial subflow, and its reference to the netns, which is then never freed. This can happen when the initial subflow has been reset or has timed out, and the connection is closed -- the orphan then waits for the end of the DATA_FIN exchange, up to TCP_TIMEWAIT_LEN -- before the endpoint used by another subflow is removed, e.g. when an interface goes down. Only the worker can close an orphan, as it must then destroy it. So here, mark its close timeout as expired, and queue the worker, like it is done for an msk in the accept queue. The worker then closes the orphan with mptcp_do_fastclose() -- nothing is sent: the only subflow left is closed -- and destroys it. If __mptcp_close_ssk() was called by the worker, this happens later in the same run. This issue has been found by an AI code review agent, while reviewing the code of the commit "mptcp: leave an orphan's DATA_FIN to the worker", and confirmed with a new Packetdrill test: the initial subflow of an orphan waiting for the end of the DATA_FIN exchange is reset, then the endpoint of the other subflow is removed. Without this patch, the orphan stayed: UNCONN 0 0 192.168.0.1:8080 192.0.2.1:39933 kernel_orphan_last_subflow.pkt:39: error executing `! ss -HMan | grep -v = LISTEN` command: non-zero status 1 Fixes: 27e5ccc2d5a5 ("mptcp: fix dangling connection hang-up") Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 16824bed85b4..6dc55a3f027b 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2794,8 +2794,13 @@ static void __mptcp_close_ssk(struct sock *sk, struc= t sock *ssk, */ if (list_is_singular(&msk->conn_list) && msk->first && inet_sk_state_load(msk->first) =3D=3D TCP_CLOSE) { - if (sk->sk_state !=3D TCP_ESTABLISHED || - msk->in_accept_queue || sock_flag(sk, SOCK_DEAD)) { + if (sock_flag(sk, SOCK_DEAD)) { + /* let the worker close and destroy the orphan */ + mptcp_set_close_tout(sk, tcp_jiffies32 - + (mptcp_close_timeout(sk) + 1)); + mptcp_schedule_work(sk); + } else if (sk->sk_state !=3D TCP_ESTABLISHED || + msk->in_accept_queue) { mptcp_set_state(sk, TCP_CLOSE); mptcp_close_wake_up(sk); } else { --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599675; b=v4E2vxuHP6txmxcqcmMw6qPaEwG5XLbq/Zl5RoLVPph5vEoPcXg0csE9yBKCqwal3SQ5 yJUK7/GsiooY44RXDYCMARMVMOGob1S5/I+3sTW7mU8S0G/U4VWqjSXbZ+qj/DJ2u1XOs k6EHlupb/IWC13qvR/qQnsu9tsdDcOm8kZTy4kb1HuJ6QdS6aD5SKK2tQUZW2ubIC9MIh 9HbX7DZ9r1l6pJ7pFuz4hZrOcMllg/Tf0/dUvRUD3J14dhIQp7k1K+yJUdaC51b08E67f cOi0bZUJCElUOO+JdDRcJ0FtO6vgTgogcUOrlzE5mhzMkIhx1o6+JnoyJutc/isg/JA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599675; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=8Lxk2leFGI5ZQWF4W1kNNO2MPur9K1wnOp9pbPXwSHs=; b=Q2ITb63K9Mnxcb259IzL5TAicPXe5icn9brftkHPC0rc+Hb+5D+k/8IHfacKMGvDdYdp C2UTs6zB5THaQcNoxAoqAqniD2WkwXBIBfMKUoFYs9Bq0Cm41YxLcWGK5jukrfUdWMxtj ILtMjPZgZDbXJodFOeSA6TB8q27T2G2qUqK6SVdswWC/NRcPCyzhMiZEbf5h2CA80jLpd tfWYNJpD3uDc+O9opq+tcb7mGOdFrIak+DntTlxWreQnWYoB9P0sjYHkmKAZhvFZSR+ik w3L1BJhn9bdLHjLqP3fWKrBwk2JzPdluGLeJF2BCXTfvbQ4G8U7xDmlC3W86I2h2PhQ== 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=mzB86FiN; 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 AAE16606F37A for ; Fri, 13 Nov 2026 19:54:35 +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=mzB86FiN Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA9CD1F000C4; Fri, 13 Nov 2026 19:54:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599675; bh=8Lxk2leFGI5ZQWF4W1kNNO2MPur9K1wnOp9pbPXwSHs=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=mzB86FiN38pRZj+Ke1IuOkmB2wwd+Id1aADCkSeQ+Uk8OWj5G1j/FDT9J3tXsCI/y Rpi5GLV1ysEi9E1x+iCxYKa2PozGAFHmNRP+qRzzJsA+OuxbEyGcZCp9r31LP/jVtV ZcawDzv7oI+8ZHdeTkGeiK3T+j7S2fxA5T6nk6i/SU7cqadddfS9oisyMd3mmAZGQ3 m93Ug2ZYRa/un/DILeKpzNzKpO7h/pOj6Yv+v5gRHHzKYp/gBEel+OguB6u6uLw+Ld GHb5WI4dgY7YTt+rFp2O5hx/fZYBCFk1r4pIZNESO6hHUGTwURzxYcPGWieDWr3k/m SDPvon84bsrFw== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:49 +0100 Subject: [PATCH mptcp-net 11/34] mptcp: do not use a raised snd_wnd for the send window 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-11-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3683; i=matttbe@kernel.org; h=from:subject:message-id; bh=y4cht3Zrr/MZq0iXxTj59uQzUB0cKXZS8Asa5QTlug4=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z9387SSVKtBX4v7O2c1nbr78nlKFd/ztvbuW/bE46 3jo9kfHjlIWBjEuBlkxRRbptsj8mc+reEu8/Cxg5rAygQxh4OIUgIlE/mFkeKKfMaGu7nncwyUc v5pdmbqt/gWrPFmpOqE6Mdk+SnDud4b/GffV30pN9FjHFc1XULSy5GlWlKX5gtCXj9VKLQL2Ot5 nBQA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 ack_update_msk() sets the right edge of the MPTCP send window from the DATA_ACK and tcp_sk(ssk)->snd_wnd, but this is not always what the peer announced: mptcp_check_allowed_size() raises it to window_end - data_seq, so that TCP lets through what the MPTCP-level window allows. That is fine for new data. For data sent again, data_seq can be below snd_una, and snd_wnd ends up too large by the difference. TCP only overwrites it when an ACK moves things forward on this subflow, see tcp_may_update_window(). If a DATA_ACK moved by another subflow comes in on this subflow before that, wnd_end goes past what the peer offered. It only moves forward, so it stays there. The sender then transmits data beyond the peer's window: the peer drops it (MPTCP_MIB_NODSSWINDOW) after TCP acked it, and only an MPTCP-level retransmission can recover it, which raises snd_wnd again. The connection can then stay stuck at a low rate for several seconds, with nothing in flight on any subflow. This raise has been added by commit b713d0067574 ("mptcp: really share subflow snd_wnd"), but snd_wnd could already be too large before: when nothing moves at the TCP level, tcp_may_update_window() ignores a lower non-zero window, while the peer can announce one with a DATA_ACK that moved, keeping the same right edge. Use the window announced in the packet carrying the DATA_ACK instead. In my case with BBR, a small TCP rmem, and a second path with a much higher latency, a lower throughput and some losses, this small change can double the throughput in the worst cases. The issue has been reproduced with a new Packetdrill test, on a single subflow: the data is acked by TCP, then by MPTCP with a lower window, keeping the same right edge. Without this patch, the 2000 bytes written next were sent, instead of the 1280 bytes up to this right edge: dss_dack_window_server.pkt:23: error handling packet: live packet payload= : expected 1280 bytes vs actual 2000 bytes Fixes: 6f8a612a33e4 ("mptcp: keep track of advertised windows right edge") Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/options.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index 71579238a951..b4b3292fb4dc 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -1121,9 +1121,11 @@ static void rwin_update(struct mptcp_sock *msk, stru= ct sock *ssk, =20 static void ack_update_msk(struct mptcp_sock *msk, struct sock *ssk, + const struct sk_buff *skb, struct mptcp_options_received *mp_opt) { u64 new_wnd_end, new_snd_una, old_snd_una; + u32 win =3D ntohs(tcp_hdr(skb)->window); struct sock *sk =3D (struct sock *)msk; u64 snd_nxt; =20 @@ -1144,7 +1146,12 @@ static void ack_update_msk(struct mptcp_sock *msk, after64(new_snd_una, snd_nxt))) new_snd_una =3D old_snd_una; =20 - new_wnd_end =3D new_snd_una + tcp_sk(ssk)->snd_wnd; + /* What the peer announced: tcp_sk(ssk)->snd_wnd can be larger, see + * mptcp_check_allowed_size(), and is not always updated. + */ + if (likely(!tcp_hdr(skb)->syn)) + win <<=3D tcp_sk(ssk)->rx_opt.snd_wscale; + new_wnd_end =3D new_snd_una + win; =20 if (after64(new_wnd_end, msk->wnd_end)) WRITE_ONCE(msk->wnd_end, new_wnd_end); @@ -1314,7 +1321,7 @@ bool mptcp_incoming_options(struct sock *sk, struct s= k_buff *skb) * monodirectional flows will stuck */ if (mp_opt.use_ack) - ack_update_msk(msk, sk, &mp_opt); + ack_update_msk(msk, sk, skb, &mp_opt); rwin_update(msk, sk, skb); =20 /* Zero-data-length packets are dropped by the caller and not --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599677; b=vLddle2FgAClV/dS2zFg99pKQ2+8WBmvELAJd7iRa8RTMlg5gD2iCgZva643xUQVA2Ep JC5V7ylXMf5yfsgwlP07e75Rs+KVqeD2/qDT9wuxx/zgGai0G0rjrwdBZEFZl70FZ+Vfc IQyTE/N1jU1OuBq9ya0YfxmOYLHCRSyJVQYqo40B7KjsWFilttu5e3hkRXmd/8GJM73Jp ujHvJxrF8ixZ4IR0I+qVjWSKAxvrQYzP05h4EUAIYL2bfbNwTKXsaPEWkIH3gJ8l4amsz sxxV4nL2Ufy1Goj1VeK6q4bhgEVNe7NFBbCdZlMg+pRKA9lX8Q+OuLKEvuj3x2qGUMA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599677; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=9z0phqwA/x/mKMnhrgbdQ+q0K6pjFpQy6EtNNaJiYlg=; b=u2qAvgPi8BZMenjFXFODCbIKNVzCpmLlYQXBzKtDB2FdClKd8Cx6zwKVxTv9m2Tk059H acjCstQhh9P5ghmRQbD/QHbUaROPxW6LuWMeYnJWjK3uQgFxMmvWQTJLFk4yw8NvwIQ6N 4bmyGgrTMW/mmXMtojy0soiWt8R+BaYvnJFshCv9l2QiJ/YbCwDBxv/OWprJb1iNbZgG/ 8vdr3pYz8dTq2Cvb3EDlicMr5Ul9hfxDxOhrWWgkOG8ao74kOELX1Z/zZSYuHOCvX2dXh yJoaSzSQFNQFRfjScJzTCq6utXUI+3oGzQpVOdrHd06UzmQRVAwL4PT1q1LwuJZeEmA== 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=lU7Iwgg3; 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 147CF60A2616 for ; Fri, 13 Nov 2026 19:54:36 +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=lU7Iwgg3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E90081F000C4; Fri, 13 Nov 2026 19:54:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599676; bh=9z0phqwA/x/mKMnhrgbdQ+q0K6pjFpQy6EtNNaJiYlg=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=lU7Iwgg3l2zbdBX0jp1zTMnp/0fKNs1jkABcEvgLs6SJZOoOWKW6krXrn7HnlzYFE LY/hsHKkaOOCYW0Pz6lEIuF7ySPZIQ5+1u0gucNQwk6Ry7I24DkyzgNrvsu+W2/mSo NPvFVn1qodjp424k0pvXwwFvz6VbsSnEuYYQBE2etp3y/TQV+mI0/Knja0k/GcGuvf 495JV7NwFAMNCM1z/Z8T2FNU/BCgdg+kq3tuT3NUnwpf7Xuc9rReySztrcLwc+UQql jZTl8h3A56zwGgCKRuOfXzzGX4nHJd6yRrOAchCVu5nAUeYV2TR4VGy1IhZyeWnAUU anF9oqwrqC+VA== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:50 +0100 Subject: [PATCH mptcp-net 12/34] mptcp: drop non-MP_JOIN cookie ACKs on PM listeners 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-12-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2846; i=matttbe@kernel.org; h=from:subject:message-id; bh=nAccD7htPNqufXaAEbi057sDDtIAX41OxigkYKSnCgg=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z90q7jmkv2yyrtZ/+cXcYYUmD2NS706aFMTvkRz8S F/58gTLjlIWBjEuBlkxRRbptsj8mc+reEu8/Cxg5rAygQxh4OIUgIlImTEyTM2SX3JDv37JgR0V ufzZVa4PNjSU5RY/+PGV5UbplopX3xgZWj0l3h58arNeg0eg0q1cUkQjunR1aNiPaSJTlgvz7ez kAgA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason With SYN cookies enabled, a port-based MPTCP signal endpoint can stop accepting new subflows until it is deleted. Nobody calls accept() on the listener that the in-kernel path manager opens for such an endpoint, so it must create only MP_JOIN subflows, which never enter the accept queue. The listener is marked pm_listener, and since commit 3d041393ea8c ("mptcp: prevent MPC handshake on port-based signal endpoints") subflow_check_req() refuses a SYN with no MP_JOIN option on it. But a SYN cookie does not record the MPTCP option of the SYN, so mptcp_subflow_init_cookie_req() picks the kind of child from the options of the ACK, without looking at pm_listener: ACK with a valid cookie and no MP_JOIN option creates a plain TCP child, or an MPTCP one if it has MP_CAPABLE which stays on the accept queue until the endpoint is deleted once the queue is full, the listener drops MP_JOIN SYNs too The fix used here is to refuse an ACK with no MP_JOIN option on such a listener in mptcp_subflow_init_cookie_req(), so that the request sock is freed and the ACK is dropped. This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch: a client sent 1025 ACKs with valid SYN cookies and no MP_JOIN to the listener of such an endpoint. Without this patch, its accept queue stayed full, and another client could not create its additional subflow, even 130 seconds later: TCP: request_sock_subflow_v4: Possible SYN flooding on port 10.9.0.2:6666= . Sending cookies. [...] C2 4.007 [130 s after C1 has gone] RESULT: subflows established = 1, in SYN_SENT 1, the service works --- V, after that try of C2 listener 10.9.0.2:6666 Recv-Q 1025 Send-Q 1024 Fixes: 1729cf186d8a ("mptcp: create the listening socket for new port") Signed-off-by: Chris Mason [ Shorter comment, the details are in the commit message. Commit message: how the issue was found, and its symptoms. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/subflow.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 00677fb3efcd..14e4557c3a9c 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -312,6 +312,11 @@ int mptcp_subflow_init_cookie_req(struct request_sock = *req, =20 opt_mp_capable =3D !!(mp_opt.suboptions & OPTION_MPTCP_MPC_ACK); opt_mp_join =3D !!(mp_opt.suboptions & OPTION_MPTCP_MPJ_ACK); + + /* PM listeners only take MP_JOIN, like in subflow_check_req() */ + if (unlikely(listener->pm_listener) && !opt_mp_join) + return subflow_reset_req_endp(req, skb); + if (opt_mp_capable && listener->request_mptcp) { if (mp_opt.sndr_key =3D=3D 0) return -EINVAL; --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599678; b=JTlsGhoiTvjUS16019KFXppqMR7KYESKjTnKx7+Zffanp0K6b/BnIY+PmQZjadjgFhuf 1XpUmpKYaXmSmuRy64++AkXvIbvBbg/Zsf2Hgr8Dk1yuuzWSMIkF8Kd/oPiUgIBmzbteU KNql91i2j0t/IgEJG57lm//XyFxo6wgcT244sNIPJWLQHDQTIpHbXDjKjwNVeMvMuVZWM DUO8M0199aTOnUV2qK33cZBz84pwR65LD0OUIccXbTWAmYFzqjVnaQs4fVMKlUbIwbv1N zVt0SLvdlA/pxyRcbPxO6s96+UGCtZh3hwq3333zqh88OQKhQcsMuB5VmWdp3Y6mpzA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599678; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=466qZiFYSvQUeue/MADYPAUqndRBnnYaTEKY7WOpLeo=; b=mfTft6kKxXILvKX2Dulh4YLvAJakHtol28jF3QMZOQiO8UdSyC2Rp/cbyrnB4sR/8mTy hypw7a5bHqCrBUO7pLz8GWaxo7By+xgR4X+WcDPMx43oaxQbPAvBEPbiYFb44ByXVQr+V hds/LE0vSukdejEAK+U5haLGDiv3ncg7L5v6kUCl5y3PBfH8/oRgg+7U6VQswohk1W5PN 0tNCJH7mczp9tXZa4IfS7/ZlIQjKqa9RKr6acCKcFvO/88OTvYMb3dT4DryilC4Yi1RCz +6BSMLvLPUMdflCcMpE8cVJy0/VA6x35VTiRmWPEAa800ZDneGte8fWEbRvM57H6yxA== 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=Ary2ElRn; 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 EAA5E60A261A for ; Fri, 13 Nov 2026 19:54:37 +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=Ary2ElRn Received: by smtp.kernel.org (Postfix) with ESMTPSA id 145211F000C5; Fri, 13 Nov 2026 19:54:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599677; bh=466qZiFYSvQUeue/MADYPAUqndRBnnYaTEKY7WOpLeo=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Ary2ElRn+/VyurMule72L+LVkd9chP4t39c+UB8DeZOcnElkdk4ov0Z0viYRQefm5 zMf1/WnXcJwWkdDCObyRYgJ3GvSxNoMqmXcjhCTUhrGsD0Th6ZDmn59kAT0jHc/NY/ oXGtpu0Qxx8C1MbuJeItpq58DUDSkSHUdEtqYRJd0veB0tNcTg3dKPBrq8Y70oSJNL YmyQlegf7z+C3OoBESprG53CyikNOCdCzzg6xhEIaWlv6OIQPGS5WVCLzpN3/2ITaW basAF+UYfFeBu9+91S5GKFLaXCqrj6SxwIztW9Has9MiIRvzaty3ulB7T3UcDGXI82 /Sn1S/JFlL5ew== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:51 +0100 Subject: [PATCH mptcp-net 13/34] net: add __sk_net_refcnt_upgrade() with a GFP mask 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-13-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2373; i=matttbe@kernel.org; h=from:subject:message-id; bh=VMuDMJ+QYpChqPbElRGFQ6C9jKJt7DZnMFWfmai9U/A=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z92uNd43L9mz3sOoaGfakfezJr446ZuvzyX58NBOH yv9zqTejlIWBjEuBlkxRRbptsj8mc+reEu8/Cxg5rAygQxh4OIUgIkE6jEynPnBoyB8VyqYbcVJ zQ8Xduif0Lddfyto1c/df43LNmlkzGJkmPzqi9qH9WvkXdU3X69ombe5IrKkcqcyg5LfhD17ZSy m8gMA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 sk_net_refcnt_upgrade() gives a kernel socket a reference on its network namespace, with a netns tracker allocated with GFP_KERNEL. The next commit needs to do that for a socket created in atomic context: the child of a kernel MPTCP listener, created when an MP_JOIN request is accepted. Add __sk_net_refcnt_upgrade(), taking the GFP mask to use, and make sk_net_refcnt_upgrade() call it with GFP_KERNEL: no functional change for the existing callers. The 'Fixes' tag here below is the same as the one from the next commit: this patch is needed to fix the issue introduced by this commit ID. Fixes: 1729cf186d8a ("mptcp: create the listening socket for new port") Signed-off-by: Matthieu Baerts (NGI0) --- include/net/sock.h | 1 + net/core/sock.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index d58d38db732d..1f64f08a8131 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1847,6 +1847,7 @@ static inline bool sock_allow_reclassification(const = struct sock *csk) struct sock *sk_alloc(struct net *net, int family, gfp_t priority, struct proto *prot, int kern); void sk_free(struct sock *sk); +void __sk_net_refcnt_upgrade(struct sock *sk, gfp_t gfp); void sk_net_refcnt_upgrade(struct sock *sk); void sk_destruct(struct sock *sk); struct sock *sk_clone(const struct sock *sk, const gfp_t priority, bool lo= ck); diff --git a/net/core/sock.c b/net/core/sock.c index e529ffeaedb9..c9fa717d953e 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2434,7 +2434,7 @@ static void __sk_destruct(struct rcu_head *head) sk_prot_free(sk->sk_prot_creator, sk); } =20 -void sk_net_refcnt_upgrade(struct sock *sk) +void __sk_net_refcnt_upgrade(struct sock *sk, gfp_t gfp) { struct net *net =3D sock_net(sk); =20 @@ -2442,9 +2442,14 @@ void sk_net_refcnt_upgrade(struct sock *sk) __netns_tracker_free(net, &sk->ns_tracker, false); net_passive_dec(net); sk->sk_net_refcnt =3D 1; - get_net_track(net, &sk->ns_tracker, GFP_KERNEL); + get_net_track(net, &sk->ns_tracker, gfp); sock_inuse_add(net, 1); } + +void sk_net_refcnt_upgrade(struct sock *sk) +{ + __sk_net_refcnt_upgrade(sk, GFP_KERNEL); +} EXPORT_SYMBOL_GPL(sk_net_refcnt_upgrade); =20 void sk_destruct(struct sock *sk) --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599679; b=s8i3c3tnHq9K5PZNBBuQpuBB6l3KHVYzpGbxSlRI27lTJyvqSYTdcEhvUmHb24F6qdtj CPIwDwMfM5aiQ3VFZhFBm9vGGECY4Pk8v4Hp0vHZdzHuQd4ZAAo0kkEJ9m1zrfvstNwg7 YMa0Trf/BPdDCe2MLyh4SzgcYXfE6KRUuuIrdg//85QrckuUGNxtqIEzP6Voi0uc2SfUu VlKhpjhuVGHi2F89RsXuJEh5M2dnYJuiyAhgWu+JmNmEK5X9UA42G6oslqfuF43i8D76H wjpvxw7kgXFcwsSlMRHrH6BYm90MXl5I2M0YId9LRyikDpSreGJwS1XJXqoc3L+TG4w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599679; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=nFe1PGT6ukee0cBJfsvGhcbVJsJj6oLkbRhi/oNKO4s=; b=XJoJKEwqiuSrqO2c7HnaAmwUTHL8mrUYWg4sAa0HyBE5xyaN2H6HwAl5BYI0zCzni+bs thj/EIvRJ3m0znPlmW9yGuXsNKmWrPvFaAymyfpX01eE4gh5COx4V8ZtOMXBnn/+K+MEP ayS78By5jDf9d/wX3H2EHY1H8OitRXXcLTyWZ9+M1Hqn82MZJ1IkR4Di5gffaDabk/bwN VWkmUmwHfR4bikvkHMQ/RYpjPlzP2g8dTYSpDcXOSlJZvSGJFkL9QVbdB87WxvJDmR+bG xL1rKWz9UOi+2oYMUVXa711qx/hws/4B00mSgHEQZCZxPDdViQNAuq0z8XttcUNhavA== 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=VdmiajsA; 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 4A59360A2637 for ; Fri, 13 Nov 2026 19:54:39 +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=VdmiajsA Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33F7D1F000C5; Fri, 13 Nov 2026 19:54:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599679; bh=nFe1PGT6ukee0cBJfsvGhcbVJsJj6oLkbRhi/oNKO4s=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=VdmiajsAnL4jegSePo6folfVlmJuhgVQ9CVER+cirNvo9wfrkarJyTgbOAwJmHSfE w6gvg9kNa1Uyv/cU0wAN2cIcjvOn3r2XXp91gAGAJ35m9Lmt/6/kj++KXBT8xaMD9A 5MHQk4SKZCCelTyzJgWF4w9gtXnr/Foa26GXu3T6bKPK83kDJnvNLJWm+jghyF2EJa Kd/mh6jQQwQDtR+urB7ZzRAC5Gs38qIUrOOQOhqkjVfOENCSXaoy0W+LHS0WNJmHLA 1JsYZp+nuyMVFuDLlbSbrh1J1gv/LMrtLQ46LCK9/1Tzv1QdTapAzR16WxXJiGaD46 /0Y9tbLS02q5A== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:52 +0100 Subject: [PATCH mptcp-net 14/34] mptcp: pm: don't let listeners pin their netns 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-14-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" , Josef Bacik X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4426; i=matttbe@kernel.org; h=from:subject:message-id; bh=oyysGJijFxAIXfPqLYBBeCBP27Lj2NpPOu7LdS8gkk0=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z91eec/rTJeq7MmPS53nSvI0Frlt0A14PPWf8+Ioy yu3wmwed5SyMIhxMciKKbJIt0Xmz3xexVvi5WcBM4eVCWQIAxenAEykKJ/hf6SV+8arnOUHbe88 ZZFbc3KWZZfl2YoZd6Ntnwp7TO+c/Y2R4a78g8OzYi1eK5xK4Zr0+JeAfKZR5IMgbrNTidMc3ov 68gIA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Josef Bacik For a "signal" endpoint with a port, the in-kernel path manager creates a listening MPTCP socket with sock_create_kern(). This socket is released when the endpoint is deleted or, failing that, by pm_nl_exit_net() when the network namespace is dismantled. The MPTCP socket itself holds no reference on the namespace. But its first subflow is created by mptcp_subflow_create_socket(), which always calls sk_net_refcnt_upgrade(). So the namespace cannot be dismantled before the listener is released, and the listener is not released before the namespace is dismantled: unless somebody deletes the endpoint, both stay around for ever once the last process of the namespace is gone. unshare -Urn sh -c 'ip link set lo up; ip mptcp endpoint add 127.0.0.1 port 4321 signal' leaks a namespace, with everything it contains, each time it is run. It remains charged to the user's max_net_namespaces limit. Only take the reference if the MPTCP socket has one. A listening TCP socket has no timer of its own, and request sockets of a dead namespace are taken care of by inet_twsk_purge(). The sockets cloned from that listener for incoming MP_JOIN requests do need the reference, for their timers, but inherit sk_net_refcnt =3D=3D 0. T= ake it when they are created, with __sk_net_refcnt_upgrade(), from the previous commit, as this is done in atomic context, and drop the connection request if the namespace is already going away. The TCP listener of such an endpoint is now a plain kernel socket, like the MPTCP socket it belongs to: it is not counted in "sockets: used" in /proc/net/sockstat any more, and its destruction is not broadcast to the listeners of the SKNLGRP_INET*_TCP_DESTROY sock_diag groups. This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch: the command above, run 1000 times by an unprivileged user. Without this patch, all the network namespaces were leaked: result: 1000 network namespaces made, 0 taken down, 1000 are left Fixes: 1729cf186d8a ("mptcp: create the listening socket for new port") Signed-off-by: Josef Bacik [ Use __sk_net_refcnt_upgrade(), from the previous commit, instead of an open-coded copy of sk_net_refcnt_upgrade(), with maybe_get_net() like rds_tcp_tune(). Shorter comments, and describe the condition: any kernel msk. Commit message: how the issue was found, and its symptoms. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/subflow.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 14e4557c3a9c..d23da4ac1968 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -849,6 +849,22 @@ void __mptcp_subflow_fully_established(struct mptcp_so= ck *msk, WRITE_ONCE(msk->fully_established, true); } =20 +/* Children of a kernel listener need a netns ref for their timers */ +static bool subflow_child_get_net(struct sock *child) +{ + struct net *net =3D sock_net(child); + + if (likely(child->sk_net_refcnt)) + return true; + + if (!maybe_get_net(net)) + return false; + + __sk_net_refcnt_upgrade(child, GFP_ATOMIC); + put_net(net); + return true; +} + static struct sock *subflow_syn_recv_sock(const struct sock *sk, struct sk_buff *skb, struct request_sock *req, @@ -917,6 +933,11 @@ static struct sock *subflow_syn_recv_sock(const struct= sock *sk, =20 tcp_rsk(req)->drop_req =3D false; =20 + if (!subflow_child_get_net(child)) { + subflow_add_reset_reason(skb, MPTCP_RST_EUNSPEC); + goto dispose_child; + } + /* we need to fallback on ctx allocation failure and on pre-reqs * checking above. In the latter scenario we additionally need * to reset the context to non MPTCP status. @@ -1865,8 +1886,10 @@ int mptcp_subflow_create_socket(struct sock *sk, uns= igned short family, /* kernel sockets do not by default acquire net ref, but TCP timer * needs it. * Update ns_tracker to current stack trace and refcounted tracker. + * Not for a kernel msk, e.g. a PM listener: it would pin the netns. */ - sk_net_refcnt_upgrade(sf->sk); + if (sk->sk_net_refcnt) + sk_net_refcnt_upgrade(sf->sk); err =3D tcp_set_ulp(sf->sk, "mptcp"); if (err) goto err_free; --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599680; b=d+juJpo3Dx5siizQ+Q0IXwKqu9HiZSfjuvygwmvu0cnKjKV8OZnn8gW70Ute0XcBCoER kakCgiWjG1y+R0YVoT2sDxsR7agCLOb8CgA2XTfq0Zs/TLnBNJx33g03b9Gc/W+Pbhs2Z Od3W8So7EksziMzLbUSG9GZ2VhJxdxAADgACmmT3UpFTixWKQ2vcEZSAhCRfCAiZRZ0oY wyQbMMhT0ywJ9t9Errtw2jEelkdcafKG8D7Km8VENjtyIChrHT5zSUblNLBXJI6dgeYxC T4vIipuvM+pfa6k376oSzS7/Qy5cNHf+qYhG1HyFPaIlP27N16YTSe+TeCXsLr7T0bA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599680; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=BELkbp4ExWP6/lcL/Ev8fJQI696janFQwLCyGJlE480=; b=K+dL/3Yl+ljNeTVhWtBJOuFVl/78huowi8hp3jaa1LyU/l2L3sRFDeKIOhVTamygkID1 cBCPmZNN08M9rKYcF7DWZ34wwnsCNYgA2TO1Ite6UJO/aIRx0s5c+Hzr8bQDyvjBymW++ ZHuzeH+6aE0U+GRXqq6kibnjJXE0mGeIx/6O0gtvGKiAtGR3TvCzmrySdMz8NChN/DTVb z7yxtkjwd0Vo+AtFNawTt8wYzUck/oMve+8YMOoKTtZW34X3ssa1gc9eE0wXDO9RY8N/i Ff60MoGWKlzlOrZDiKiQ9BqZVtzVbxsFjg4pzgF58lyKrDh6YMaHqsPKWMqPXFfcLgw== 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=blL4BwCE; 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 82192606AE8F for ; Fri, 13 Nov 2026 19:54:40 +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=blL4BwCE Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7819F1F000C5; Fri, 13 Nov 2026 19:54:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599680; bh=BELkbp4ExWP6/lcL/Ev8fJQI696janFQwLCyGJlE480=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=blL4BwCEyTiP5iw5GnfbHnZTX//gdSaxKrkACMgeHTdU/7W/yIi4rSP9DfN4MSP9s TDrGpoNe2/rBKpR5LW89VsxKEuhK60TQqwtXdhQTgSAcx85aIDp2i1OPOivUyv/rGp 2n/gd9KKUe94ARJtS6p7gOjhi8p00wdiS+o8xJ2oFdJODEH/wOOXZSUfpXq4qOpvAI yC3zZV1i7knUJp6FTl4fSxiosrBAMaT5VNrwTL1fVR+OMcycsyX0bZGmquLjCuKPwD KxIei8+thHPn6f7OkW9DD09B1Gz5I+J741aPQGwiq8HrhIfdjk7jWxspPgU2WMlfH0 gf0op102qYsjw== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:53 +0100 Subject: [PATCH mptcp-net 15/34] mptcp: close a subflow reset for a bad mapping 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-15-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2798; i=matttbe@kernel.org; h=from:subject:message-id; bh=X7DMfxvUXFr2YBk4zqnV1sIrcYWLMnTUGu/oUF1i1RI=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z91hYbN74XxN+vxU3pufLSa8DE7KCjNWOiaSJfkjR bPzYx13RykLgxgXg6yYIot0W2T+zOdVvCVefhYwc1iZQIYwcHEKwERSBBn+Wepb5dod35dw4vP/ 4xanBfk8Piw8mnEnaYZDnIFB82TdpYwMkxacalyjaqU1+bbGtqUiR8JmBb/J8b/2S/Xnytaf/1W ucQAA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason An MPTCP socket can stay in the ESTABLISHED state after MPTCP has reset its only subflow because of data with no valid mapping, and recv() and send() then block with no error. If data arrives with no valid mapping and a fallback to TCP is not possible, subflow_check_data_avail() resets the subflow: it moves the TCP socket to TCP_CLOSE with tcp_set_state() and sends a RST. The MPTCP worker then has to close the subflow in __mptcp_close_subflow(), and closing the last subflow starts a timer that moves the MPTCP socket to TCP_CLOSE. But the worker only calls that function if the bit MPTCP_WORK_CLOSE_SUBFLOW is set, and this reset neither sets the bit nor schedules the worker. The fix used here is to call subflow_sched_work_if_closed() after the reset, which sets the bit and schedules the worker. This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch, and with a new Packetdrill test: data without DSS while the fallback is not possible, here because of out-of-order data at the MPTCP level. Without this patch, the subflow was reset, but the MPTCP socket stayed established, with no subflow: read() returned EAGAIN and send() timed out, for good: dss_drop_ooo_reset_server.pkt:30: runtime error in read call: Expected er= rno 107 (Transport endpoint is not connected) but got 11 (Resource temporar= ily unavailable) Fixes: 40947e13997a ("mptcp: schedule worker when subflow is closed") Signed-off-by: Chris Mason [ Add a Fixes tag. Moved before "mptcp: continue the last mapping after a fallback", which makes this reset path reachable in more cases. Commit message: how the issue was found, and its symptoms. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/subflow.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index d23da4ac1968..7b8183b6a13e 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -1499,8 +1499,8 @@ static bool subflow_check_data_avail(struct sock *ssk) } =20 if (!mptcp_try_fallback(ssk, MPTCP_MIB_DSSFALLBACK)) { - /* fatal protocol error, close the socket. - * subflow_error_report() will introduce the appropriate barriers + /* fatal protocol error, reset the subflow and let the + * worker close it */ subflow->reset_transient =3D 0; MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_DSSRESET); @@ -1515,6 +1515,7 @@ static bool subflow_check_data_avail(struct sock *ssk) sk_eat_skb(ssk, skb); mptcp_send_active_reset_reason(ssk); WRITE_ONCE(subflow->data_avail, false); + subflow_sched_work_if_closed(msk, ssk); return false; } } --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599681; b=E6GT/CsuZc6SvQL7RAqMplfXdaXNGooiPXWqKWTFDKUfpTmipOyR4rrg3TzN4yQRfRlF O+qdVj03CKcR510fInIGWz6y0+CJRfs0dPLjGWZbHCTBx2eYUUqb8pBLz1+RpJ1eBw3Bp 9DrQNOkBPZY4QjgyXog5LNIKrqeBBeW1HVBqGHApyj3gyH8vewz8a/1WTPzvpG/iyDr/k qp/KzjlRJ/crX4OED36L/z5vvpACVVy1fV6Le2VGO/esrDkw+CRnnpILFLoI2Smnx5cDD Ntg16AKTjzz56YvQZisJDkwri2xnmmlk32SV1ZAi3DDcf+EQpKGP3LT7uARAwpbeOjA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599681; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=PvTUbuQb8MHiVLyqrdeS9xyc96F8bRisytUKyGbJEOQ=; b=mI3/AGTzL5W0ubMtSQnWupH1qxM6ReJ4nxEPhHXI/DUcM0cnIP12w+UHwuCEjv8QlISl TpKGmrUAYlWvf71B8iRdNkxZz0dEJ9SZrkPLvq9BNDWgV7WH9G+JdjEPCIjtEprau9hY2 X1V0gxTXMN0YKw6N//nn50lE2yL1jtK27ewV2tBNG8L9RAbm5P1jRcG1QQLQZyiNNPxK2 2rXTj9kBj29CVGqxbEKUMnx4UNwsV3sfUZ9BSjrTyhG/m6BAkzmcuyoi6BndnjjHSgbgU 2y4ye+9csFre1a3CpJEv4Ed+UtTv9oSnb137UvX+LddoShA2c72KP7oCZSXVj9TyGgw== 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=Vvl2ahfV; 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 766C3606AE95 for ; Fri, 13 Nov 2026 19:54:41 +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=Vvl2ahfV Received: by smtp.kernel.org (Postfix) with ESMTPSA id 964551F000CA; Fri, 13 Nov 2026 19:54:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599681; bh=PvTUbuQb8MHiVLyqrdeS9xyc96F8bRisytUKyGbJEOQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Vvl2ahfVSWgDCL7X9BfU/tbQMGzQFnoDF/XvCeuRa3q0EP/8u+V3vosabdX8/qnZd dfW41yQDWBYlVJnTXS5zaaKyjYkVfOF3ECHHozV4WQuN5XYqIDLhWUT7zeWV//E+UN Bq1CC4M0Jnt78dW6REokGVrq/8zCgtCziKZ3lgzje2Mnub0hTTlrf/A2rDUet6bqbZ RVphiWngW17wPQKKdRILN3pJYWEQBin/4I+QGPBP8pt6WmgTX1MIdKfWld81yb6eF0 8/qQtUIbcZxmjFfXFPPsPmvFxnb9s0QB2GD3JQUIbrDyYI/uXTy/LxJ3mF5JueFKP/ gIJKOjMI9bfew== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:54 +0100 Subject: [PATCH mptcp-net 16/34] mptcp: initialize drop_req in subflow_init_req() 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-16-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2851; i=matttbe@kernel.org; h=from:subject:message-id; bh=PWYUAZdkSfAkh8EC4Mo/jVDZmR8fX9/umHc1wQ2yQhQ=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z92d86CV43aB5QsnNhWGWdm3mn68dCiJLbB8+5M54 OdRfoW6jlIWBjEuBlkxRRbptsj8mc+reEu8/Cxg5rAygQxh4OIUgImkfWZkmL/Eg++r0lNmQT7V Re2MXNIri5/XKGTbTOpRnHxfdtqWxQz/XTi5cj8xzBNfoRzx69feghNXPX83H/tmuPvQYbtsG7n nrAA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason With CONFIG_MPTCP and SO_REUSEPORT migration, which net.ipv4.tcp_migrate_req=3D1 or a BPF program enables, TCP sockets can leak until reboot, and each keeps its network namespace alive. tcp_check_req() keeps a child off the accept queue if drop_req is true in a request socket that an MPTCP listener created. drop_req has one writer, subflow_syn_recv_sock(), which tcp_check_req() calls before that test only for an MPTCP listener. But if SO_REUSEPORT migration moves the request socket to a plain TCP listener, the test reads what the allocation left in drop_req, and nothing drops the last reference of a child that stays off the accept queue. The fix used here is to set drop_req to false in subflow_init_req(), which runs when the request socket of an MPTCP listener is set up. This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch, run as an unprivileged user in a user namespace, with net.ipv4.tcp_migrate_req=3D1: an MPTCP listener and a TCP one sharing a port with SO_REUSEPORT, the MPTCP one being closed while handshakes complete. Without this patch, the children were leaked, with their network namespace, without any message from the kernel: repro: step 3 to 6: 32 SYNs, 16 went to A. A closed, 16 third ACKs. accep= t() on B returned 0 [...] repro: RESULT: 16 children never reached an accept queue repro: one RST for each connection. TCP: inuse 0 orphan 0 tw 0 alloc 16 m= em 0 =3D=3D=3D exit code 0. The process and its namespaces are gone =3D=3D=3D after: TCP sockets allocated, all namespaces: 16 [...] With UBSAN, the original version of this patch also reported: UBSAN: invalid-load in [...]/include/net/mptcp.h:144:47 load of value 14 is not a valid value for type '_Bool' tcp_check_req.cold+0xb6/0x189 tcp_v4_rcv+0x11f4/0x4230 Fixes: c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitt= ing SYN+ACKs.") Signed-off-by: Chris Mason [ Shorter comment. Commit message: how the issue was found, and its symptoms. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/subflow.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 7b8183b6a13e..543368cfc890 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -151,6 +151,9 @@ static void subflow_init_req(struct request_sock *req, = const struct sock *sk_lis subflow_req->allow_join_id0 =3D mptcp_allow_join_id0(sock_net(sk_listener= )); subflow_req->msk =3D NULL; mptcp_token_init_request(req); + + /* read by tcp_check_req() even after migration to a TCP listener */ + tcp_rsk(req)->drop_req =3D false; } =20 static bool subflow_use_different_sport(struct mptcp_sock *msk, const stru= ct sock *sk) --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599683; b=FKn9uLnfCw1r5Y9qlA1OMyw31xso4eU+ueUtb/KHg8IBg48jq0moJcXfBplX6K/WcY4T dHZzFVyJRHUUgdJBxQO0tO5REMino4LQilAIyEhoNOOmj65Q1RTdOc03J3pOg3kgstO23 ETr7z9I9XHI5DWglUBNkLOYG2nm3OfY2wjo6PDh8OhC8q5HcDeoz98ouiBYeG4nabA0MZ YBc9G/77w5mApjzmumW+D3sBLyKCFEWQMuwAtyMAXWwcUnyjlqENgBGwsW9s0vsNoTKLa QMIezxuhVyDgYTNfzW/oeMPeHFhNmrd55lHaAds7aj/15OSbrHQSBD3LzljLRLSd+1w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599683; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=C4X5HzONSCfdWXGQSkyVhX4JvV2WJ4zr2jsyiMJCi4o=; b=PG+jPd2CZRrop51DHqWUWA7e+3t/JcayrvoLEISoV/6/Ns63vxqk3oBeWsNdimxy/msH +4xBKXOYiRxu2Hk88DJ+nFuZgQM/jM98rSzK1O3p0CqpXbtyDwN0UJi3vqfhVISsoKrLB tzc+V6yOeLKXExc2yyVkQ5Fb8y4Vgfvzhl/bUuhuTimcKPLU8OwNk/zgcqKxil741RbXu DMI92dhX6kLhzaYzfZy39Q82ue7svpf2ceQAto0jKztXPNBruFOH80BN+mxWES/d+l4QA jynOqI2Qz8qlatmsKH/qzV+eFkc8gT8nwjR1jzuxLy3BuV7dNiWnIqJ3d0W4/CJA1QQ== 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=nYiZBAS7; 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 E2CA5606A89A for ; Fri, 13 Nov 2026 19:54:42 +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=nYiZBAS7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B45F61F000C5; Fri, 13 Nov 2026 19:54:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599682; bh=C4X5HzONSCfdWXGQSkyVhX4JvV2WJ4zr2jsyiMJCi4o=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=nYiZBAS7VDTaUQ3t8HBjB8kPDJRJnpYHRLjlrI8SG0DqBP+BboHAN9pnrWtWF6/zv H+ot9A2mLfCdhZo9bEYU/XQtru3v3+cKR5+Vyi0cnYwLKfEuPto5EeDwUMh1ORYeQb N46QJSFb9S13SVT58rE1g4Uk/MRqd0E+iC4HZIBljztYYHwVkA4EU7KrevAonPwxT3 9FELbESOy8ZZHyJf6HMMZa9hZQWMtgAwqx6VzmanzSyQuKilt8T2VIfH1bvPyRpcTz PEKSoEofStqC33SNagy2TBZd7T7LAd+CZCtyi9p1CHmjU21D/5aKMS8V8txmOs3+mb ZgrMbffK19rJw== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:55 +0100 Subject: [PATCH mptcp-net 17/34] mptcp: pm: kernel: count endpoint listeners as sockets in use 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-17-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3061; i=matttbe@kernel.org; h=from:subject:message-id; bh=BoI5JMs8XNYoBRMkau/c8cUjriZTyOx+60jgUoDQygQ=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z931jFdzX5Actv66QJ/En8O5MfybDr3e+0/8bvWsf j+lxcdOdZSyMIhxMciKKbJIt0Xmz3xexVvi5WcBM4eVCWQIAxenAExESJ+RYSa34J1ZBSeb3ioH /uwoYqsRS2hcUHKEw/1m4+rpanJa/IwM3Qslb5uK5W2L83r4OiQt2SR11lTFid3PTUuyzvz4cDC CEQA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 The listener that the in-kernel path manager creates for a "signal" endpoint with a port is not counted in the "sockets" column of the MPTCP or MPTCPv6 row of /proc/net/protocols, but it is uncounted when it is closed. Each removal of such an endpoint then hides one MPTCP socket of the same family from this column, for the lifetime of the netns. mptcp_check_listen_stop() decrements this counter for any MPTCP socket closed in TCP_LISTEN state, and mptcp_listen() increments it when listen() succeeds. But mptcp_pm_nl_create_listen_socket() sets its MPTCP socket in TCP_LISTEN state without incrementing it. This socket is closed when the endpoint is deleted or flushed, when adding the endpoint fails after the creation of the listener, e.g. because its ID is already used, and when the netns is dismantled. Nothing depends on this counter, it is only displayed. But it is wrong once such an endpoint has been added: its listener is not counted while "ss -Ml" lists it, and after its removal, the total is one below the number of MPTCP sockets of the same family in use, a negative total being displayed as 0 by sock_prot_inuse_get(). The counter was introduced by commit c558246ee73e ("mptcp: add statistics for mptcp socket in use"), when only the subflow of this socket was in TCP_LISTEN state. Commit 57fc0f1ceaa4 ("mptcp: ensure listener is unhashed before updating the sk status") then set this socket in TCP_LISTEN state too, without counting it. The fix used here is to increment the counter when this socket is set in TCP_LISTEN state, even if __inet_listen_sk() fails then: unlike in mptcp_listen(), the socket stays in this state, so the counter is decremented when it is released. This issue has been found by an AI code review agent, while reviewing the code of the commit "mptcp: pm: don't let listeners pin their netns", and confirmed with a new Packetdrill test, and with a shell script adding and flushing such an endpoint 3 times in a new netns, then creating 3 MPTCP listeners. Without this patch: kernel_listener_inuse.pkt:15: error executing `test $(awk '/^MPTCP/ { n += =3D $3 } END { print n }' /proc/net/protocols) -eq 2` command: non-zero sta= tus 1 inuse: endpoint 1 present: 0 (expected 1) [...] inuse: 3 user listeners: 0 (expected 3) Fixes: 57fc0f1ceaa4 ("mptcp: ensure listener is unhashed before updating th= e sk status") Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_kernel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c index cd882eb6af54..4955c928ea32 100644 --- a/net/mptcp/pm_kernel.c +++ b/net/mptcp/pm_kernel.c @@ -906,6 +906,7 @@ static int mptcp_pm_nl_create_listen_socket(struct sock= *sk, * old status is known (TCP_CLOSE). */ inet_sk_state_store(newsk, TCP_LISTEN); + sock_prot_inuse_add(sock_net(newsk), newsk->sk_prot, 1); sock_set_flag(newsk, SOCK_RCU_FREE); lock_sock(ssk); WRITE_ONCE(mptcp_subflow_ctx(ssk)->pm_listener, true); --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599683; b=zFhNEPi85vctSXdNSDY5DzhbXZbBy8s5Moi1UXyEf38SDlE6ikUgHEEgHE0PH/Ilh4mw VYuXDlVf9VwU+scHc7LrWGWJsxQAriWFVtE1Dh7MZa3jKF3nq8YU8WUwlGTh40YMnxemU CN6rCGyhieeqWYd1jfh8hML/uVIvHA5nvKtyJFdf/gnhblE+7Nz9SFMvIuOjRiswffU6l t52lr63S1fN9s5WkFma1SOgye/qx/gZvnljUBJJFVBcOqHRrdXTVidZMuI/ftjHTgI35y tNj4os7shn+dOnRQ0ujes4M0p1ulMM730uu+DSIWhCuNWRzCh32grrB0BwuFKt7zPUQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599683; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=WeSZTbUfTmiY4P3kv0k2uDVrCyD2mmUymj2WUv9LguY=; b=gW3iWvbLl0sZ/QsZA+AH7hrpcO6QOwK0F6XTvL2La9C8G8QYZkxlwsv1Kujhfnscy/J0 1LsLnd3v2HlYoQFsqZzz9ibWHegni3J++BvZSbnXk0Lr4VATs6Q1D9IGdCHxR1JFpSAuf G4VBntnHYPypfsU9mIDo/ZQLCrwTTS2W4J7Ho9c6Ea/cdCA7O590zpQdpCaq2NFMAHlKb 1Knd9pi4C36RKnKLBs/TaIprWsqO9jMtkLs3Bu1HR9KPOAMTfpytda8EM7MbbB5brllnp X2fnUZsepBrL5uf8zkyJzKo4fNEOks2JCxjk22saPN18Xzm9WRNEA0DvMLDvqNj/6Bg== 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="HPte//c5"; 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 B852E60A2637 for ; Fri, 13 Nov 2026 19:54:43 +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=HPte//c5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6B3D1F000C4; Fri, 13 Nov 2026 19:54:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599683; bh=WeSZTbUfTmiY4P3kv0k2uDVrCyD2mmUymj2WUv9LguY=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=HPte//c5dEO6cV5bwQQoDYimk34vACe9lMWCv7i7EqoKmq3VtqpSlSj5I+LPx7NzW SmWrS++MpR8dfRSwtKnOo46Ye8R7YmBFMm+CgpBA/tEX7EKwtS66su9nBX+7iBDfUA pgVpvlaxGscdlJN1cdI5alZLR62uZbCHbnQP37Z8QGfwj6Vgp5KaJ3uMkMF0wyq0Fc jG35Z5WdSbYjy5qKAofp3pxICssK7/b0lqGZ14g8pS297HTyQJBa+d9B/x8txgl3A3 iJQ+oEKTGy8RxhOPdtPsnmShkpYeMvkfd1ieD3wmeS+g4BueFPIwtthihIDWbanvsB M47Ng/rDQ9AfQ== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:56 +0100 Subject: [PATCH mptcp-net 18/34] mptcp: count a listener once when listen() is called again 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-18-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2648; i=matttbe@kernel.org; h=from:subject:message-id; bh=t8BnfJts93zbU93F5dtfmVY8DEQMiji/CE7gCVGyXgE=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z93jZhaYH7X3G9vyxf5Lkq9+O2q+Qbd1slVDY612t /yqW8z/O0pZGMS4GGTFFFmk2yLzZz6v4i3x8rOAmcPKBDKEgYtTACYS8oqRYRpn/DW7mscZdi37 VvecizPlvn56ktjRhGDJLeHdLUa88YwMHzz1f3z6tzlc+1TMv4sP1sx7aHzkaADndqbt6jfDll7 g5gUA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 listen() on a listening MPTCP socket only updates its backlog, as with TCP. But mptcp_listen() then counts this socket once more in the "sockets" column of the MPTCP or MPTCPv6 row of /proc/net/protocols, and sends a new MPTCP_EVENT_LISTENER_CREATED event, while only one decrement and one MPTCP_EVENT_LISTENER_CLOSED event are done when it is closed. Each extra listen() call then leaves the counter one above the number of MPTCP sockets in use, for the lifetime of the netns, and a userspace path manager can see two listeners created for one closed. With TCP, the socket is only counted when it is hashed, which is not done again for a listening socket. The fix used here is to only count the socket, and send the event, if it was not already listening. This issue has been found by an AI code review agent, while reviewing the code of the commit "mptcp: pm: kernel: count endpoint listeners as sockets in use", and confirmed with a new Packetdrill test, and with a script calling listen() twice. Without this patch: listen_listen.pkt:12: error executing `test $(awk '/^MPTCP/ { n +=3D $3 }= END { print n }' /proc/net/protocols) -eq 1` command: non-zero status 1 inuse: relisten: listening: 2 (expected 1) inuse: relisten: closed: 1 (expected 0) Fixes: f8c9dfbd875b ("mptcp: add pm listener events") Fixes: c558246ee73e ("mptcp: add statistics for mptcp socket in use") Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 6dc55a3f027b..8f954a752797 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -4381,6 +4381,7 @@ static int mptcp_listen(struct socket *sock, int back= log) struct mptcp_sock *msk =3D mptcp_sk(sock->sk); struct sock *sk =3D sock->sk; struct sock *ssk; + bool listening; int err; =20 pr_debug("msk=3D%p\n", msk); @@ -4397,6 +4398,7 @@ static int mptcp_listen(struct socket *sock, int back= log) goto unlock; } =20 + listening =3D sk->sk_state =3D=3D TCP_LISTEN; set_bit(MPTCP_RTX_ENABLED, &msk->flags); mptcp_set_state(sk, TCP_LISTEN); sock_set_flag(sk, SOCK_RCU_FREE); @@ -4411,7 +4413,8 @@ static int mptcp_listen(struct socket *sock, int back= log) release_sock(ssk); mptcp_set_state(sk, inet_sk_state_load(ssk)); =20 - if (!err) { + /* only the backlog changes when listening already */ + if (!err && !listening) { sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); mptcp_copy_inaddrs(sk, ssk); mptcp_event_pm_listener(ssk, MPTCP_EVENT_LISTENER_CREATED); --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599685; b=o4BQQWzZOlbuxG+rEl54M5+3U24Hj+FgY6q0rM92HQrQpBPs2j5jPNhMKk5zras18gOT RjkVTxnUn3pRR0pF0GuZ35FajjWPxcZfyITPBrsgnmZ/1D36Dodyxup18VYINlpPbhP0I WQwSBt4wJEEPD+rVJGGFOa1+5/Coa5d6JLaF7xk8agXlNQBvymgODuUZi/MMelmcxxWfA UnHjRM/IFsgBEGbmjkqJWTlLS/hcLO2E3Z7RKd8zbHsqFMznx4S74LFWVKYGkh4WpM/0u eyli82ru/Y54nqmiYxeN+CbMfpOZqKDvv1gs9aodOGhc2ScYYRyJi4llGlN0LbeTXhg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599685; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=imrHokibfbJUigTYinrScpriEfwVQrmZYyhf64nR94o=; b=qiOMNCjvYS9MLpHtMtjEu6flT64VBAUQkx9IG8kpgcTKDMT6v/H4Qihc6qCZon+MOuK+ 99LfxNYuclNIr34ArZyG/vKXpRdxC7kJT7w36D/LC0+YAJTYpYM26ByeKUEwskUj8cXbR YjxRCK16nGilZh7yNbMcOjetUkRoM7h+nudVuPfuXu2kk2zdHq+mcuuzB2uX4gdrUqPf6 6CUvk8woOVwBVu/Z71IM7gZkhh0MS6Jqa0L8S9aAacO4s6wZYJq9bxrQjZ7z56ZCyRU5q jdhuAqzyAi8OEiVhy1OWKCEWpOs8OC6i/pQ6wiXFzgYGNxGEJSyq26W7e5w2/+Moe5A== 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=HTshLBCA; 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 E1D4060A3809 for ; Fri, 13 Nov 2026 19:54:44 +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=HTshLBCA Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01A6A1F000C4; Fri, 13 Nov 2026 19:54:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599684; bh=imrHokibfbJUigTYinrScpriEfwVQrmZYyhf64nR94o=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=HTshLBCA8untuX59EDlYgWjIDnV6qCtKHjzfNbxaTkWEyIyZt9c1CVmJyBJ0oMI/J 72PodRrIYiStPyJ2fDbDCLzkgxGhdXAp/Cfq48xtpi6ncQOvD8e+J0Qd7VsP2VekDQ Fc/TCQDqYQRCDOGhvIMTItAYEs3K1CFQH7IWjP9qQ1P0UugOuWXWQiMttOJPNL9gvm q41hM/ZzasGeWHZr2PBImZabNHY3Tc7LEx/PoBIYd7H0KAUpIu6XImJHaEb8PUl0i6 2HHiELknAz0umilo1g1Vq9Pq89uSnjQpiBVrGHY9usMAKoAmGZSByLKIAuUKAYhCSc 7w+iIz2KrTV0Q== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:57 +0100 Subject: [PATCH mptcp-net 19/34] mptcp: do not fallback while old data is in flight 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-19-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=8308; i=matttbe@kernel.org; h=from:subject:message-id; bh=NcNLfFtAD2iC34O32qNaGX1T4AF5wd0pN+2JeOTKac8=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z93n3H+vj7/kkOYmRbE5CktEn5mFLau00P63rsM9f h3nQ3+vjlIWBjEuBlkxRRbptsj8mc+reEu8/Cxg5rAygQxh4OIUgIl84GT4X7bTYPPt7+Wry3V8 BTnObLwnefzo9E2zIjvWuGxcl/RH6gDD/zjmi592/HBsEo/omFgdZhq1z0Jl85K98beOLewofMt 6jQMA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason If an established MPTCP connection falls back to TCP while a zero window probe or reinjected data is queued or in flight, recv() can return data twice with no error, so the stream is silently corrupted. After a fallback mptcp_established_options() writes a DSS option only for an infinite mapping, so an skb that mptcp_sendmsg_frag() queued with a mapping to data sequence numbers (DSN) is sent without that mapping. The receiver treats the bytes of the subflow, in sequence order, as the rest of the stream, so a fallback is only correct if the subflow carries each byte of the stream once. But allow_infinite_fallback, the flag that permits a fallback, stays set in two cases in which old data is queued again on the only subflow. First, a zero window probe is a copy of the next unsent byte, mapped to the last acknowledged DSN so that the peer drops it as a duplicate. Second, when a subflow whose MP_JOIN handshake has failed is closed, __mptcp_retransmit_pending_data() marks all data that has no DATA_ACK yet as unsent, although no second subflow has joined. If the sender falls back while such bytes are queued, they are sent without their mapping and the receiver delivers them as new data, as here for a probe: sender receiver =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D queue a probe, a copy of byte N get data with no DSS, fall back read, open the window send the probe with no DSS no DSS: fall back deliver byte N send byte N as data deliver byte N again /* corrupt */ The fix used here is to refuse the fallback while old data is in flight: - when mptcp_sendmsg_frag() maps bytes to a DSN below snd_nxt of the MPTCP socket, set the new bit old_data_pending of the subflow, and store the TCP sequence number after these bytes in its new member old_data_end - clear the bit in mptcp_incoming_options() when a segment with a DSS, other than an infinite mapping, acknowledges that sequence number - make mptcp_try_fallback() fail while the bit is set, so that its callers reset the subflow - delay the infinite mapping that answers an MP_FAIL, and the fallback that comes with it, to the first data that is queued with the bit clear, and send plain mappings until then - after a fallback, skip data below snd_nxt in mptcp_sendmsg_frag(): a reinjection that has not reached the subflow yet does not set the bit A consequence: if the old data reached the peer with its mapping, but the DSS acknowledging it is still on its way back, or lost its options, a fallback attempted meanwhile resets the subflow, although it would have been safe. This window lasts about one round trip, or as long as the acknowledgments lose their options. This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch: between two unmodified Linux hosts, nftables removing the MPTCP options, e.g. while a zero window probe is pending, or after a failed MP_JOIN. Without this patch, the reader got some data twice, with a regular end of file: the stream was silently corrupted: receiver 4.692: READ-TOTAL outcome iii-repeat-or-gap bytes 8388609 of 8= 388608 missing 0 twice 1 [...] end: eof [...] receiver 8.611: READ-TOTAL outcome iii-repeat-or-gap bytes 26000 of 140= 00 missing 0 twice 12000 [...] end: eof Note for the backports: this patch depends on commit 119d51e225fe ("mptcp: fallback when MPTCP opts are dropped after 1st data") and commit f8a1d9b18c5e ("mptcp: make fallback action and fallback decision atomic"), two fixes which may have already been backported: they allowed the fallback in the reproduced cases, once data has been acknowledged without checksums, and after a failed MP_JOIN. Fixes: 1e39e5a32ad7 ("mptcp: infinite mapping sending") Signed-off-by: Chris Mason [ Shorter comments. Move old_data_end to an existing hole, after subflow_id. Commit message: mention the reset that can now replace a safe fallback + how the issue was found, and its symptoms + note for the backports. Moved before "mptcp: continue the last mapping after a fallback". ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/options.c | 6 ++++++ net/mptcp/protocol.c | 17 ++++++++++++++++- net/mptcp/protocol.h | 9 ++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index b4b3292fb4dc..682a7b93d962 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -1317,6 +1317,12 @@ bool mptcp_incoming_options(struct sock *sk, struct = sk_buff *skb) return true; } =20 + /* DSS acking the old data, not an infinite map: no peer fallback */ + if (unlikely(subflow->old_data_pending) && + !(mp_opt.use_map && !mp_opt.data_len) && + !before(TCP_SKB_CB(skb)->ack_seq, subflow->old_data_end)) + subflow->old_data_pending =3D 0; + /* we can't wait for recvmsg() to update the ack_seq, otherwise * monodirectional flows will stuck */ diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 8f954a752797..7329deb43c62 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1472,6 +1472,12 @@ static int mptcp_sendmsg_frag(struct sock *sk, struc= t sock *ssk, info->mss_now =3D tcp_send_mss(ssk, &info->size_goal, info->flags); copy =3D info->size_goal; =20 + /* after a fallback, the subflow got all data below snd_nxt already */ + if (unlikely(__mptcp_check_fallback(msk) && + before64(data_seq, msk->snd_nxt))) + return min_t(u64, msk->snd_nxt - data_seq, + info->limit - info->sent); + skb =3D tcp_write_queue_tail(ssk); if (skb && copy > skb->len) { /* Limit the write to the size available in the @@ -1552,6 +1558,12 @@ static int mptcp_sendmsg_frag(struct sock *sk, struc= t sock *ssk, TCP_SKB_CB(skb)->end_seq +=3D copy; tcp_skb_pcount_set(skb, 0); =20 + /* old data mapped again: no fallback until acked with a DSS */ + if (unlikely(before64(data_seq, msk->snd_nxt))) { + mptcp_subflow_ctx(ssk)->old_data_end =3D tcp_sk(ssk)->write_seq; + mptcp_subflow_ctx(ssk)->old_data_pending =3D 1; + } + /* on skb reuse we just need to update the DSS len */ if (reuse_skb) { TCP_SKB_CB(skb)->tcp_flags &=3D ~TCPHDR_PSH; @@ -1582,7 +1594,10 @@ static int mptcp_sendmsg_frag(struct sock *sk, struc= t sock *ssk, out: if (READ_ONCE(msk->csum_enabled)) mptcp_update_data_checksum(skb, copy); - if (mptcp_subflow_ctx(ssk)->send_infinite_map) + + /* the infinite map implies a fallback: wait for old data acks */ + if (mptcp_subflow_ctx(ssk)->send_infinite_map && + !mptcp_subflow_ctx(ssk)->old_data_pending) mptcp_update_infinite_map(msk, ssk, mpext); trace_mptcp_sendmsg_frag(mpext); mptcp_subflow_ctx(ssk)->rel_write_seq +=3D copy; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 3be60da12924..75d4c2f82501 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -602,7 +602,8 @@ struct mptcp_subflow_context { is_mptfo : 1, /* subflow is doing TFO */ mpc_drop : 1, /* the MPC option has been dropped in a rtx */ resetting : 1, /* subflow is resetting */ - __unused : 9; + old_data_pending : 1, /* old_data_end not acked with a DSS */ + __unused : 8; bool data_avail; bool scheduled; bool pm_listener; /* a listener managed by the kernel PM? */ @@ -630,6 +631,7 @@ struct mptcp_subflow_context { */ =20 u32 subflow_id; + u32 old_data_end; /* TCP write_seq after the last old data */ =20 long delegated_status; unsigned long fail_tout; @@ -1330,6 +1332,11 @@ static inline bool mptcp_try_fallback(struct sock *s= sk, int fb_mib) struct mptcp_sock *msk; =20 msk =3D mptcp_sk(sk); + + /* queued old data would be sent without mapping after a fallback */ + if (subflow->old_data_pending && !__mptcp_check_fallback(msk)) + return false; + if (!__mptcp_try_fallback(msk, fb_mib)) return false; if (READ_ONCE(msk->snd_data_fin_enable) && !(ssk->sk_shutdown & SEND_SHUT= DOWN)) { --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599686; b=zgySrX4H87l3Uk5z34UPSYJhztqz5Lj01VUKVSE+W8GtoFK4Yh+hrzvecsky4diTbRu+ FruX17xM337eZZtuQHvvbIoeWpi44l1yD+k/FlXAsC+Y9Jq5fATV4XPLiYx5CVycy8qTu g7lIu9+0LmHQfAiCRx/3aLgvbWDmyBUO0v47EB2mkIi9hnbwfFe8ewwatLYDevIhPos3f +M7AOO8nmST5jVCASrPUl6tyoHZNfw7RLp8alcZdIM7p2c/QvQll0RMctb/JOstg/VceT 8gq45mUEBceA267ydESqLCvLLR7eFp7KYBIJrhWwDnzlOI3vTlbYqvJi8GcfNkmaHsA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599686; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=LGQziJWXSnuepgQoY91VWzlyQ+xtTmXMbUmaQjznZF8=; b=1Q/7TJf3MGM4N1eYerhc5Y49EBtNddLq62+py23NIRe6UPA8QRDum1YFIavv+gB9SvNF 0zV9SlI0GhuNMMDD8MPI+i87V7U02wDCVDCfuDnnkC+7TRbmGiRRkPRbyI4mseTuDCb0j MZWovztPCVOuG+chWKB1t7zkp6/JMjCqO8ped6QsNsaUWKgzsQ3DlwC4QpZ3v5bL8vzRh ZmeEmBaruPX/iQhQ/PB4AsaYwlr8yb3eY0MNDNn8OxjBeX/rGviItUTQQ3V0JZefPpvrL sNKjqatVcPpJbA8GZH6ACZvg6iRksbQ6qUi0kSBwhaETSCkLAhOqO3Flwpxg0pdd2Mw== 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=opettgoH; 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 38AC5606D0CA for ; Fri, 13 Nov 2026 19:54:46 +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=opettgoH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 201D71F000C4; Fri, 13 Nov 2026 19:54:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599685; bh=LGQziJWXSnuepgQoY91VWzlyQ+xtTmXMbUmaQjznZF8=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=opettgoH8skBugbRPa9lMrY/8UaMBIP0citcP1q/3F5XQKagmESSQLK5w/X3mNrwi dryyyEmdC5+ZTRUgbEuQTX8TsplmF+RPFyEuWFZvDp4nbUVHGPGLw6QifT0XWEfLpS dGs8YQCfXoT7Bh/dxi4Ot5tnmB8qAxrj9C5Kjku36CmzHf8QDxVnUynUMLDNVH5SxA uDA7dHR7VdKGJNXcUrGjXnLGkZ7rL0eO32HmIdyn4ZtZEnM1DpADrfdp6cCQum77cV 4u4IdiqeT08GB9jQiiPazTPohEKTStJlhC3I9dIv6tgc2n/qExSZZe6Kkt7nU5I0mD YdtQQwnm6yrEg== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:58 +0100 Subject: [PATCH mptcp-net 20/34] mptcp: stop resending data to a peer that fell back 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-20-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=7336; i=matttbe@kernel.org; h=from:subject:message-id; bh=QW3eneUxjiAhekY67A723B56Azcp+iaoyZwE0r4/vYI=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Zz3w8DY6O1vu9EcJl5L3gvN1vJeW9X41+3qp4cX1b i3LiCkKHaUsDGJcDLJiiizSbZH5M59X8ZZ4+VnAzGFlAhnCwMUpABOZ857hD6euiflFSaa0W593 Jj26wCSfWTe77LO51VKB7JdvV2/oEWD4Z7WDdZ3CGZ+CbQ6aZzMNeHZ/fvfJS/jcbO38U9kaGu/ yeAE= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason recv() on an established MPTCP connection can silently return data that it has returned before, again and again, if the receiver falls back to TCP and the sender does not. While no DATA_ACK arrives, the MPTCP retransmit timer makes mptcp_sendmsg_frag() queue old data on the subflow again: either fragments from __mptcp_retrans(), or a zero window probe. That is only correct while the receiver reads the DSS mapping of these bytes and drops them as duplicates: a receiver that has fallen back to TCP delivers them as new data. But mptcp_incoming_options() ignores a bare ACK, one with no MPTCP option, on a fully established subflow, so a sender that gets only bare ACKs from that receiver stays in MPTCP mode: sender receiver =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D send bytes N to M (a middlebox removes the DSS) no DSS: fall back deliver N to M, send a bare ACK no DATA_ACK, the timer expires send bytes N to M again deliver N to M again <-- wrong send a bare ACK The fix used here is to: - reset the subflow, with the reason "middlebox interference", when mptcp_sendmsg_frag() has more old data to queue and only bare ACKs have acknowledged the old data queued so far. The test reads old_data_pending, which the earlier commit "mptcp: do not fallback while old data is in flight" sets when old data is queued. That commit clears it when a segment with a DSS, other than an infinite mapping, acknowledges old_data_end, the TCP sequence number after that data. The reset is counted in FallbackFailed: the peer has likely fallen back, but this side cannot - clear old_data_pending for a segment with any other MPTCP option too, in mptcp_incoming_options(). An infinite mapping stays the exception - skip a zero window probe while the TCP retransmit queue of the subflow holds data: the MPTCP retransmit timer, armed when a push leaves data behind, tries again later This limits the repeats, but does not prevent the first one: data that was new when it was first sent does not set old_data_pending, so its first MPTCP-level retransmission is still delivered twice by a peer that has fallen back. After a failed MP_JOIN, more of the reinjected data can be. A consequence: a peer still in MPTCP mode, whose options are removed on the way back for a while only, recovered once the options came back. Its subflow is now reset as soon as more old data is due. This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch: between two unmodified Linux hosts, nftables removing the MPTCP options in the middle of the transfer, so that only the receiver falls back. Without this patch, the reader got the same data again and again, here 65 MB more than once in 120 seconds: receiver 127.514: READ-TOTAL outcome iii-repeat-or-gap bytes 68255744 of = 8388608 missing 0 twice 65650688 [...] [...] took 120.0 s end: limit: still data after 120 s Fixes: 119d51e225fe ("mptcp: fallback when MPTCP opts are dropped after 1st= data") Signed-off-by: Chris Mason [ Shorter comments, also in struct mptcp_subflow_context. No timer arming when a probe is skipped: "mptcp: arm the rtx timer if a push leaves data behind" already does it. Commit message: the first repeat is still delivered, and a peer that loses its options for a while only is now reset + how the issue was found, and its symptoms. Count the reset in MPTCP_MIB_FALLBACKFAILED. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/options.c | 12 ++++++------ net/mptcp/protocol.c | 19 +++++++++++++++++++ net/mptcp/protocol.h | 2 +- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index 682a7b93d962..6790c9e15521 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -1271,6 +1271,12 @@ bool mptcp_incoming_options(struct sock *sk, struct = sk_buff *skb) if (!check_fully_established(msk, sk, subflow, skb, &mp_opt)) return sk->sk_state !=3D TCP_CLOSE; =20 + /* MPTCP opt acking the old data, not an infinite map: no fallback */ + if (unlikely(subflow->old_data_pending) && mp_opt.suboptions && + !(mp_opt.use_map && !mp_opt.data_len) && + !before(TCP_SKB_CB(skb)->ack_seq, subflow->old_data_end)) + subflow->old_data_pending =3D 0; + if (unlikely(mp_opt.suboptions !=3D OPTION_MPTCP_DSS)) { if ((mp_opt.suboptions & OPTION_MPTCP_FASTCLOSE) && READ_ONCE(msk->local_key) =3D=3D mp_opt.fc_recv_key) { @@ -1317,12 +1323,6 @@ bool mptcp_incoming_options(struct sock *sk, struct = sk_buff *skb) return true; } =20 - /* DSS acking the old data, not an infinite map: no peer fallback */ - if (unlikely(subflow->old_data_pending) && - !(mp_opt.use_map && !mp_opt.data_len) && - !before(TCP_SKB_CB(skb)->ack_seq, subflow->old_data_end)) - subflow->old_data_pending =3D 0; - /* we can't wait for recvmsg() to update the ack_seq, otherwise * monodirectional flows will stuck */ diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 7329deb43c62..388e77da8f16 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1444,6 +1444,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct= sock *ssk, struct mptcp_data_frag *dfrag, struct mptcp_sendmsg_info *info) { + struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); u64 data_seq =3D dfrag->data_seq + info->sent; int offset =3D dfrag->offset + info->sent; struct mptcp_sock *msk =3D mptcp_sk(sk); @@ -1527,11 +1528,29 @@ static int mptcp_sendmsg_frag(struct sock *sk, stru= ct sock *ssk, return 0; } =20 + /* a new probe would move old_data_end: one at a time */ + if (!tcp_rtx_queue_empty(ssk)) { + tcp_remove_empty_skb(ssk); + return 0; + } + zero_window_probe =3D true; data_seq =3D snd_una - 1; copy =3D 1; } =20 + /* old data acked without MPTCP opts: the peer may have fallen back */ + if (unlikely(before64(data_seq, msk->snd_nxt) && + subflow->old_data_pending && + !before(tcp_sk(ssk)->snd_una, subflow->old_data_end))) { + tcp_remove_empty_skb(ssk); + MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_FALLBACKFAILED); + subflow->reset_transient =3D 0; + subflow->reset_reason =3D MPTCP_RST_EMIDDLEBOX; + mptcp_subflow_reset(ssk); + return -EAGAIN; + } + copy =3D min_t(size_t, copy, info->limit - info->sent); =20 /* like TCP, allow some progress up to tcp_wmem[0] */ diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 75d4c2f82501..e61b6a3a955d 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -602,7 +602,7 @@ struct mptcp_subflow_context { is_mptfo : 1, /* subflow is doing TFO */ mpc_drop : 1, /* the MPC option has been dropped in a rtx */ resetting : 1, /* subflow is resetting */ - old_data_pending : 1, /* old_data_end not acked with a DSS */ + old_data_pending : 1, /* old data not acked with MPTCP opts */ __unused : 8; bool data_avail; bool scheduled; --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599687; b=IBCmtJlLSEetIYYtmmLkrcMSKkfTCDgGxbC9H9up/Ovp2oOY83EcxjkgZuP31N2bncpc jDv2KmVUmISXCclXr9cO+Bp+2mCKPHsXAhUGQvMsYXWYSM33nhWbn4jJ9xWmm4b8QyDdP S83WqI1C8kwRYaFMqo3CXWc8kjR5r4thgJXs/CgBh0lFFfewxS56HZnPUIrrFuwxUa9bq ch3XFt9wk5x9Y9MvA+syRa9VYXvp5MG1FtLumVTt0GsGqjwp7wUtAkQ9zVQpd78j6QjmK bAaXAJVnjs0m4THAf1ND8O/4gzse2TJC7Etvda5b00j3wo1dyHx5H5Ppdm+Bf+OIU1Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599687; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=LtykvKAuB/k2zHXEydM4TKa/vTDWgr+HDiamPibVH1Y=; b=cUV01gWdOmfTdpiUk49p0vU0V16ytj53IXz/E2iaRJKjw0vfLqF6+tCTc4/J0rojVBaL t5vaSRAcCT7WpokLhMbGyqDi79s4M6iiX3YyE/7h4t35U73hm1CDqocINep/7ipvqsPAM K5egvfr5V3Rs/EqpGq77gE/p/CjPBilbRGWJbdFvYTb8V/Eu6msTkgSvKPmrgyVmZ11N8 xZsT/oNBVSIgXbBH6r6JNAjm9h4QDwuvcKgNzwKXerOFYzlEKFHKHQmTVKLC0fUhKg3gG De7MrbOTwdh9cYlTzH9iuosWf6i3iXEkEaEx46ILwB+eVLew1EqPARgkVmhwLSMVRxw== 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=YJaQlfmt; 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 44AE7606D0C2 for ; Fri, 13 Nov 2026 19:54:47 +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=YJaQlfmt Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FB501F000C8; Fri, 13 Nov 2026 19:54:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599687; bh=LtykvKAuB/k2zHXEydM4TKa/vTDWgr+HDiamPibVH1Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=YJaQlfmtm7SVVmD7knMrnw44vvyJT8o57wATdanHV2cfzufy4XZBf/2UIWgao86rr laqF7lCHyz5k6YL/+HJZle9lvozYKVKI/mGoPm24ZBpQAbLqwE29VVpUP3/A0cKQt3 l59Km3F1FrLu+6Lvh2gXrprYGtNdlhELqYk5bYEnyH1m6HoKxsNNmn/W5MsvekMaCt 7eh5zWkZJ6iTl0qbL7Ojpy/FQmh9dSlGwlJJCDXxVBjo2xcaaOakIxWsgYmxsXZorz 1h+VuuTBfRqUQsMdlNVXjj0zmyg9xj4UbtkUS08218c0u8ggdjNG51Dj7/fAn72RKO sPnUiwba0s4Ng== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:53:59 +0100 Subject: [PATCH mptcp-net 21/34] mptcp: pm: kernel: don't count signal+subflow ID 0 endp 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-21-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" , Josef Bacik X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2991; i=matttbe@kernel.org; h=from:subject:message-id; bh=8X/pgFm5oMi6uqXYBW1J615qsTAMQvVMjuctgZ1KHek=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Zz3YYLStq9JK9XbQ43mWR07dWXB326fJBtcfzlrF1 LpIb1PAm45SFgYxLgZZMUUW6bbI/JnPq3hLvPwsYOawMoEMYeDiFICJWG1l+J/xa/u9Ium9iqla qW+2bD23JP7uqaRZndy985ynpRkEB61nZOh45Py9eqauyp737nFvhOoVV29qvT837/7ylleau1W kGlkB X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Josef Bacik local_addr_used must not be incremented for the endpoint of the initial subflow, because __mark_subflow_endp_available() does not decrement it for ID 0. mptcp_pm_create_subflow_or_signal_addr() tells that endpoint by local.addr.id =3D=3D msk->mpc_endpoint_id, in the loop that creates the subflows and after it. For an endpoint with both the signal and the subflow flag that comparison comes too late: the part that announces the address has replaced local.addr.id by 0 already. So the counter goes up each time such an endpoint is removed and added again while a connection that started from its address is alive, and never comes down. When it has reached the number of subflow endpoints, the connection does not use any new endpoint: after four rounds local_addr_used was 5 instead of 1, and an endpoint added then got no subflow. ID 0 can't be the ID of any other endpoint: look at that, after the replacement. This issue has been found with the help of an LLM. It has been reproduced with the modified "delete and re-add" subtest of mptcp_join.sh, from the next commit: without this patch, the subflow of the ID 0 endpoint was not created again at the third round, local_addr_used being above local_addr_max: # 002 delete and re-add [...] # after re-add id 0 (3) [FAIL] got 2:2 subflows expec= ted 3 [...] [...] subflows:2 [...] local_addr_used:4 local_addr_max:3 [...] Fixes: 9366922adc6a ("mptcp: pm: fix ID 0 endp usage after multiple re-crea= tions") Fixes: 579a752464a6 ("mptcp: pm: in-kernel: always mark signal+subflow endp= as used") Signed-off-by: Josef Bacik [ Keep the original one-line comment. Commit message: 'behind it' -> 'after it' + how the issue was found, and its symptoms. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_kernel.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c index 4955c928ea32..976d72565bda 100644 --- a/net/mptcp/pm_kernel.c +++ b/net/mptcp/pm_kernel.c @@ -411,7 +411,9 @@ static void mptcp_pm_create_subflow_or_signal_addr(stru= ct mptcp_sock *msk) /* Special case for ID0: set the correct ID */ if (local.addr.id =3D=3D msk->mpc_endpoint_id) local.addr.id =3D 0; - else /* local_addr_used is not decr for ID 0 */ + + /* local_addr_used is not decr for ID 0 */ + if (local.addr.id) msk->pm.local_addr_used++; =20 nr =3D fill_remote_addresses_vec(msk, &local.addr, fullmesh, @@ -432,7 +434,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(stru= ct mptcp_sock *msk) * case. This avoids issues later when removing the endpoint and calling * __mark_subflow_endp_available(), which expects the increment here. */ - if (signal_and_subflow && local.addr.id !=3D msk->mpc_endpoint_id) + if (signal_and_subflow && local.addr.id) msk->pm.local_addr_used++; =20 mptcp_pm_nl_check_work_pending(msk); --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599688; b=nndEBA2TECMe5D0IZi8OJnum6HRZ9HHY1Z3KoVnjCCaqGMDtZ+LddkZzZ97ZbLzQwOtY 8twm0+rTwVHJq9L+ZuR0Rzw7PYrgpikzxQTcMcd2KQeNH7hSMwNbBOFK3A3JGL7e2rqS4 j/domG13Yr0F9BNE4QY0aijRSLZ/dLvRPXKGQ2QLtWhDuEmb2w1PFPcfD8Maj7NxU7S1A PYbrcy0U8COXX8cOyR+MnmRCPWowHWyuR5AFO2r9YW67P2gPvvru+R2aSD2qp7HZlCYoZ G8bHk4/ynvuPvfj/f90650GV2ECPcl2AxRQLqkGAKQ9ik4uYYK42423vWj7yAKHp5CQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599688; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=lMRIQVsONxIKglrvSyqr5H/29Al6TnhbZxn2Kyw6k9w=; b=nsjRRQ3aHul29dj2KfMmkJZ8kgN9lx7gJApr1DcfvYu1u3eHNPkdzVBhrliGw3QGgzsO 6ipZ9v2NxOPhCJS4sa/moWkXdj9+31D8uoz4sffpMsafCSFNCqF1pSgr89jeEHQr8CSEP wBZbqnmMxO7cEhuBRS4dscYJsUyZDYQfjrjtlB2PcLw7166w0QSTUSqKQManK4UOaR+9K J6yC9WgYTETYg6+slb2M2fWh6+9aywTee9iPM70qXPvAXP2Yh2/W/HL9lHcieeWa+v+Rn A1DEQahm9CeiOzi84PYbQF7MuRrG8unywnTr0GMpZxLGWDND6yg9iNCZzTXtQKQ/fGA== 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=EyyQor6H; 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 A888A606D0D1 for ; Fri, 13 Nov 2026 19:54:48 +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=EyyQor6H Received: by smtp.kernel.org (Postfix) with ESMTPSA id 831381F000C5; Fri, 13 Nov 2026 19:54:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599688; bh=lMRIQVsONxIKglrvSyqr5H/29Al6TnhbZxn2Kyw6k9w=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=EyyQor6HXmT/yJx5Wbxa+Tl6d2e+cuZ95bKX9+YsJ+HofTSuKWKyQdSKGSzu7yPa8 KvwF7BtDQ0YqMSk0mTWP7rfPRBAPE/C521UYjSXJUpgZx1cSk+ku/ORtjKwgTIVddg 5muXc2tLo8DbgIFQHjuCAkslfpC8IiDKuPjsP7oTNkeoX2lnYH49KSAObX3ei/veCz 1vAoqBwbc/atptZa/x9zXRYfws0l6HkBwA42kIuuW71XgtlWBh5ZSW919aUkKbp2yd TbCstqvzzx+GtyUe8g604NxUHAXjQst0xnlYjQ8LCkLGvAa73lOZ+QjIiJWcBgizy3 2Q1f9bO4MpUQw== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:54:00 +0100 Subject: [PATCH mptcp-net 22/34] selftests: mptcp: join: check re-adding signal+subflow ID 0 endp 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-22-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2754; i=matttbe@kernel.org; h=from:subject:message-id; bh=TjBpwuHhNzRS1ipzelTDYXpHBFaY0+qGHmTDuX/fwbc=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Zz3smPVupV9/yYJ7Hl5Hrjv/sg9OYr4Zq6n8rzPiU rdh3/e+jlIWBjEuBlkxRRbptsj8mc+reEu8/Cxg5rAygQxh4OIUgIlopDEyLPx5es2VDHX7nR+s 1ub/dFxwvbTROtK2YU/VrEnP7tYt5mVkmMQlsGRqyGuTkj79DXOk52Y8MjsdlrhaSD7sv4v5xJt L+QA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 This test extends "delete and re-add" to validate the previous commit: when the endpoint linked to the initial subflow (ID 0) had both the signal and subflow flags, it was counted as used each time it was re-added, while this counter is not decremented for this special endpoint. Once the counter reached the number of subflow endpoints, no more subflows were created. From the second round, this endpoint is now re-added with the signal flag too: without the previous commit, the subflow is not re-created at the third round. The ADD_ADDR sent at these two rounds are dropped, and not retransmitted: if the server received them before the new subflow, it would try to connect back to the address and port of the client, and fail, which would change the counters. The 'Fixes' tags here below are the same as the ones from the previous commit: this patch here is not fixing anything wrong in the selftests, but it validates the previous fix for an issue introduced by these commit IDs. Fixes: 9366922adc6a ("mptcp: pm: fix ID 0 endp usage after multiple re-crea= tions") Fixes: 579a752464a6 ("mptcp: pm: in-kernel: always mark signal+subflow endp= as used") Signed-off-by: Matthieu Baerts (NGI0) --- tools/testing/selftests/net/mptcp/mptcp_join.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testin= g/selftests/net/mptcp/mptcp_join.sh index c3ccce96b45b..6cd187577479 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -4387,17 +4387,23 @@ endpoint_tests() ip netns exec "${ns2}" nft insert rule ip filter OUTPUT \ ip saddr 10.0.1.2 meta l4proto tcp \ "${RM_ADDR_OFFSETS}" drop || nft=3D0 - local i + # No ADD_ADDR to ns1: it could try to connect back to ns2's port + ip netns exec "${ns2}" sysctl -q net.mptcp.add_addr_timeout=3D0 + ip netns exec "${ns2}" nft insert rule ip filter OUTPUT \ + meta l4proto tcp \ + tcp option mptcp subtype add-addr drop || nft=3D0 + local i flags=3D"subflow" for i in $(seq 3); do pm_nl_del_endpoint $ns2 1 10.0.1.2 sleep 0.5 chk_subflow_nr "after delete id 0 ($i)" 2 chk_mptcp_info subflows 2 subflows 2 # only decr for additional sf =20 - pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags subflow + pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags "${flags}" wait_mpj $((3 + i)) chk_subflow_nr "after re-add id 0 ($i)" 3 chk_mptcp_info subflows 3 subflows 3 + flags=3D"signal,subflow" # ID 0 not counted as used either done [ "${nft}" =3D 1 ] && ip netns exec "${ns2}" nft flush chain ip filter O= UTPUT =20 --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599689; b=nm+1aj4HiiE/qh9l0ulERR4dlMSoYkaP5XALc4kvszcEqjUp/4Pxbfs1DNhGeS+ul1y3 Cd26yriYnkP1ycttQaw9/OIRcJR2SP2Tq+7pQW4DFyYxy0tAvplk0en2WjhSqEAF9jHwE rzKuxRPD42dk/g2dTZwTBECoIcG0DxUlRX3wkYD6pz3hWqWh041gH4A8gXhuEYa8t3Kmy zWtYwKNdGkk2lNJvJBZB/1c007zCjQ4HjfvLFfHode7HyaSnfC7wqlw2PsFOSA3e3Ztfm 8wSMTR4FDVGzcXA3WX/MFL8RmkUqw5lH2t6oj4faAZnQJq7EJ8ojt8xXyvPZIttQ2ng== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599689; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=dOQQHZT5y9iZOXtyva7qJi/mlZZok7kK1SJ1l4LJY1U=; b=3NDz7Dg/sTgLxtSB/QOGepv/fgYb7SfpbKdTwmMgRhzRcXPHu5FFHYiqCstL0UO1dp0E dAtGMqITQxJA8ru7EKts81iVEpYE+ELGWC9fQPwaMkJUqi6DxPMxcCTNdRmXgzMx/QwDO WnCbeeokFaTeHhHQRCgw6gyMVcn9nv6M0F8DQVt0W2Yv/Thz2QdcdthcxCk4GAtANYSTa ellRpDVwkEsS33oA32+L8D0xWKHDWD52GFY+9uOw0jQf+uCvE3oJl7bRT5DTeU6pl1lbF dESTnWInVlYtGVrQIM94gZcngx0Yey2o8jQ9ZStzn/CaDcWgYYOfzXYvOi2eZ2GhwwQ== 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=KYDvRXfA; 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 834E0606D0E0 for ; Fri, 13 Nov 2026 19:54:49 +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=KYDvRXfA Received: by smtp.kernel.org (Postfix) with ESMTPSA id A24E51F000C8; Fri, 13 Nov 2026 19:54:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599689; bh=dOQQHZT5y9iZOXtyva7qJi/mlZZok7kK1SJ1l4LJY1U=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=KYDvRXfAcCUhWnPPr/Z9fvct6lpoZECCSrWxB41WxfddB14YSg61tBFuH4FopRWbj bNH/9hATaeo2gHB0UOzEuRvrgVBxE0BQcasKEbZ++43ApSbLYBsJR0LjFSftQ1lnAb no457kJUp4xKGO8C0D92ahXytvpYGm+DFW4y2UhxxdsO0nXs0DyBKr/wFM8wLUMudf m6pnXRTE3yRcgmTpeElDR+GyrzUOqPfAVSdtk2RASh5EnARVgy3zOUfRE/3VX2ZfdN GueMfwbFbcSz07dg0AY7QLyggTeB9jIdCPl7tx+vIXqSZ5UBlrlI5m8C6naUVUxHTj 3iXCHAoO7/MxA== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:54:01 +0100 Subject: [PATCH mptcp-net 23/34] mptcp: use sk instead of casting msk in check_fully_established() 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-23-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1592; i=matttbe@kernel.org; h=from:subject:message-id; bh=BIchpMSFFRoVXDHhNN+GHJA5kr5JKEzhPgY9OxUNiJA=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Zz166vxCoO7T9ifOmrMXBgnrVnjoL/C4+unEs4ena uer36s36ShlYRDjYpAVU2SRbovMn/m8irfEy88CZg4rE8gQBi5OAZiIJxMjw0cWtYURPy5ufr9S uvDMV/Xi2qXW6+zeP0llsj53Kbfg0lOG/yVfj5mvfiJwglW5JKDZIfOaDu+vtK0HumJ7zzr9npT ygR8A X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 The MPTCP socket is cast to a struct sock in check_fully_established(), to take its data lock. The next commits need it more, to push the pending data. Add a local 'sk' variable instead of casting msk each time: no functional change. The 'Fixes' tag here below is the same as the one from the next commits: this patch is needed to fix the issues introduced by this commit ID. Fixes: 36b122baf6a8 ("mptcp: add subflow_v(4,6)_send_synack()") Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/options.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index 6790c9e15521..a74520f6b069 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -982,6 +982,8 @@ static bool check_fully_established(struct mptcp_sock *= msk, struct sock *ssk, struct sk_buff *skb, struct mptcp_options_received *mp_opt) { + struct sock *sk =3D (struct sock *)msk; + /* here we can process OoO, in-window pkts, only in-sequence 4th ack * will make the subflow fully established */ @@ -1044,9 +1046,9 @@ static bool check_fully_established(struct mptcp_sock= *msk, struct sock *ssk, if (mp_opt->deny_join_id0) WRITE_ONCE(msk->pm.remote_deny_join_id0, true); =20 - mptcp_data_lock((struct sock *)msk); + mptcp_data_lock(sk); __mptcp_subflow_fully_established(msk, subflow, mp_opt); - mptcp_data_unlock((struct sock *)msk); + mptcp_data_unlock(sk); =20 check_notify: /* if the subflow is not already linked into the conn_list, we can't --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599691; b=NS3QZ49t3BBvuRt52mhl3HCTO8NU395x5tMwKrbYCucJMcOCv2bcZy2o3seWw9XnKege bwOZQ+Ij8m4fvjCHpKyl9fN6lVfJ9nmSz/vMAmRP8BlMtTgAQk3PH+tRcD2EKfWXGClFL Jqb7Y466wWhAk6iS1ilh/PjNeOf8xxayb5SkXVxnCOBb3seP8zc3180AhavoAJ2RJ23Fr qO/DWoivkajPe36q2j37LMezDJxMICd4UAhHwCa3OqaAD4S+V9K/LHYZHz5t7gqLAwUDK K4nnx6J07Fpo2yqbfUeXbl5/BqqG1Fo8JJj33y42g/1TG0pHDBxWsG7roHvx85IRveQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599691; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=73Q50ZJbtUofhkqDeqIdFCD+8VHDOnYJeBukBl20hxU=; b=KTTBLeygmIFUIGTAiVNnpckKeAKWQOImHyW3pbl1xj4H5Y4x3OJPJCBOMGoyHFWmp8Xn 9f+zLeJTqtUl1ncM+z9lDsF8Zi5oqhdq5VVaHgFdAfa1FfRD+VK0MKMySG6dLF/gOj46Z Qfugf6m3CT+m1FNugJgZCt1NdGTfeNmuEPhkPtGVEG3+qITAg8eNX9XJUhYaELd1uCMdu UFqBoF6C4AyDrQ7Ny3JawiOb6kqmUjNy5GTAlevWz+JMmyK+CTPRxOOv89s7pcH0QTT8I zs2RDnPqV+ssfYwbVUkyR8k16NLtnQJjfG2B/DsoxGayDfExR+8Lda7VmOEem/2/0aw== 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=XEkCA4gf; 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 20850606D0EF for ; Fri, 13 Nov 2026 19:54:50 +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=XEkCA4gf Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1D351F000C8; Fri, 13 Nov 2026 19:54:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599690; bh=73Q50ZJbtUofhkqDeqIdFCD+8VHDOnYJeBukBl20hxU=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=XEkCA4gfvrm26jbGlGTJZwxKtlx5NPa2IfRwkQIlUlbfEo3UCc/F6/JBUTYvXv3oN 3CvsoNz3mrHKb18mjahpz5nugrcBkpZLA4/lWiuUZU5uMmme/wROQre6F4o00sKL5Y eD6RicgYb6wy5xSfWuH+n/38XK/W8v+uEJQoCvl9pxSEcjRZsosiL9lMvGHhlQk8Nq ki5q4C0IxncdEzT7CiR9UjJDoYI+7aWlGPlya5Zm1/HSO2264VCq3kfL2a628sOMUE kwzB8nhNOS92iThNk0hXcy4Ki6Fp2H7IQfGqA38YfNeEt1mXEnF2I02/nkoPUXTmdL oATIW4dSdAT6A== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:54:02 +0100 Subject: [PATCH mptcp-net 24/34] mptcp: push queued data on passive TFO subflows becoming established 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-24-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" , Petar Sakic , T S Rameshkumar X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3433; i=matttbe@kernel.org; h=from:subject:message-id; bh=qsjLEJPZNLiVtwGz2tvC9VdE7rExvTlSWx/F6iR+vRA=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Zz3+rngt4ebO65wBN16klX99wHHB5YH9h6A+/75eu f+xs0x4O0pZGMS4GGTFFFmk2yLzZz6v4i3x8rOAmcPKBDKEgYtTACbS/pqR4bTZ05sck9dGJ26/ OKV52kczk0+LqvN/qD8/eWehWuLCzcoM/0v+vmEU+83KfC4w5EHmsSuTp3+w/ZW3xb5KzyY71/5 6ER8A X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 With TCP Fast Open (TFO), the data written by an MPTCP server before the third ACK is not sent when this ACK arrives, but only when another event triggers a push, e.g. new data from the peer. With a request/response protocol, the client waits for the reply, which can then stay stuck. A SYN with a valid TFO cookie creates a child socket right away, which can be accepted while its subflow is still in the SYN_RECV state. The MPTCP socket is already in the ESTABLISHED state: send() puts the data in its write queue, but this data cannot be pushed to the subflow before it is established, see __mptcp_subflow_active(). When the third ACK, with the MP_CAPABLE option, arrives, check_fully_established() marks the subflow as fully established, but nothing pushes the pending data: this ACK has no DSS option, so ack_update_msk() is not called. The fix used here is to push the pending data when a passive TFO subflow becomes fully established. Checking subflow->is_mptfo is not enough: since commit e00b63056fb4 ("mptcp: fastopen: only mark MPTFO subflows with SYN data"), it is not set when the SYN has no data, while a child is also created in this case. syn_fastopen_child is then used instead. This issue has been reported by a user of proxies over MPTCP: the clients put their requests in the SYN, and the replies from the targets close to the server were stuck. It has been reproduced with new Packetdrill tests, where the server writes data before the third ACK, after a SYN with and without data. Without this patch, and before the earlier commit "mptcp: arm the rtx timer if a push leaves data behind", this data was not sent: server-tfo-write-before-3rd-ack.pkt:24: error handling packet: Timed out = waiting for packet Since this earlier commit, this data is sent, but only when the MPTCP retransmission timer fires, here after one second, as the tests increase its interval: server-tfo-write-before-3rd-ack.pkt:24: error handling packet: timing err= or: expected outbound packet at 0.237174 sec but happened at 1.181857 sec; = tolerance 0.100000 sec Fixes: 36b122baf6a8 ("mptcp: add subflow_v(4,6)_send_synack()") Suggested-by: Petar Sakic Suggested-by: T S Rameshkumar Reported-by: Petar Sakic Closes: https://lore.kernel.org/mptcp/CAFPPu1gU2Y-D+d4i3F0MoNkYK+e1U+=3DX3q= f6QycjfKBw+8snPg@mail.gmail.com/ Signed-off-by: Matthieu Baerts (NGI0) --- Note: T S Rameshkumar sent earlier versions of this patch [1], but stopped. In the end, we are back at the version suggested by Petar, with syn_fastopen_child instead of is_mptfo. This issue is affecting users, we can no longer wait: that's why I'm taking over, after having sent a few reminders. [1] https://lore.kernel.org/20261012111001.542847-1-rameshkumar.t@phytecemb= edded.in --- net/mptcp/options.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index a74520f6b069..3477a7ec5a05 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -1048,6 +1048,8 @@ static bool check_fully_established(struct mptcp_sock= *msk, struct sock *ssk, =20 mptcp_data_lock(sk); __mptcp_subflow_fully_established(msk, subflow, mp_opt); + if (tcp_sk(ssk)->syn_fastopen_child) + __mptcp_check_push(sk, ssk); mptcp_data_unlock(sk); =20 check_notify: --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599692; b=2bwvIzUVoifO9Si/BYGpZAk/WJEZcmpma/B1cmRFaJX8iy2uSPY56Wi+2+5lyqn1SLV+ legCF3eFEeOBq6fvOnOOYo97p45rQZC4oyRbOPl4szdBj/VK9BgLCiF4iYLeEH1mVJsO4 dtvgZD/WyzDnHArvRSCYYLefjeyYCrOVU2/O5pgo4kcq0o6xwJbaNuZkuZqp81beh+LMa SZZkJjNX/12CqKiRFvmEBxjI60Q0g7jz26fVgdzFOyVMJ20Rcz9ngtFGSTsNzPrrp4m5F Oi88RC+BuLtJ2gOR+uoW6vtsVXxjmTBylN2QQu+ly9NfSkiXaRIsaZvsBq4diWoH9RA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599692; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=J2fN1dTbxw9ZFbXlLl+ZVj0v3rMcXWmbDkGIedCb7DI=; b=RpusPKc88jVqMTGumownHC/IVHuPhITAuD3CQ4YKWeRhAQR7BgdIXi34scVn6XApdBPk dz+PNoNnCJf5bHyq9Xn3xxFGeV0Z+a8rheSpJJlzE7OeHicTTGlAy3+rlMDwVL+ZvmAqu Ki+kAQWvnle6OoICDHewAo1qF8pNpT+RpgDxatLiqdbG8Lqh2pWfhCjbHIdX2/cqMGe2b wbWjOKTXLvuHCH0m3EVu1zDAjvNU1ogDWOdz6kUcLf/mwYhvpoRaavLYTP95xpU74Tyc6 zW/gbVtaKqXgWugKyUqtKWAtXgMcvV3FnLqLNG/JcYHBqpsEZd3sGyxBKxVdmKxrGQg== 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=OUe0ihDA; 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 36A62606A8A3 for ; Fri, 13 Nov 2026 19:54:52 +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=OUe0ihDA Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37B661F000CA; Fri, 13 Nov 2026 19:54:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599692; bh=J2fN1dTbxw9ZFbXlLl+ZVj0v3rMcXWmbDkGIedCb7DI=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=OUe0ihDAxdevb8mIC2IDB7mGXdIIufPCBcAiSb0W0+aaMPstO9ogqJSp0wSjT622w qNHc1mb8MqEOvwzOTMVzLU8MRUAPNLJh9ttTDyigb0WXdEu05ofn5RfBvdRaoDulAm FPqmk8jAKzhTLFvOI1bMO+5WCZc46z/uvlGwJZOQ3hk2ip9wG62GkDFSpH23xSWyoT iUIalkq7JJ6n01XwCETW5Sac4uV1HEEbJCNf6g6IoOHx1/lCHWN7pm00jO2ZFPmIIE z7Em7I1b+z54Lu3TIa7Dt8co6IT9gV/+9YNS7E2wwsb1qNaBrszfv3SXvdhzHAZ9Wd BE+3ntT32ofAQ== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:54:03 +0100 Subject: [PATCH mptcp-net 25/34] mptcp: push queued data on passive TFO subflows falling back to TCP 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-25-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2300; i=matttbe@kernel.org; h=from:subject:message-id; bh=tolMyCn3ZfsUpNCvJ7fbbbjbTidaykJPTNVmxGkQvXQ=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Zz3Z7/XgmW53vIL40fLkDEuNfZ9zzB0FL/IL/f+70 SfoTq5QRykLgxgXg6yYIot0W2T+zOdVvCVefhYwc1iZQIYwcHEKwESy+xj+GWwO4nly2UdU//JC lcM77Wzcdi/0vWr54CRfYYbsO0FZFUaGhp1nrp9Xnvl6+2LXjHJ+vWtcD3fUxXvL+dfqPiieMes BFwA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 With TCP Fast Open (TFO), the data written by an MPTCP server before the third ACK is not sent when this ACK arrives without MPTCP options, but only when another event triggers a push, e.g. new data from the peer. The previous commit pushes this data when the third ACK, with the MP_CAPABLE option, makes a passive TFO subflow fully established. If this ACK has no MPTCP options, e.g. because a middlebox removed them, check_fully_established() falls back to TCP, and returns before this push. The fallback case of mptcp_incoming_options(), which pushes the pending data, is only reached with the next packets. The fix used here is to push the pending data after this fallback too, for the passive TFO subflows only, as in the previous commit. This issue has been found by an AI code review agent (Clashiko), while reviewing an earlier version of the previous commit. It has been reproduced with a new Packetdrill test, where the MPTCP options are removed from the third ACK. Without this patch, and before the earlier commit "mptcp: arm the rtx timer if a push leaves data behind", this data was not sent: server-tfo-fallback-write-before-3rd-ack.pkt:26: error handling packet: T= imed out waiting for packet Since this earlier commit, this data is sent, but only when the MPTCP retransmission timer fires, here after one second, as the test increases its interval: server-tfo-fallback-write-before-3rd-ack.pkt:26: error handling packet: t= iming error: expected outbound packet at 0.235869 sec but happened at 1.144= 189 sec; tolerance 0.100000 sec Fixes: 36b122baf6a8 ("mptcp: add subflow_v(4,6)_send_synack()") Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/options.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index 3477a7ec5a05..c56ca5e4df14 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -1035,6 +1035,11 @@ static bool check_fully_established(struct mptcp_soc= k *msk, struct sock *ssk, MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_FALLBACKFAILED); goto reset; } + if (tcp_sk(ssk)->syn_fastopen_child) { + mptcp_data_lock(sk); + __mptcp_check_push(sk, ssk); + mptcp_data_unlock(sk); + } return false; } =20 --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599693; b=OMSI3B1smy/7CJSuMnwu5Pc9C2XeivBJoqlJxP94nUplLSsdzewRYGpzFwty5aCk22bM nyqYl7bEXJrydFWu/gw4dmfk/ggRMBMHdVRg2H6gFD/gJXNLFzxunbQ6/KyrXr9YDkLo1 pSa9ZGaNpCYiQyIq9BodRbQO7Ou1R1UdAcQo+uBEIy44X6pzaaB1VAmY+X7uS3W/nFaG+ b+K+hMM38wIvvTM51BWnLbrDfT4+/hbnz1ndOWU5Oi6/i7sMpXyBcFgRQJX+nKGCap+jl s0xK2+UDXIEVvGahJQtYTHQh8L3W6w/RCmlufp1o0deGaF3oJssQuUQrtHwrqlY6OZA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599693; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=RXyfarQm91RWVJovkOcaSl9U1kxbBlrNXjsV7TSVacE=; b=NNz9d/5W7aQB1twO4gBvFN1NcIpsU0BNsgoJ1xvYX8ysUb3F574PsR7MwQ8pRn3JDPFN JAYcTA4QLWdn7B7sLUkY+jHdIXMB35g1pczzWprKSaA9dW3U8c7BiSbYMlI6QpkRPADX0 45oiPmO5hU+Xr/o2aZoDSvYFQ1badfLCNsJFHiSADRcWD2Ql5PgWL4K7awyMvMgCL8sKv kRwKkVIhgnskStHAY9w4eklOL6+Vz6OjWrhFvxhqtVsiOEBA4Q8Fd0RtLrcQKhJ5Si/Al nbcc80t8lcc5k7Qv0JdHTkQRJDYAHsk4iQF6YWwr1arV6tgCWlGY0ULN6MYxU/jyBgQ== 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=Cf6wUp5F; 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 4EB04606D0FA for ; Fri, 13 Nov 2026 19:54:53 +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=Cf6wUp5F Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57ADE1F000C4; Fri, 13 Nov 2026 19:54:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599693; bh=RXyfarQm91RWVJovkOcaSl9U1kxbBlrNXjsV7TSVacE=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Cf6wUp5FH6Rrsql7TK70OIV0W0fifnFAqRLT+FdKIuW3IG6SZ8+M/i0g7IDGCJfWB 3IQtEmjfGJrY8xCEgalbgTbZxHsRnFj59gteqAckXTOID4692nnQSx9VaRzMnlMnel MvcLwH0vjF3QPmT0EBOhsZy1T8x3qRYbnlUv4GLz/2vbaAnELZE6kb/CEDVpiyOvq7 gypuiG7tYkUxT+ck4tdptrVyGlaqTE5XLcfvagv7Rgsaevjk5UE9X0f2eynmT64H82 90FYJzQDbiJI0RudNGyCULUnVTSfVHHOCZobxoS6Isp94VH1O9MaBcwb/fef9T+Yas Gx26hUucyTfQA== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:54:04 +0100 Subject: [PATCH mptcp-net 26/34] mptcp: don't send a FIN before the pending data on fallback 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-26-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2694; i=matttbe@kernel.org; h=from:subject:message-id; bh=jqibTObWwJ+hwhTwzQ1+5CEC/4YRaITgXK4sdRphLFI=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Zz2RTC0IsU56+2PlpReh+auE1zcdNT3+aMqnDbndu f/jO9iYO0pZGMS4GGTFFFmk2yLzZz6v4i3x8rOAmcPKBDKEgYtTACYyQ5SR4cZGhuL5gpk/D0h6 Zi94euaQyf1dznwn067dOC8v18f4Zgsjw2tDU5blXZPOv1ZYO33+xjSlc5MnXL/I8H7m0WW77Zd vkeUGAA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 When an MPTCP connection falls back to TCP after having been shut down, the data that is still in the write queue of the MPTCP socket is lost: a FIN is sent at fallback time, and this data cannot be sent after it. This can happen with TCP Fast Open (TFO), when a server writes data and shuts the connection down before the third ACK, and this ACK has no MPTCP options. When the MPTCP socket has been shut down, mptcp_try_fallback() also shuts the subflow down: if the DATA_FIN had already been sent, nothing would send a FIN on this subflow otherwise. The commit introducing this only considered the case where all the data had already been pushed to the subflow. The fix used here is to only shut the subflow down at fallback time if no data is pending. Otherwise, mptcp_check_send_data_fin() will do it once this data has been pushed, e.g. by the previous commit. This issue has been found by an AI code review agent, while reviewing the code of the previous commit, and confirmed with a new Packetdrill test, where the server writes data and shuts the connection down before the third ACK, from which the MPTCP options are removed. Without this patch, a FIN was sent right after this ACK, and the data was never sent: inbound injected packet: 0.240127 . 501:501(0) ack 4103187975 win 450 outbound sniffed packet: 0.240207 F. 4103187975:4103187975(0) ack 501 wi= n 1050 outbound sniffed packet: 1.347800 F. 4103187975:4103187975(0) ack 501 wi= n 1050 outbound sniffed packet: 2.499829 F. 4103187975:4103187975(0) ack 501 wi= n 1050 outbound sniffed packet: 4.739843 F. 4103187975:4103187975(0) ack 501 wi= n 1050 server-tfo-fallback-shutdown-before-3rd-ack.pkt:27: error handling packet= : Timed out waiting for packet Fixes: d51991e2e314 ("mptcp: fix shutdown vs fallback race") Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index e61b6a3a955d..d76eaed4f01e 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1339,7 +1339,10 @@ static inline bool mptcp_try_fallback(struct sock *s= sk, int fb_mib) =20 if (!__mptcp_try_fallback(msk, fb_mib)) return false; - if (READ_ONCE(msk->snd_data_fin_enable) && !(ssk->sk_shutdown & SEND_SHUT= DOWN)) { + + /* no FIN before pending data: see mptcp_check_send_data_fin() */ + if (READ_ONCE(msk->snd_data_fin_enable) && !mptcp_send_head(sk) && + !(ssk->sk_shutdown & SEND_SHUTDOWN)) { gfp_t saved_allocation =3D ssk->sk_allocation; =20 /* we are in a atomic (BH) scope, override ssk default for data --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599694; b=3XJ1UpXoYAbB6s2W7jk+QwYhjDZBmRva8jXXyvVuqalyf1Wbp+dbZDEy3ovtxRggOWW9 dEws3aKKoI2IZUo48sdmcy+syuZbCgJFx9ryhgH5iNL93lxS/OxRKwQsOhUSPJjN72Rmm /fEx+Ob6MrwvRXtmblTclOY525/sHbK8eYjT0qp4HZiYL0OTbvvsp+S05co42nYUju+AW +Uaw4Is09PiuS7yJvHwK3ybWPvNV+MfiL40nJeO7BbrCCmvqgEvT6YWHv/ZECIbAxOrLN pzbZ/l3+rWXwLZ9PFB8usV+9TIBWNHCOGSKjnGIg4pW/ReaCXoKYy+ndWJFA0gLNdHg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599694; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=1+GMm9bo2jBU50QEK+49Z942SdK0zztpyaweSmkMiEo=; b=PdqPC8WaNbDSdWha0Pj0eZTgTHpJEWk2rSZlY1HDcUILMuachHqQUHZkZPYYJoBL03jO O5Nlrpx44APOQ4di7kt7qL8DL2vGM6uAFzUgH8VPHO4/wYnsE5hUf0amRUcgKuVHH2ndq cCw6SWdrpG5Iq1i8h3mpjOYlmoMhMUpp1Pz+d/Ld7cPuLK+TLE5hL33MhOri/eEHG8ZW/ y5TGGzm5M2/NO7aZjUM3lu+wRqTfTeYqkiiVK0VSwyRKanimz9bYy5sj/JrHcpCxmM8qZ NQx84JnTbiZh1fAPZb73bnjpPbpfXJv6h168Y99B/QmOzPK+Irli9/V7W21hstr4FPA== 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="DdW0b+/c"; 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 61285606D0EB for ; Fri, 13 Nov 2026 19:54: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=DdW0b+/c Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77A571F000C6; Fri, 13 Nov 2026 19:54:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599694; bh=1+GMm9bo2jBU50QEK+49Z942SdK0zztpyaweSmkMiEo=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=DdW0b+/ccTjBJ+zh/viTUQCZ2yOwQrpYYzc5V3wTemzLUc0JzYDQMjGHDfN1FGieZ IG26La2tNwIqwnWbzMTCNGVmGSprE+cmAWT4cXTG20ZDoCDn087UN6ZRiTxw0eBcWe Y6xdkxnaXKzBC4ChDJu+qST6x8JVSStPuy/rn+vpb617lHlHMJ8JR1U32KhsAUkusK qV/pn8MzIPkWjj6Uej7bXZ8BGBvqJ115cNqJiIwtjIq6UUZyfiDifc5WdUmHpVmrnu 9ADPqW5WnWxA2cu7l18Kipn5krJLqO5i3luvDqKKUYpzZyGYOBdIDX20mw8Xarbk9A bYjqkn185iQ1w== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:54:05 +0100 Subject: [PATCH mptcp-net 27/34] tcp: do not pass a BPF reqsk to an MPTCP listener 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-27-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3160; i=matttbe@kernel.org; h=from:subject:message-id; bh=6HheWE2kPACK0MgpwEPXOtAzyEFwPPlvyzfTK7gyE9k=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Zz3dfPSImLyiWt/xkgVqv8xDLwpqC0ZuutHtafgvT nZ1of2LjlIWBjEuBlkxRRbptsj8mc+reEu8/Cxg5rAygQxh4OIUgIkIL2BkmOl4IX9rxsULEq0/ M/54uv4yfVny/4FL3aGNb2NVrYT72Rj+uz07+MtVUZnpbNzHr3me7fbrfB/xbNrCFplqoS7Zl7q JBwA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason A slab-out-of-bounds write and a panic can occur if a tc BPF program that validates SYN cookies assigns an ACK to a TCP listener, and the ACK then goes to an MPTCP listener of the same SO_REUSEPORT group. bpf_sk_assign_tcp_reqsk() attaches a plain TCP request sock to the skb, and returns -EINVAL if the program passes in an MPTCP listener. But inet_steal_sock() and inet6_steal_sock() select a listener again from the SO_REUSEPORT group of the listener that was passed in, and the result can be an MPTCP listener. cookie_bpf_check() then passes the request sock to mptcp_subflow_init_cookie_req(), which writes to members of the larger struct mptcp_subflow_request_sock, so the writes can land in the next object of the slab. The fix used here is to drop the segment in cookie_bpf_check() if the listener is an MPTCP listener. This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch: a tc BPF program validating SYN cookies -- the one from the BPF selftests -- and an SO_REUSEPORT group with a TCP listener and an MPTCP one, the latter being selected. With KASAN, the original version of this patch reported: BUG: KASAN: slab-out-of-bounds in mptcp_subflow_init_cookie_req Write of size 1 at addr ... by task python3 mptcp_subflow_init_cookie_req cookie_bpf_check cookie_v4_check tcp_v4_do_rcv tcp_v4_rcv Without debug options, and with request sockets of half-open connections next to the corrupted one, the kernel panicked a second later, when the timer of a request socket fired: BUG: kernel NULL pointer dereference, address: 000000000000058f #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page Oops: Oops: 0000 [#1] SMP NOPTI CPU: 3 UID: 0 PID: 0 Comm: swapper/3 Not tainted 7.4.0-rc1+ #1 PREEMPT(la= zy) RIP: 0010:tcp_syn_ack_timeout+0xd/0x30 Call Trace: reqsk_timer_handler+0x22e/0x500 call_timer_fn+0x2a/0x140 __run_timers+0x1f7/0x280 run_timer_softirq+0x49/0xf0 handle_softirqs+0xfa/0x300 __irq_exit_rcu+0xb5/0xf0 sysvec_apic_timer_interrupt+0x73/0x80 Kernel panic - not syncing: Fatal exception in interrupt Fixes: e472f88891ab ("bpf: tcp: Support arbitrary SYN Cookie.") Signed-off-by: Chris Mason [ Shorter comment. Commit message: how the issue was found, and its symptoms. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/ipv4/syncookies.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 4e0ff3b82062..8433c856a7d8 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -308,7 +308,8 @@ struct request_sock *cookie_bpf_check(struct sock *sk, = struct sk_buff *skb) skb->sk =3D NULL; skb->destructor =3D NULL; =20 - if (cookie_tcp_reqsk_init(sk, skb, req)) { + /* reuseport can pick an MPTCP listener: req is too small for it */ + if (sk_is_mptcp(sk) || cookie_tcp_reqsk_init(sk, skb, req)) { reqsk_free(req); req =3D NULL; } --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599695; b=zQKbhWahdycs1hTLUxjDV9AlOmq8VI5b9+6+9bD/L+WLr8WJTZKh0A0GYwGMt3n/71et Ajn/TvKXj7QsdwoTXweXuBnS6zeMpdOb8kDrg6F1KpbKqZNzyUs3BBMg/cKhhyAiow5N9 +XpvmOPVNrcvTIEehgZhHN052lR0Tbs58OuoESyVkBhQ4nsXH1q53xMPBAJpAWweQx7lb PP+ajvizcpBeXj0IHuLjK4mV9VlBNSqXDEJo0lmE+qtDbtiRfQQYPf2ybU/7yiQGqwApt btix4VvXr8Ysb03kuqYYKq+yJVGHsIxJ5m8cf34OXSjQd66mVd6T3xTCvrpBHg3BcsQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599695; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=THxN1T4aANbFzmX1cuvclRlaxB/76WnQPGnh/XvBdBQ=; b=aXHxSuv8nBW+7KF/5sIGe524zTOdgX/cGm057wd53320zXOR4PrjKi8q7oxgBRAaBBUy YR3VHBY3x0Lzg3mMLK1DmyTkAjk6/WuuBKKFa9F+LcS5H37lEw+22BPr87N5qXxorGc2O uafHznp5y0QsU4OoLnagCwX4vHY3FGBbTTG9BPh87k//V+vdXNXdoOnk2vQw83nw0boMW g/i9qiqXEkRMzgfCzh9ILF/gIEqHr53rnstG8gLk6xY2Y9vE4/jWGsbayC5nD6EH0bB2N KAo/e/QrLCDfGCNt4iRUIxB6ro3cgyyu9h7I86pyXLQRzMVi2Ydb0rFL4vGkK2j6FlA== 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=a+VdbB3K; 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 76F7C60A3801 for ; Fri, 13 Nov 2026 19:54:55 +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=a+VdbB3K Received: by smtp.kernel.org (Postfix) with ESMTPSA id 977111F000C6; Fri, 13 Nov 2026 19:54:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599695; bh=THxN1T4aANbFzmX1cuvclRlaxB/76WnQPGnh/XvBdBQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=a+VdbB3Kp/OzjW1q48HPqvAYeFYPsv4j91XeAqGF6q2bk6Ad/aTep62QrmihkRI/3 1P4W1tQ8KJTBpBEU57KVAbNaX621Mr8BYjPiUvIOoFE3e6guCOv+1DX7f8NtvCxbVP zSWDAVEAAcZpx9CM4/mTYlglmgtJ/CESx09Xh/V5jYlsDp9t7pC8L1d3n3RHGXAGJo Qty48hN30RhMQ3XWPn8uoj4j0aVNnCiXoVyndWAzGgMzJORTrqDlS49ZGkImmVDRXw RC/dfIMQXchDRtM1EsPfElwUzD9vHO5MMJKANDpZextJOI1vdexYzdGX60dXrMne+q q9FUTtluOWfIw== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:54:06 +0100 Subject: [PATCH mptcp-net 28/34] mptcp: reclaim forward memory after coalescing skbs 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-28-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2957; i=matttbe@kernel.org; h=from:subject:message-id; bh=iNMKPU9f1mtAwb9m5EG4B3dJgQMqVdeOh6NRUwvXimQ=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Zz3b/D7m+fIr959E7D5x3WrLjQ+v9FIFzXU4LJr/z t2q8Kr9VUcpC4MYF4OsmCKLdFtk/sznVbwlXn4WMHNYmUCGMHBxCsBEqg8zMqw6Yam+N5dXyOSv SAALw+Q3pm83LJzxsefOM3Hez2ZJq+4z/FNbv0/vyErLk96PhDldtve1PBDJPBdi5FFtujL6sGT fKRYA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason If MPTCP sockets receive many small segments whose data stays queued, TCP can stall on the whole host, and an MPTCP server can be OOM killed in its memory cgroup, although almost no memory is in use. When the MPTCP socket (msk) takes over an skb from a subflow, mptcp_borrow_fwdmem() adds skb->truesize to the sk_forward_alloc of the msk, and the subflow reserves new memory for the next skb. Both sk_forward_alloc and sk_rmem_alloc count against tcp_mem and the memory cgroup, but only sk_rmem_alloc has a limit, sk_rcvbuf, so what queueing the skb does not move to sk_rmem_alloc has to be released. But mptcp_try_coalesce() moves only the increase in truesize of the skb that receives the data, and skb_condense() in mptcp_data_queue_ofo() can lower skb->truesize, so the rest piles up in sk_forward_alloc. The fix used here is to return every whole page of sk_forward_alloc with sk_mem_reclaim(), in mptcp_try_coalesce() once the merged skb is freed, and in mptcp_data_queue_ofo() once the skb is queued. This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch: a remote peer sends 33000 segments of one byte after a hole in the data sequence, which are merged in the out-of-order queue. Without this patch, the memory forward-allocated by the MPTCP socket -- msk_f -- grew with each merged segment, above 29 MB, versus 3200 bytes with it: SNAP label=3Dstage1-1-connections tcp_mem_pages=3D7168 [...] msk_f=3D2944= 5248 [...] [...] OFOQueue=3D33000 OFOMerge=3D32862 [...] With more connections, the original version of this patch reported that the TCP memory went above tcp_mem[2], stalling the other TCP connections, or that the memory cgroup went above its limit. Fixes: 9db5b3cec4ec ("mptcp: borrow forward memory from subflow") Signed-off-by: Chris Mason [ Shorter comment. Commit message: the rest of the borrowed amount has to be released + how the issue was found, and its symptoms. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 388e77da8f16..0758b048316e 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -197,6 +197,9 @@ static bool mptcp_try_coalesce(struct sock *sk, struct = sk_buff *to, sk_mem_charge(sk, delta); kfree_skb_partial(from, fragstolen); =20 + /* release what is left of the borrowed 'from' truesize */ + sk_mem_reclaim(sk); + return true; } =20 @@ -422,6 +425,9 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk= , struct sk_buff *skb) end: skb_condense(skb); skb_set_owner_r(skb, sk); + + /* skb_condense() can shrink the truesize borrowed from the subflow */ + sk_mem_reclaim(sk); } =20 static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offs= et, --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599696; b=kg9pBiZQX04sLc9balYRSlrscLEF1QVNZT00T/yvavYV1nLXICqKQL4RYJghRyYrpR2c n4uQKxl/TruidTK4PlaB00qdiOFhe6ssRIBveaCAsVTKkeAWoY1wBKWDLGsyKcg1lJmhU TAFwVas87RWSmALMeJW54x/OkHH1TE/JjbDkJtUdmgBwLQY7/bhy4pLXHhT9qcko0mEe6 x223v765bXx5LL2hK3r71O3pANep1Cb3vfZODlgUEwpcZfhFWtlG6h0P1TVuMv8hM+3sZ SS5vgtE0g7LNoxo8nzlSrA0mm7TRKaJcUdRUzhLFH6ahRCrlpu7BSre+hCWU+qpYUwA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599696; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=aQibswpO8WW2LKhoV6ATHchq0rYOGobJeP1nIzxnlag=; b=HUnCPea6Hv3/ri6Rj3XO8kfUYx6juJ8eLnB53ZobwkF9LQi9fS0yB189ICjejDq3cdui rHKpjYRB7/be/sH95Ehn46fZQkwzM2kMwOe32DWWJnD0lENRCyL8tc60T4xTF/oEqAIY1 386yL3AeKF7VyrYkiUInPER9it6QmS5zMAPAcXLrCILWjtEO76uqkQl7bnwdvFM0X3Ogr 5K3Yy1psJ2M4Hsl3fSr55cEHXLFfUxcb15MJNd1b3Vp5K/5q+oRbEqXYsipNnhCfVUgZD dC2uOu2qnNlQAAuDrjh5S3PGIPURi002cwZq8AG1paOaOGc1nlqGBo/5Ri+k6WwNkTA== 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=gQd1mKhv; 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 CD5B760A381A for ; Fri, 13 Nov 2026 19:54: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=gQd1mKhv Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5BD91F000C6; Fri, 13 Nov 2026 19:54:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599696; bh=aQibswpO8WW2LKhoV6ATHchq0rYOGobJeP1nIzxnlag=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=gQd1mKhvw1GKaoEK7zdXWS3F2Lz1ajv5rTmhClavWrnJvAPgO5o/gDti1MkBD9Fha nQ9VnU/ZAKVyfYoAzj0vVHc2EyRRNqiwFFKY0bh/4pN3z8aA0HEmkR3IZkypz2oevy A0ihcicyZHnjcVDp+qhhu2V2jdqsauIoxYROXZbcqyH8tD90hERK/POfRWtcQ5PdY7 V9NuIOI4/P8RDGwG42YlTizJ8Rqh8st6JCmAyLR0bf047dlRG8MJAQvoeUTWuwHUXF rn8QqPL9hSt6YLU6+T/c9CG+z3g4RBl8RY6MzqPtyGn59Jwl1UECXkW79kZLciMuBf T2ofhlSo3vFzA== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:54:07 +0100 Subject: [PATCH mptcp-net 29/34] mptcp: don't charge a shared page twice at accept() 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-29-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3722; i=matttbe@kernel.org; h=from:subject:message-id; bh=eYeiRS4brNkKxqTuSg5JfeOJF+43Io2WIr6z/uJjj+o=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Zz2fs2BV+8VZB7/+WVnicrvh+9PFSyJdniSqVVnJ/ +4vuFub31HKwiDGxSArpsgi3RaZP/N5FW+Jl58FzBxWJpAhDFycAjCRwM2MDKdNY/dyv3lsYa/m f/H9OpmiK2XKX5TW/+97/t62kdth81+GvyJVq27mP7z54V1p0I3VE/8/WXGke+6HI0rc4jxNU2+ t+MIJAA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason accept() of an MPTCP connection that has already received data can leak one page of memory cgroup charge, and the leaked charges can get the server OOM killed. At accept(), __inet_accept() charges the MPTCP socket (msk) for the memory that it holds, rounded up to whole pages, and mptcp_graft_subflows() does the same for each subflow. A page is uncharged only once, when the socket that holds it releases it, so rounding up each socket on its own is only correct while each page belongs to one socket. But for each skb that the msk takes over from a subflow, it borrows skb->truesize bytes from the pages that the subflow reserved, so the two can share a page: reserved by the subflow 4096 bytes 1 page now held by the msk 896 bytes charged for 1 page still held by the subflow 3200 bytes charged for 1 page The fix used here is to keep a running sum of what the msk and its subflows hold, and to let the new mptcp_charge_subflow() charge each subflow only for the pages that it adds to the rounded-up sum. This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch: an MPTCP server in a memory cgroup, the first byte of the client arriving before accept(). Without this patch, 4096 bytes stayed charged to the memory cgroup for each connection, after its end: SNAP label=3Dafter-1000 rounds=3D1000 sockets_left_in_srv=3D0 [...] c_soc= k=3D4096000 [...] SNAP label=3Dafter-5000 rounds=3D5000 sockets_left_in_srv=3D0 [...] c_soc= k=3D20480000 [...] With a memory limit, the original version of this patch reported that the server was killed by the OOM killer after about 14,400 connections. Fixes: 9db5b3cec4ec ("mptcp: borrow forward memory from subflow") Signed-off-by: Chris Mason [ Shorter comment. Commit message: how the issue was found, and its symptoms. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 0758b048316e..dd441e5aa435 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -4465,10 +4465,26 @@ static int mptcp_listen(struct socket *sock, int ba= cklog) return err; } =20 +/* The msk and its subflows share pages: charge their rounded-up sum */ +static int mptcp_charge_subflow(struct sock *sk, struct sock *ssk, int mem) +{ + int new_mem =3D mem + ssk->sk_forward_alloc + + atomic_read(&ssk->sk_rmem_alloc); + int amt =3D sk_mem_pages(new_mem) - sk_mem_pages(mem); + gfp_t gfp =3D GFP_KERNEL | __GFP_NOFAIL; + + mem_cgroup_sk_inherit(sk, ssk); + if (amt > 0) + mem_cgroup_sk_charge(ssk, amt, gfp); + kmem_cache_charge(ssk, gfp); + return new_mem; +} + static void mptcp_graft_subflows(struct sock *sk) { struct mptcp_subflow_context *subflow; struct mptcp_sock *msk =3D mptcp_sk(sk); + int mem; =20 if (mem_cgroup_sockets_enabled) { LIST_HEAD(join_list); @@ -4486,6 +4502,9 @@ static void mptcp_graft_subflows(struct sock *sk) __mptcp_flush_join_list(sk, &join_list); } =20 + /* What __inet_accept() just charged for the msk, before rounding up. */ + mem =3D sk->sk_forward_alloc + atomic_read(&sk->sk_rmem_alloc); + mptcp_for_each_subflow(msk, subflow) { struct sock *ssk =3D mptcp_subflow_tcp_sock(subflow); =20 @@ -4501,7 +4520,7 @@ static void mptcp_graft_subflows(struct sock *sk) goto unlock; =20 __mptcp_inherit_cgrp_data(sk, ssk); - __mptcp_inherit_memcg(sk, ssk, GFP_KERNEL); + mem =3D mptcp_charge_subflow(sk, ssk, mem); =20 unlock: release_sock(ssk); --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599697; b=As8aE7N1ZzlT52EttE6UVmuBaPerPzsQd+z946RLFXcgF0Vk4CXlkVBqXYx+0mwo09cm SDfwdYI8afOxdbAapzFG2sTTftBJQw/ISDcCAQjOA6NSNYRGN4Pxj2RjQrkuz9tISWjRW 8XdcQO1OYhJKmNEiuMY5hD7v6nP6lT1ISOqkCislDMu3B4E5hu6zMMWtrLR/Z4oiysNNr qbUUC78AOgxcAbHCfnXb5oNRIHufZcrFCK/VkUBfKMYOCyC+vAO61IXxk5B9CBvcsBYt7 AENP0Q9FsU7xxhmvXsxm9tyxZpZ1P+ECS+ELQjw6KTyG7RDZqErFWMYxIYBSAudQXGg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599697; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=H82IBm6DO/p1viyPZ1HA7TGUJwp1BkQgoerZpC941wM=; b=K7YsnUwHdZxP4bewmQrgPxdM7RbRolCiqY0GLm/9RTuuhjOAXSqfdit0Sx7bZQREkjQ6 aD3AxJctZJuCRwOec6P/E2M0ge5CTry5wptsjnLwU3q2zCp70ZszRVq2ZpLu3LT34veoq 3SangxOU1qtG81AxDSonO0b7dcisn57rmj45lFuTXFo/ymxyv7cB4RIPMLTde6xQag89g AX8+fG2cG5T+YJH5kDQR/y+MJfx0nRorEwtqcjfx4zwjmJlbXM7RpwZ5BysN2nkMJ/VQs z2I3my5zLn28dJFwN/lpnC6z5pjheEWlj9mDDDulz1ZSwlyQKckKOxODfF+TArIuODw== 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=GBWz6o6c; 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 CE57E606BCD8 for ; Fri, 13 Nov 2026 19:54:57 +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=GBWz6o6c Received: by smtp.kernel.org (Postfix) with ESMTPSA id D55801F000CC; Fri, 13 Nov 2026 19:54:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599697; bh=H82IBm6DO/p1viyPZ1HA7TGUJwp1BkQgoerZpC941wM=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=GBWz6o6cgGD2deKcQf+pI8POmqtt5JFZDRmsTyQUSeI/oIMlrMaz+Pip32aJk1oea JrA86zYOCzCSpv2NItJM86T5G07BY0aY0ZCr/xrpi6eASBy37Gyl8U0fLU/tX+xD9c c3IZxZ01iddch0V+q8egk4zf/uC7lA0nHmWsC1uEKm9u417tAOTyfgUDJU+MgUIZb8 M/+2MJuwdOfb7z4BBBrYO/FmD5yXnO6IB/6Qb4ARpVSqr3Rz30aPCNv+AbHuzL6tmF /Vsiv26gMCmoGHmTXe4Pg03cH4CkQALhKX4bGLpNUa/OgwV3Xf/MEBf0XTs4ICkiTJ qa9PIPjF4vzFA== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:54:08 +0100 Subject: [PATCH mptcp-net 30/34] mptcp: don't charge the backlog twice at accept() 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-30-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=5181; i=matttbe@kernel.org; h=from:subject:message-id; bh=e+ZCAH8Ga2HEasO5YB/yBUdYv5u1cJJ7E4hqjd550tQ=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Zz3fuDU+4d4Xjmu7OFSVdz55FJlT8N3gy4utJ2wOT KitTJg8t6OUhUGMi0FWTJFFui0yf+bzKt4SLz8LmDmsTCBDGLg4BWAi07MYGZpXL9V03rXT3qKq +vPNpi97GZnlGMq6LF+6r/8n6a9fdJaR4Y6nwL+OTn2LBZuLF9swP2/+yrP6+1d9uXABiXXfD++ cygcA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason accept() can permanently overcharge the memory cgroup of an MPTCP server, so the server can be OOM killed, if the new connection received data while its MPTCP socket was locked. The sockets of an MPTCP connection have no memory cgroup before accept(), which then charges the sk_forward_alloc and the sk_rmem_alloc of the MPTCP socket (msk) and of each subflow. mptcp_graft_subflows() also charges msk->backlog_unaccounted: the truesize of the skbs that __mptcp_add_backlog() queued while the socket lock of the msk was held and their subflow had no memory cgroup. But the first charge already covers each of these skbs that has not been freed, in the sk_rmem_alloc of its subflow or of the msk, so no later uncharge matches the extra charge. The fix used here is to remove msk->backlog_unaccounted, its charge in mptcp_graft_subflows() and the warning that tests it in mptcp_can_spool_backlog(). An RFC patch [1] removes the same lines, as part of another approach. This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch, on a kernel with the previous patch: 100,000 connections to an MPTCP server in a memory cgroup. Without this patch, about 63 MB stayed charged to this memory cgroup once all the connections were closed, and to its parent after its removal: SNAP label=3Dafter-100000 rounds=3D100000 sockets_left_in_srv=3D0 tcp_mem= _pages=3D0 [...] c_sock=3D63295488 [...] [...] SNAP label=3Dc-removed rounds=3D100000 sockets_left_in_srv=3D0 tcp_mem_pa= ges=3D0 c=3Dremoved [...] p_sock=3D63295488 [...] And about 12 MB with only 50 connections, each getting 20,000 duplicates of a byte before accept(), beside bare ACKs with RM_ADDR, which make the MPTCP worker take the socket lock: SNAP label=3Dafter-50 rounds=3D50 sockets_left_in_srv=3D0 tcp_mem_pages= =3D256 [...] c_sock=3D12881920 [...] Fixes: 6228efe0cc01 ("mptcp: leverage the backlog for RX packet processing") Link: https://lore.kernel.org/all/20260924080219.1036588-4-caixinchen1@huaw= ei.com/ [1] Signed-off-by: Chris Mason [ No comment change: the commit message explains why the backlog is covered. Commit message: refer to the RFC [1] removing the same lines + how the issue was found, and its symptoms. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 35 +---------------------------------- net/mptcp/protocol.h | 1 - 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index dd441e5aa435..2a47107001fc 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -798,12 +798,6 @@ static void __mptcp_add_backlog(struct sock *sk, =20 account: WRITE_ONCE(msk->backlog_len, msk->backlog_len + delta); - - /* Possibly not accept()ed yet, keep track of memory not CG - * accounted, mptcp_graft_subflows() will handle it. - */ - if (!mem_cgroup_from_sk(ssk)) - msk->backlog_unaccounted +=3D delta; } =20 static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk, @@ -2418,12 +2412,6 @@ static bool mptcp_can_spool_backlog(struct sock *sk,= struct list_head *skbs) { struct mptcp_sock *msk =3D mptcp_sk(sk); =20 - /* After CG initialization, subflows should never add skb before - * gaining the CG themself. - */ - DEBUG_NET_WARN_ON_ONCE(msk->backlog_unaccounted && sk->sk_socket && - mem_cgroup_from_sk(sk)); - if (list_empty(&msk->backlog_list)) return false; =20 @@ -4492,8 +4480,7 @@ static void mptcp_graft_subflows(struct sock *sk) /* Subflows joining after __inet_accept() will get the * mem CG properly initialized at mptcp_finish_join() time, * but subflows pending in join_list need explicit - * initialization before flushing `backlog_unaccounted` - * or MPTCP can later unexpectedly observe unaccounted memory. + * initialization by the loop below. */ mptcp_data_lock(sk); list_splice_init(&msk->join_list, &join_list); @@ -4525,26 +4512,6 @@ static void mptcp_graft_subflows(struct sock *sk) unlock: release_sock(ssk); } - - if (mem_cgroup_sk_enabled(sk)) { - gfp_t gfp =3D GFP_KERNEL | __GFP_NOFAIL; - int amt; - - /* Account the backlog memory; prior accept() is aware of - * fwd and rmem only. - */ - mptcp_data_lock(sk); - amt =3D sk_mem_pages(sk->sk_forward_alloc + - msk->backlog_unaccounted + - atomic_read(&sk->sk_rmem_alloc)) - - sk_mem_pages(sk->sk_forward_alloc + - atomic_read(&sk->sk_rmem_alloc)); - msk->backlog_unaccounted =3D 0; - mptcp_data_unlock(sk); - - if (amt) - mem_cgroup_sk_charge(sk, amt, gfp); - } } =20 static int mptcp_stream_accept(struct socket *sock, struct socket *newsock, diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index d76eaed4f01e..18222dd78fed 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -392,7 +392,6 @@ struct mptcp_sock { =20 struct list_head backlog_list; /* protected by the data lock */ u32 backlog_len; - u32 backlog_unaccounted; }; =20 #define mptcp_data_lock(sk) spin_lock_bh(&(sk)->sk_lock.slock) --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599698; b=o34k3sx7Yt+VCxp91wZIt3DCv0+5J5CGhPq4vxJYiB+H//WkRkD7iJr0ueMzKZpR2SZI KgylL1D4Ys66oeOuw7o8KCN4VEP0vgtte2U5gUziDUF3QiKOqDE/2uOHwEqJD8vlQdglk zACSqstOm10SX+7A1UmPst3OkbU0fZ+TaThFBurMa3MOuBABzlKabnFOGiKcSiFwcPqR7 aK0ydty+YGa9bstOAP9DZyWii7fjtSdRRXo0N/LsXOuI+s80Jfxt1IaefRqOixNP34dim dDPlR3f7DhG9M/AmrBSJ1w0gAyzJ6P+5WIOVtwo9PvmSPswkw+cPQERTdE4YygQMz0A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599698; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=UzQjT6pTdVhVgVD1x7jkIM/8s3GmfnVk1e/maolr/S4=; b=zcimel+20pN2S4u8DPbfy9AhgPjntW9VsMFciF9mN5NTmbCrvpgO7dmb2UV/OMGthl4F eFmJKZvh77z/UbVHoKpK0d9bzGV2mGZEDHsORrjv1jcMc13wktuXgstNFCYglDRHGKs7o +GoSryflHMC+dXnRbjAHi9eh+vTRr8yO2kEtjGI8ZeD8NPvwWUf6HzL9cRkR3vLC1AU8B Lzg/jRKU6lCYN3MD8sIibbw+STgTa5cNJJxXcFhfzghOAAa2kzMWic10Oeo0mJALln9uh yhlzs5J7pxprI0RShjS4mLnvaGxqejB7Pt0XeN2jj6+0i+I9Fk+s80m02KCwquDqIDQ== 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=LZzk5hIr; 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 DF5B5606BCD6 for ; Fri, 13 Nov 2026 19:54:58 +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=LZzk5hIr Received: by smtp.kernel.org (Postfix) with ESMTPSA id 047531F000C6; Fri, 13 Nov 2026 19:54:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599698; bh=UzQjT6pTdVhVgVD1x7jkIM/8s3GmfnVk1e/maolr/S4=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=LZzk5hIrwwmlJIKmFjmCUP7QcMAHykoLBloNEiJdUh+9QANOZrNX/OkIYPmjSowhm /KFCMbwSgK8YfxX+5dcjHzJcEhhHbPsNdFzK/tmrR9WpU5oM7ea1wOL3WRbh+C3zga XpgUROEnwiHXnbEOS6smISitXTk3HmD8e06v3iIoV5Hk8esYIu5VMp3crJ2Wbr0y6+ /sYDbptl+jkRDMIcTCnuWK5qvW735hXnFc7RzF5W1/1GxjRHHJJXXpkI0LI9bJ2G5E Q2du4mkk2LcerLvdie6+r9XP5kXHs7xVUjgqN+RDj6v1P6TUn6T3nxL3jotninabJK gZOCPZ652HF0w== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:54:09 +0100 Subject: [PATCH mptcp-net 31/34] mptcp: don't charge a subflow twice when it joins during accept() 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-31-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2598; i=matttbe@kernel.org; h=from:subject:message-id; bh=Me5+bq9iyzEOYaa3xqyQ24369zFmx5spOsiCZTXyQ5k=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z704dnOGwJ4Vu1JzFDztXvQ+7vA4rM15+GB46hQ+u 49/95yw7ihlYRDjYpAVU2SRbovMn/m8irfEy88CZg4rE8gQBi5OAZhI1ARGhjsTL+3KbZ/iFPLm 4Lt3B24WB5zclcFfwNe64KGUnGqmQzIjw3I70/sT+poM7omeftzBtkpF4faSH0o/uxP29ogkzuy I5gcA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 A subflow that joins an MPTCP connection while accept() runs can be charged twice to the memory cgroup of the server, for the memory that it already holds when accept() charges it. Nothing removes this extra charge. At accept(), __inet_accept() gives the MPTCP socket (msk) the memory cgroup of the caller, then sets its sk_socket. From then on, mptcp_finish_join() gives this memory cgroup to a joining subflow, via mptcp_sock_check_graft(), and each page that the subflow reserves is charged. Because accept() owns the msk, such a subflow is added to the join list, which mptcp_graft_subflows() moves to the subflow list before charging each subflow for the memory that it holds. A subflow that joined in between is then charged a second time for this memory, which will be uncharged only once. The window is short: from the end of __inet_accept() to the start of mptcp_graft_subflows(). And the extra charge is not zero only if data was received on the new subflow before mptcp_graft_subflows() gets to it, while a peer must not send data on it before the fourth ACK (RFC 8684, section 3.2). The fix used here is to skip, in mptcp_graft_subflows(), the subflows that already have a memory cgroup: they got it when they joined, and their memory has been charged since then. This issue has been found by an AI code review agent, while reviewing the code of the commit "mptcp: don't charge a shared page twice at accept()". It cannot be triggered on demand: the window is too narrow. It has been reproduced with a 500 ms sleep added after __inet_accept(), to widen it, and a Packetdrill script sending 1000 bytes on a subflow joining during accept(). Without this patch, a page stayed charged to the memory cgroup once all the sockets were freed, and none with it: memcg sock: 4096 bytes Fixes: 6228efe0cc01 ("mptcp: leverage the backlog for RX packet processing") Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 2a47107001fc..afc122e476cd 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -4503,7 +4503,8 @@ static void mptcp_graft_subflows(struct sock *sk) if (!ssk->sk_socket) mptcp_sock_graft(ssk, sk->sk_socket); =20 - if (!mem_cgroup_sk_enabled(sk)) + /* Got the memcg when joining: its memory is already charged */ + if (!mem_cgroup_sk_enabled(sk) || mem_cgroup_from_sk(ssk)) goto unlock; =20 __mptcp_inherit_cgrp_data(sk, ssk); --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599700; b=2+eyMIU5dgqhmswRBudg/XzNpKaRxbuWitcLVcT7uESfABFDWh0LlIvx5WmiCLbHH68P rxmTe8pV9gcKBKZcma1iXRh0O2VGLZs6UqZr4tCgcc8Ub0gglpA5LllztlnkG80FWghD9 Wh74GHJNoNTqZonr9Zqf6YOZPh+LC/UKSfuaz6ap2pSfqQAZs626WJEQY7sTfB9COCGxi qeXxO2FDaYbvatoAeNgw8MesUKL2JccnbANChnrHX+g+3mUjtG6vGqGvQ+F7jv2PPpdyZ dz8FY/fNxDK/MzQcW4EChcQJIO4Y/4DflKc5VCklsHhSS9Va3Lbki/7H5Y72E41j2Lg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599700; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=+YKFPhGuuIMzmC7OJ6WZULZD5l9ml7MWyBYCLPkG6sw=; b=nc4qmr23dL781nMnj8exsH2rPPHOWbJsfdX6JolvWak6KIQqR3FWldHV3sTNLEiSzacC ao4kstUhyuOgOAN9oQDX2VJTGl1xBnG/hDtncVdOIocEiK2SNBYtv8tbg+b1I4hUxYDxW 1zCWF7zOKygqnb5ShG9r90NDEZEeaZn6efPh/yVVjujCVORkK+OgETeQJeUKxQEUO0As8 wFiS3JuftWfSz7umPaxoPnZNe9Byz4z/4N4QgCnpDOwU/re202nhEu9kF+cHXDMhdEvcb 7gUJEswAEZjpMg0qJlSJKF+EbNc7IAXzf08qdYTU3PVdXtZwEGA7ShIa7nQj7jNGtbA== 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=mJxil700; 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 78FC8606BCEF for ; Fri, 13 Nov 2026 19:55:00 +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=mJxil700 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 235881F000C5; Fri, 13 Nov 2026 19:54:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599700; bh=+YKFPhGuuIMzmC7OJ6WZULZD5l9ml7MWyBYCLPkG6sw=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=mJxil700nab9oj2eghY1rMx7UTxfJeb6D6wH3jNoe6/iZ0xcL8VmggXIXQpQEspAb TDzaEGlic1P9pA93nsNqTG4sdCmPi8FhLQWm4vqPftJjaeKA3H8grNc5Xg4BORTRQy eqWVo8o9rN/OCP/9UxfJrOHL94Oz5v7RqauMqAH3WgaDubZGmSb/WWBYUBbGsJbpsU MMkiNqGvnjEFDn0G4EW+B2vZwidWmDoQv3UiZ2yt3brtLdH4ZAcczcFsYkTZDaG5Tw 0cBkHwA9Uh6blhe21YXE7IOIYRLirhgbQxBiP1U21wmZgtU++PxCByHsfuCpdWffgW tDrRbFEinI4kA== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:54:10 +0100 Subject: [PATCH mptcp-net 32/34] mptcp: fix dummy mapping of overlapping segments 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-32-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" , Geliang Tang X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3818; i=matttbe@kernel.org; h=from:subject:message-id; bh=0QRk4oktO2Az9k/hwN8yJquspyusBd9NOF1vxmLcViM=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z70si93hs9BGyWPZzj0VbRIvImyfmDZ75v4OKHh4S nXZtt2mHaUsDGJcDLJiiizSbZH5M59X8ZZ4+VnAzGFlAhnCwMUpABfJY/jD/2f2wn+v1Bt0/rmr zDUzFn5wqz3p9UrHKuOos289Qw6WMPyzur7qkZzm5A0yNeXnxEW+b67T3lLXsHG7z/vW9nU7pDh YAA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang An MPTCP socket that has fallen back to TCP can silently lose received data if a segment partly overlaps data received earlier, and recv() then blocks, returning neither later data nor end of file. After a fallback, subflow_check_data_avail() makes up a dummy mapping for the skb at the head of the subflow's receive queue, in which map_seq and map_subflow_seq must describe the same byte. But since commit 2834f8edd74d ("mptcp: cleanup fallback dummy mapping generation"), it computes map_seq from the first byte of the skb, while map_subflow_seq is still computed from copied_seq, the next unread byte. mptcp_subflow_get_mapped_dsn() then returns the data sequence number (DSN) of the first byte of the skb, instead of the one of copied_seq. These two bytes differ for a segment that starts before rcv_nxt and ends after it, since TCP does not trim it. mptcp_init_skb() then gives the new bytes of this skb a DSN that is too low, and __mptcp_move_skb() skips some of them as old data, leaving a hole in the stream: bytes 0 to 999 are received, the skb holds bytes 900 to 1499 byte 1000 gets the DSN of byte 900: too low by the 100 old bytes that is 100 below ack_seq, the next DSN that MPTCP expects __mptcp_move_skb() skips bytes 1000 to 1099 as old data ack_seq is the DSN of byte 1400, copied_seq is byte 1500 later data starts at the DSN of byte 1500: out of order the TCP FIN becomes a dummy DATA_FIN after the last byte ack_seq does not reach it, so there is no end of file Fix this by computing map_subflow_seq from the first byte of the skb as well: mptcp_subflow_get_mapped_dsn() then returns the DSN of copied_seq. Chris Mason sent the same fix in private, and found this issue with the help of an LLM. It has been reproduced in a VM, with the reproducer he shared, and with a new Packetdrill test: after a fallback to TCP, a segment overlapping data already received is injected. Without this patch, the new bytes at the beginning of this segment were lost, and the connection stalled, with no end of file: reader 30.64: conn 1 BREAK: at my offset 1000 the bytes claim offset 11= 00: A GAP OF 100 BYTES reader 30.64: READ-TOTAL conn 1 outcome iii-gap-or-repeat bytes 1400 of= 2500 [...] [...] end: hang: no data and no end of file for 30 s And with the Packetdrill test: dss_fallback_overlap_client.pkt:24: runtime error in read call: Expected = result 2500 but got 1400 with errno 115 (Operation now in progress) Fixes: 2834f8edd74d ("mptcp: cleanup fallback dummy mapping generation") Link: https://lore.kernel.org/4c48d016490d43b6892c622cbae858b48f176cff.1794= 304840.git.tanggeliang@kylinos.cn [1] Co-developed-by: Chris Mason Signed-off-by: Chris Mason Signed-off-by: Geliang Tang [ Combine the commit messages of Geliang's [1] and Chris's versions. Commit message: how the issue was found, and its symptoms. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/subflow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 543368cfc890..64e8f5c36415 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -1526,7 +1526,7 @@ static bool subflow_check_data_avail(struct sock *ssk) skb =3D skb_peek(&ssk->sk_receive_queue); subflow->map_valid =3D 1; subflow->map_data_len =3D skb->len; - subflow->map_subflow_seq =3D tcp_sk(ssk)->copied_seq - subflow->ssn_offse= t; + subflow->map_subflow_seq =3D TCP_SKB_CB(skb)->seq - subflow->ssn_offset; subflow->map_seq =3D __mptcp_expand_seq(subflow->map_seq, subflow->iasn + TCP_SKB_CB(skb)->seq - --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599701; b=kSQERUHVey1CV6Uz6VsW+bHeNUN1B+QbzgHj6+7V6fpneSmGWc0Wbc5gWM+ueIooslL4 54vqSrnuyVkpg69VLo1SJQnAA2LsuOSQzBqSWaJ7fGylmQHziHMnYR7yb79y5FlNMMzGy xamkFBQinroCdK4Pilwg1WKmu1zgigV5T2o+WRlwI7MkFViZqxO8K356I1VE9YXKeiDDz qyopzKwvK23ZHoFtn/0NTx6+EIYVAe2mUX+MuiDxAPuhg0EYrQCXzxE7bfYiU9FRr1G+7 8JlCBVDbDHq758hxYpAXkwKSEsExIwkivdoWPekp5Ij+NLWkIM96WmR9aa0A+oEYo3g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599701; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=4tW2S835loq7Wl7i1dtmVg485j77mIPCe+v47v3nVHw=; b=GouKe7aHNWIZ2uBc9n5Vu3k4nahemHQk+gJAvUQqnRxVKmT2EaFCYsmEDy4ztpozZv64 IHUNw/kdaEGsLLviDo50E4Tjlna0861ukkMZdlaMY2dpW1B/KaJwbPNUrcVxc4xaPNMPS WeLxTgJdo7aORUadALUgUlg7nbmOe4xERAdupl9NdUgsw5gNBFJd57q1CzPgqelL8X383 e7YEZKPW4ES9YWnGb4abkIvZRHWjxEOh4MSAcNhca38MqnatU5AwqxtbQstYl9j01aaus qifggEFvdrTa9oeYI5laBnKBZD0rl/YGMUz3a2PTml6G/67qC6hN74yD0WGiISLVfNQ== 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="NqxaN/yp"; 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 50DB0606BCE8 for ; Fri, 13 Nov 2026 19:55:01 +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=NqxaN/yp Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6922D1F000C7; Fri, 13 Nov 2026 19:55:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599701; bh=4tW2S835loq7Wl7i1dtmVg485j77mIPCe+v47v3nVHw=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=NqxaN/yp9IT0fl3cJf0k1rlFmxxN1mfghvaJNgj8xG+N1UJkWmNHMran35Q36mcy2 AfiVMXCO5MS26y+21DQvHphGh065tA1wVaV+j3nOqYO2OFyp9Y5dU+K4ChagQicYdE ilXPeUwVEPCx0lTcLz70KsXAJrjN/Lo4LVdj9UFdU6F6QHoczpAtwU+UEq8AcfWw8X y8z1xJ5vWjKcPse1IccFE0muH5RoV/WdQiwEirEcUl53HN66gwt4RIWOjTtcb5ZuTU 6xT6M6eu85k9TzlkpPS1G9/E7RZ5I/xHLtCNv1OUlayO9swnGGQ39AD7XMoS0rSHCt kKXiK296HR2yg== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:54:11 +0100 Subject: [PATCH mptcp-net 33/34] mptcp: continue the last mapping after a fallback 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-33-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=7098; i=matttbe@kernel.org; h=from:subject:message-id; bh=oGSx4xgFBLKeRtjHSptsuqQYOFhNbd+CsQ+BTOkQmMk=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z71K3PFxlXrOCe9TCSa79dTKcu7HV12eMFv61dNjp 5xjWtmPdpSyMIhxMciKKbJIt0Xmz3xexVvi5WcBM4eVCWQIAxenAEwk9zTDH172R/Ex3vW+YVUZ Ppf8t051Ffx7uf+SmOKzowd8m3P8Ghn+e2gtyDvcaLzdtXe1wBIrObcfz5pZ5D0rT0RfE4npVWD jAgA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Chris Mason An established MPTCP connection that falls back to TCP after a zero window probe or a reinjection can stall in one direction, so that recv() returns neither the remaining data nor end of file. After a fallback, subflow_check_data_avail() gives each skb a dummy mapping, at the data sequence number (DSN) iasn + SSN - 1, where iasn is the DSN of the peer's first byte and SSN is the subflow sequence number. This is right only as long as DSNs and SSNs advance together, but a zero window probe or a reinjection maps old data a second time, which takes new SSNs and no new DSN. Each later dummy mapping is then too high, so __mptcp_move_skb() treats all further data as out of order: data SSN 1 to 1000 DSN iasn to iasn + 999 probe SSN 1001 DSN iasn + 999, dropped ack_seq iasn + 1000, the next DSN expected dummy SSN 1002 DSN iasn + 1001 The fix used here is to: - keep in the new member dsn_base of the subflow context the first DSN of the peer's last mapping, minus its first SSN, plus 1 - compute the DSN of a dummy mapping as dsn_base + SSN - 1 - keep in the new member dsn_end the highest end of a mapping of the peer so far - make mptcp_try_fallback() fail while the peer's last mapping ends below dsn_end, so that the caller resets the subflow 32 bits are enough for both: the dummy mapping only takes the lower 32 bits of its DSN, see __mptcp_expand_seq(), and the end of a mapping stays within a window of dsn_end. One case is left: if only the receiver falls back after a zero window probe or a reinjection, it now delivers the first MPTCP-level retransmission of data that was new when first sent, as new data, before the sender resets the subflow, see "mptcp: stop resending data to a peer that fell back". Without this patch, the receiver stalled instead. This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer shared with the original version of this patch, and with a new Packetdrill test: between two unmodified Linux hosts, nftables removing the MPTCP options after a zero window probe, a DSS checksum failure, or a failed MP_JOIN. Without this patch, the reader stalled for good, the data staying in the out-of-order queue: receiver 22.764: READ-TOTAL outcome ii-right-so-far-then-nothing bytes 2= 670592 of 8388608 [...] [...] end: hang: no data and no end of file for 20 s RESULT [...] R: DssFallback=3D1 [...] OFOQueue=3D204 NoDSSInWindow=3D145 = [...] And with the Packetdrill test: dss_fallback_after_probe_server.pkt:25: runtime error in read call: Expec= ted result 2000 but got 1000 with errno 22 (Invalid argument) Fixes: 2834f8edd74d ("mptcp: cleanup fallback dummy mapping generation") Signed-off-by: Chris Mason [ dsn_base and dsn_end on 32 bits: struct mptcp_subflow_context grows by 8 bytes instead of 16, and lent_mem_frag stays in the same cacheline. Shorter comments. Moved after "mptcp: stop resending data to a peer that fell back": alone, this patch turns a stall into data delivered twice, when only the receiver falls back after a probe or a reinjection. Commit message: mention the remaining case + how the issue was found, and its symptoms. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.h | 9 ++++++++- net/mptcp/subflow.c | 21 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 18222dd78fed..f0b93c31b16e 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -578,6 +578,8 @@ struct mptcp_subflow_context { __wsum map_data_csum; u32 map_csum_len; u32 prev_rtt_seq; + u32 dsn_base; /* MPC: DSN - SSN + 1 of peer's last map */ + u32 dsn_end; /* MPC: highest end of the peer's maps */ u32 request_mptcp : 1, /* send MP_CAPABLE */ request_join : 1, /* send MP_JOIN */ request_bkup : 1, @@ -602,7 +604,8 @@ struct mptcp_subflow_context { mpc_drop : 1, /* the MPC option has been dropped in a rtx */ resetting : 1, /* subflow is resetting */ old_data_pending : 1, /* old data not acked with MPTCP opts */ - __unused : 8; + map_old : 1, /* MPC: peer's last map is below dsn_end */ + __unused : 7; bool data_avail; bool scheduled; bool pm_listener; /* a listener managed by the kernel PM? */ @@ -1332,6 +1335,10 @@ static inline bool mptcp_try_fallback(struct sock *s= sk, int fb_mib) =20 msk =3D mptcp_sk(sk); =20 + /* the peer might still be resending old data */ + if (subflow->map_old && !__mptcp_check_fallback(msk)) + return false; + /* queued old data would be sent without mapping after a fallback */ if (subflow->old_data_pending && !__mptcp_check_fallback(msk)) return false; diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 64e8f5c36415..728b27be1ad0 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -540,6 +540,8 @@ static void subflow_set_remote_key(struct mptcp_sock *m= sk, =20 /* for fallback's sake */ subflow->map_seq =3D subflow->iasn; + subflow->dsn_base =3D subflow->iasn; + subflow->dsn_end =3D subflow->iasn; =20 WRITE_ONCE(msk->remote_key, subflow->remote_key); WRITE_ONCE(msk->ack_seq, subflow->iasn); @@ -1434,6 +1436,17 @@ static bool mptcp_subflow_fail(struct mptcp_sock *ms= k, struct sock *ssk) return true; } =20 +/* Fallback: dummy maps go on from the last valid one, unless it is old */ +static void subflow_update_dsn_base(struct mptcp_subflow_context *subflow) +{ + u32 end =3D subflow->map_seq + subflow->map_data_len; + + subflow->dsn_base =3D subflow->map_seq - subflow->map_subflow_seq + 1; + subflow->map_old =3D before(end, subflow->dsn_end); + if (!subflow->map_old) + subflow->dsn_end =3D end; +} + static bool subflow_check_data_avail(struct sock *ssk) { struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); @@ -1467,6 +1480,8 @@ static bool subflow_check_data_avail(struct sock *ssk) if (unlikely(!READ_ONCE(msk->can_ack))) goto fallback; =20 + subflow_update_dsn_base(subflow); + old_ack =3D READ_ONCE(msk->ack_seq); ack_seq =3D mptcp_subflow_get_mapped_dsn(subflow); pr_debug("msk ack_seq=3D%llx subflow ack_seq=3D%llx\n", old_ack, @@ -1497,6 +1512,7 @@ static bool subflow_check_data_avail(struct sock *ssk) subflow->reset_reason =3D MPTCP_RST_EMIDDLEBOX; goto reset; } + subflow_update_dsn_base(subflow); WRITE_ONCE(subflow->data_avail, true); return true; } @@ -1528,9 +1544,8 @@ static bool subflow_check_data_avail(struct sock *ssk) subflow->map_data_len =3D skb->len; subflow->map_subflow_seq =3D TCP_SKB_CB(skb)->seq - subflow->ssn_offset; subflow->map_seq =3D __mptcp_expand_seq(subflow->map_seq, - subflow->iasn + - TCP_SKB_CB(skb)->seq - - subflow->ssn_offset - 1); + subflow->dsn_base + + subflow->map_subflow_seq - 1); WRITE_ONCE(subflow->data_avail, true); return true; } --=20 2.55.0 From nobody Mon Nov 23 20:27:01 2026 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=1794599702; b=JCZP0BvZKXR8Ysxfsb/Hi7LSc1Kh4nrJGEynd6l6l2lXHDDyBVCpfo0M1yj1gwV3FB0f 1EmhAjuO5XaizlGs/LID+zYZpyB+AkBaBvMndMlcsm9nJ5tnxrOQARLFOnwDJWk9CSXqL 0ipp8H3+LegNNbfSN3PbjICSDJTf1FMSG38VUlGBLqkpnk/MJ+x9VgA7C1uR9EsdGT9KR CyYV/YdEL1PD7+A+Ti4vqSg2MRaK6kJW5orqZsvJBtt/3fmr93Gk4Vo3jIXl+9uGAIpn2 x6T5WxIwhy2DEHcr3baGWsrhNnQbiC7R9wDnnItw5gV448WhfKxopWI118DDQ+ClnGQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794599702; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=pqCJR/YB4QEUGRx9TZbdxFYPz4oF6qjROWr/evWSeIM=; b=D2UsrrBRHOePJg6IxfUF0YWzsNwtbeqiLL+KT1DVkZCjDkwegABfW7uXBE/84zcHnzMg 5vmDj+VIMp9aO25xhW6BtfA8kwkxADEEByFnf7nKsYebp3MjtgTm/H5m/zeg4TYMMQnS6 j2qHhFYWtWBAh0ooj0wfOkHjWJsuABNEsOxq5LI5Oe8hiRn/QSAHBAezmbrJ82s98wAOj bOwd6ufq+mK2g7ep68ND5URsZNpjUPp01kBVCwk2IL4V1G9x9pzYAoWQ1hNDgiBykSS1v 1G5DAjL9lFJWgJVJSTXmKjmm0/UZKM/jWjgKo1Om0LDZGaK0hQ7kyVpWGAshciA7D/Q== 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=mg+H+M+U; 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 7C745606BCDE for ; Fri, 13 Nov 2026 19:55:02 +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=mg+H+M+U Received: by smtp.kernel.org (Postfix) with ESMTPSA id 880381F000C5; Fri, 13 Nov 2026 19:55:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794599702; bh=pqCJR/YB4QEUGRx9TZbdxFYPz4oF6qjROWr/evWSeIM=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=mg+H+M+UMYjOwD525kH2jNRyhNiug1ZEOwlloIDstgrbSykhPh2Ccd/k6/P6Kca2Z YIRrseLqB4yjAQR2+EEvqeWPGU/neThs8+SEWknfz6zAQ7M6MOBJDEl4PWEx04oYwW 1pZYwqfhJ1UjI84Jm31ff+9MCl2uT3FUbq5P9mlltyiCRDBnnhgaYM9cUl/bue739A /qZI8TRMKxuaScr/LASj0eafkUGlsmdFGbU1W1NmEJRXIVxhGQEZZeazVZgl6f0u17 Olp18bw4oS5Vxux1tLi9LCulD2J8cJ1IcG4Sdk8SBpeMVM+XR6oGE3P8UIffFJkZQF eTiN7SNKGMpSA== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Nov 2026 20:54:12 +0100 Subject: [PATCH RFC mptcp-next mptcp-net 34/34] mptcp: reset when the DSS disappears after a DATA_ACK 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-mptcp-cmason-fixes-v1-34-9205b77e9a2f@kernel.org> References: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> In-Reply-To: <20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org> To: MPTCP Linux Cc: Chris Mason , Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=7176; i=matttbe@kernel.org; h=from:subject:message-id; bh=6t2iomXzM8pmkeOteBrBXdcJQNsYEX+nNmLMGt1qr1s=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLK+Z736rvU6gLn24pw9reyNGkysJtsTY75at0epFm/x5 lo3kSuio5SFQYyLQVZMkUW6LTJ/5vMq3hIvPwuYOaxMIEMYuDgFYCKbChn+x5UWlOzxm3N0z4TJ Tn7HftoULOldJuV+55Pvx8vf0lsOrWX4p676btPl8AT18oumT+yOpxYwivlwsep8O8yzaovbmv8 NvAA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 RFC 8684, section 3.7, describes a fallback to TCP for the case where the MPTCP options get through on the SYN, but not on the next packets. A sender includes a DSS option in each segment "until one of the sent segments has been acknowledged with a DSS option containing a Data ACK": it then has "the confirmation that the DSS option passes in both directions". After that, a subflow that loses its MPTCP options "SHOULD be treated as broken and closed with a RST", with the "Middlebox interference" reason. It's a *SHOULD*. Commit 119d51e225fe ("mptcp: fallback when MPTCP opts are dropped after 1st data") did this fallback as long as allow_infinite_fallback is set, i.e. also after this confirmation, and left the check of the DATA_ACK for later [1]. Such a late fallback is fragile: the peer might still resend data that was mapped before, or a zero window probe might have mapped old data again. The previous commits "mptcp: do not fallback while old data is in flight", "mptcp: stop resending data to a peer that fell back" and "mptcp: continue the last mapping after a fallback" handle these cases, except one: if only the receiver falls back, it can deliver the first MPTCP-level retransmission of the sender as new data, before the sender resets the subflow. Yeah, a very specific corner case. Now, when data without DSS is found on a subflow, the subflow is reset if a DATA_ACK received on it acknowledged data that had been sent: the MPTCP options then passed in both directions. Except after an MP_FAIL exchange: a fallback to TCP is then in progress, so data without DSS is expected, even if the infinite mapping has not been seen. This also closes the case above, but only for a receiver whose data has been acknowledged. Receiving a DATA_ACK is not enough: when the MPTCP options are only dropped in one direction, the peer can fall back while the DATA_ACKs it sent before acknowledged no data. A client that is not fully established falls back when a packet from the server has no MPTCP options, e.g. an ACK of its data, and the other hosts when they receive data without DSS. Except after an MP_FAIL, Linux falls back without sending an infinite mapping, then sends data without DSS: the other side can only fall back too, as before. For the same reason, the amount of received data -- e.g. more than an initial window -- is not used. When a middlebox starts dropping the MPTCP options in the middle of a connection, after a DATA_ACK acknowledged data, the subflow is then reset, instead of falling back to TCP when it was safe. If it was the only subflow, the MPTCP connection stays without subflow until the close timeout -- 60 seconds by default, see net.mptcp.close_timeout -- unless a new one is created in between. A new Packetdrill test checks this reset. Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/519 [1] Signed-off-by: Matthieu Baerts (NGI0) --- Note: this commit changes the behaviour, it is for next. It fixes a very specific corner case (but it follows what the RFC 8684 recommends to do) but for that it needs an extra flag and more checks. Is it worth it? (I think so, but that's why it is flagged as RFC.) --- net/mptcp/options.c | 11 +++++++---- net/mptcp/protocol.h | 3 ++- net/mptcp/subflow.c | 20 +++++++++++++++++++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index c56ca5e4df14..ccd30e110934 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -1128,7 +1128,7 @@ static void rwin_update(struct mptcp_sock *msk, struc= t sock *ssk, subflow->rcv_wnd_sent =3D mptcp_rcv_wnd; } =20 -static void ack_update_msk(struct mptcp_sock *msk, +static bool ack_update_msk(struct mptcp_sock *msk, struct sock *ssk, const struct sk_buff *skb, struct mptcp_options_received *mp_opt) @@ -1137,6 +1137,7 @@ static void ack_update_msk(struct mptcp_sock *msk, u32 win =3D ntohs(tcp_hdr(skb)->window); struct sock *sk =3D (struct sock *)msk; u64 snd_nxt; + bool acked; =20 mptcp_data_lock(sk); =20 @@ -1169,7 +1170,8 @@ static void ack_update_msk(struct mptcp_sock *msk, if (after64(msk->wnd_end, snd_nxt)) __mptcp_check_push(sk, ssk); =20 - if (after64(new_snd_una, old_snd_una)) { + acked =3D after64(new_snd_una, old_snd_una); + if (acked) { __mptcp_snd_una_update(msk, new_snd_una); __mptcp_data_acked(sk); } @@ -1179,6 +1181,7 @@ static void ack_update_msk(struct mptcp_sock *msk, trace_ack_update_msk(mp_opt->data_ack, old_snd_una, new_snd_una, new_wnd_end, READ_ONCE(msk->wnd_end)); + return acked; } =20 bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, b= ool use_64bit) @@ -1335,8 +1338,8 @@ bool mptcp_incoming_options(struct sock *sk, struct s= k_buff *skb) /* we can't wait for recvmsg() to update the ack_seq, otherwise * monodirectional flows will stuck */ - if (mp_opt.use_ack) - ack_update_msk(msk, sk, skb, &mp_opt); + if (mp_opt.use_ack && ack_update_msk(msk, sk, skb, &mp_opt)) + subflow->dss_confirmed =3D 1; /* MPTCP opts pass both ways */ rwin_update(msk, sk, skb); =20 /* Zero-data-length packets are dropped by the caller and not diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index f0b93c31b16e..36121de59ab9 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -605,7 +605,8 @@ struct mptcp_subflow_context { resetting : 1, /* subflow is resetting */ old_data_pending : 1, /* old data not acked with MPTCP opts */ map_old : 1, /* MPC: peer's last map is below dsn_end */ - __unused : 7; + dss_confirmed : 1, /* a DATA_ACK acked our data */ + __unused : 6; bool data_avail; bool scheduled; bool pm_listener; /* a listener managed by the kernel PM? */ diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 728b27be1ad0..68a9fe29a5e8 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -1447,6 +1447,22 @@ static void subflow_update_dsn_base(struct mptcp_sub= flow_context *subflow) subflow->dsn_end =3D end; } =20 +/* RFC 8684, 3.7: no fallback once a DATA_ACK acked our data, except MP_FA= IL */ +static bool subflow_nodss_is_fatal(struct mptcp_sock *msk, + const struct mptcp_subflow_context *subflow) +{ + bool fatal; + + if (!subflow->dss_confirmed) + return false; + + /* before a fallback, only an MP_FAIL clears allow_subflows */ + spin_lock_bh(&msk->fallback_lock); + fatal =3D msk->allow_subflows; + spin_unlock_bh(&msk->fallback_lock); + return fatal; +} + static bool subflow_check_data_avail(struct sock *ssk) { struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); @@ -1517,7 +1533,9 @@ static bool subflow_check_data_avail(struct sock *ssk) return true; } =20 - if (!mptcp_try_fallback(ssk, MPTCP_MIB_DSSFALLBACK)) { + if ((status =3D=3D MAPPING_NODSS && + subflow_nodss_is_fatal(msk, subflow)) || + !mptcp_try_fallback(ssk, MPTCP_MIB_DSSFALLBACK)) { /* fatal protocol error, reset the subflow and let the * worker close it */ --=20 2.55.0