From nobody Mon Nov 23 20:27:02 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=1795440328; b=E+pvSo3MhXndsHE+9ICKQ/4ZBmFGqil2bKrbNyDjSgl+dfGJKCwDWczNFAy2ju9oozt6 FjJpNYU5YhqMQ3QxS9f5//w083I8cr7/r1lMtcxfgF63Z/Qnv7fsW++Prz4+Cj5UByxLM UUezXb8aUYNQ+5Q7gEbW9eO76cZF4+nSPQlBBdftWG1tPKPe0rfOYK2E5sjPgFm1Ah1gN sDcgbS6ZPf2K0+iHKvxqVpW2KzeGZQDLkUMCaDs8OszjLwV0++yJif/K+58ZOjf7mBDak f3E3nPxbGXbBpY/nY2FhTHe77DawhBjSl0pweev8OSwAJ58o+LFfEtLC3ueT5zQ9rFw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795440328; 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=6R0zS6N172iECvWqZi/RpO1fp5+dWMwp4TBDt1rOy7s=; b=5gOS2EIvEIpLjcOnrIRf5NGeku7zH2vhDQ8iLPW120oi5OxJo3yaHdSfKG8G017QOXuU r4skZMSZ4eRTgCqEcmMcJ57cQ0WOkd1lQk+kLU+6bNVBWVKwgOpORGuyMg4gm3Ys2dCw0 uT7KgqPL0tcLIZqSdhFGM8gA7H9jgyX0xBTxx9s+ZcjAaf1aEsLbvK3UdFslSbhH0pVm8 sWJuH+TunKIr3brlpt326DqPIDCYT8UVQMrMBRaM1ThjT+AUowGmkz+p+FpqkoDO89aYz aQ5TsekgvOR+hfllY3ON5ADinUZjn7cFuBhPw2AvBnw1PL1cWyX6wYYezxn74yKiWfg== 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=UEDwx3+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 0EB19606A31E; Mon, 23 Nov 2026 13:25: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=UEDwx3+u Received: by smtp.kernel.org (Postfix) with ESMTPSA id 844C81F000C0; Mon, 23 Nov 2026 13:25:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795440327; bh=6R0zS6N172iECvWqZi/RpO1fp5+dWMwp4TBDt1rOy7s=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=UEDwx3+uNiHMUL4GO+K4dqiEN0B6XHou27kEd5w84rx8hnSsoSGKvY9Me7j01NG3w 8zNkBG2nEmVECvJ95ohI0fiqpXmGxeLe3mTf9xmJP6I4jRVNvJXw2SviBPuStQMSqy ahyfPtC/0U+qNIoeFOaowGeCwZVhUQ1UA48+dy54MJ20ZuGru9dgseCk8R8m8oOZMB HhrZisbYfr7PvY6xoAYNudBRcxJ4j7P/oR92cdpQqr55kqOVml+Aj8tyQ1x9AF9N9p woo1wTprHvY/8zbhz36YQYasIu+ITRuZ9EsitXT4IZfg/SRjxuNvXyywvFSuskgxtu 4r3CoycoOjDmQ== From: "Matthieu Baerts (NGI0)" Date: Mon, 23 Nov 2026 14:24:49 +0100 Subject: [PATCH net 01/10] 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: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-1-278042217e8d@kernel.org> References: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> In-Reply-To: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> To: Eric Dumazet , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Mat Martineau , Geliang Tang , Christoph Paasch , Florian Westphal Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, Davide Caratti , "Matthieu Baerts (NGI0)" , Chris Mason , stable@vger.kernel.org, Neal Cardwell , Kuniyuki Iwashima X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3626; i=matttbe@kernel.org; h=from:subject:message-id; bh=KnhMwAMfUYPYaDgdpX1a2kmd2Cm5s4SvnOfH/+Eo+Og=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLJZ7HYkGLsnnXU/4BrlKNnWGdxxTmhh1ZzQQ/tOqRtHv 5Xd8Seno5SFQYyLQVZMkUW6LTJ/5vMq3hIvPwuYOaxMIEMYuDgFYCLu8xgZ/hueWrSIXWsHJ9M2 3kmCXIq3rfsrmCdcC2yL+7vdXpL/AMN/r5gK3jLDz5rf57xxfSzM37jjlQ33x6rMIwxSwVdtPh7 kAAA= 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 sets TCP_CLOSE again, then purges the Fast Open RST queue since commit 342e62fd34c2 ("tcp: purge Fast Open RST queue when listen() fails"), but not the accept queue. 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, with their new child. These entries, and the sockets that they hold, are never freed, since close() drains this queue only in TCP_LISTEN and the next listen() stores NULL in rskq_accept_head. The fix used here is to call inet_csk_listen_stop() after the error path sets TCP_CLOSE, which also purges the RST queue, except for an MPTCP subflow, which needs mptcp_subflow_queue_clean() first: only its RST queue is purged here, and mptcp_listen() has to drain its accept queue, 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, 2535 left. Sockets: 33373 made, 5070 l= eft [...] result: namespaces: 1000 made, 694 taken down, 306 left Fixes: 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table") Cc: stable@vger.kernel.org Signed-off-by: Chris Mason [ Shorter comments. Commit message: how the issue was found, and its symptoms. On top of commit 342e62fd34c2, with a Fixes tag for the accept queue. ] Signed-off-by: Matthieu Baerts (NGI0) --- Cc: Neal Cardwell Cc: Kuniyuki Iwashima --- net/ipv4/inet_connection_sock.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_soc= k.c index 9a3b05edb62b..2e27b3e592a8 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1382,8 +1382,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); @@ -1401,9 +1401,13 @@ int inet_csk_listen_start(struct sock *sk) =20 /* A Fast Open child accepted before a previous shutdown() of this * listener might have queued its request in rskq_rst_head while - * we were transiently in TCP_LISTEN state. + * we were transiently in TCP_LISTEN state. The accept queue of an + * MPTCP subflow is drained by mptcp_listen(). */ - reqsk_fastopen_purge_rst(&icsk->icsk_accept_queue); + if (sk_is_mptcp(sk)) + reqsk_fastopen_purge_rst(&icsk->icsk_accept_queue); + else + inet_csk_listen_stop(sk); return err; } =20 --=20 2.55.0 From nobody Mon Nov 23 20:27:02 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=1795440331; b=r47wX0Dybv2tnFp+0WOzfBTQRkO73Sj79VhFyPzxm0TUS3R7cSxe29y2AOJey9Ohq5NE gcmlVTiJuXo1kFOppRQAj0778k5g00Z4sacs1u/dGNpXH2p67in74/CuY6VCpjGkcl4Cr M2fi7MvcqG2oHKA1+5RUCx2odhh9qh1vH46QpcvZKPQQ9zRjP73HbYF26ivRRGY8uRwWX 4DTWuE8tWA+dsNRk9/KSiM6hikiroe5825H2TfGkeuTRIZWeFdI5jA1SRjUTO+jGsWs9M Bgpw53ekJaigbXuI2ePGFa8xq8z+cJUTliSddufQVSnjZKTJv1TQsUxJCpAlbQYt96w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795440331; 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=5Og4wPEpf33bGTGjibI2FKvY8gzfx4KipgO1zg400HI=; b=46JF105YN+WbWK1XqbjAOFFlaDVBD9rfPqNSlCojCFZ5gnItsNKx62Qazlg0EjFwdhHL UcrsMYztjR96fAlrRhXXDjYWCRcXaNs4EjcASwTMTYNgsxeo8tCGaA6BOToI+Aent1YmI m4Gtl+sCybI50zqiTse8Ut7RT38HBnDq5UonFlfk8qvdaRYZJoEnvPtTRgHowKgSHFjl4 ZCNWkfyMIQ/tM81iRk1R6YH+mx4i7HqklnnrCJjRfzQgJoMJ/7orju6aCPgm0s/PD0Lcv xnY6Do2YVbEeJAS9fMGv69WgpRSRxC44JwpI1vIDT4sEMNM8Q0ifOExwf/pDejF0wfQ== 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=SYrLs4xx; 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 2C849606A31A; Mon, 23 Nov 2026 13:25: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=SYrLs4xx Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CC1A1F000C0; Mon, 23 Nov 2026 13:25:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795440330; bh=5Og4wPEpf33bGTGjibI2FKvY8gzfx4KipgO1zg400HI=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=SYrLs4xxjlE+W9jwIaVnjMfMZQps17wlsnjriKk1pYedZzY6MTXo53ZqG+N1XiBTs eXAdnjJkn6XMUkCnZUFzWmfgKOzkO04ii9/L0DAQnyFm2Ej3UQyH90P+VIhYtXid70 kXvRIT7EBzZ8A/cAoDfezzKIoXfdKuzeRAKGAVk13yZok6OzF20TOrTGhvq8OZnlIF Wk8hohNYFcc+fYQ3EqsyfYfgth5huC/0ZUIeRO1YYYfIq39IAwWTGjgQ+VNn6g695+ Mt+0itpsBlmIdjYtcsAZhacI5Ddn1sV8GnepfDYfrBCsR5ssryIJBoX2EM4Luqe33L fxRFdP0Y+qWFw== From: "Matthieu Baerts (NGI0)" Date: Mon, 23 Nov 2026 14:24:50 +0100 Subject: [PATCH net 02/10] 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: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-2-278042217e8d@kernel.org> References: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> In-Reply-To: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> To: Eric Dumazet , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Mat Martineau , Geliang Tang , Christoph Paasch , Florian Westphal Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, Davide Caratti , "Matthieu Baerts (NGI0)" , Chris Mason , stable@vger.kernel.org X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2354; i=matttbe@kernel.org; h=from:subject:message-id; bh=2rgOVhu1I0CypO/fm+P6652Bhfc+fCsfBf4Pl3a7+LY=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLJZ7HbetzsQ+cIjN7gu+155cF/wf626O2U3PM7Pt+o9I 5ZiVZ3TUcrCIMbFICumyCLdFpk/83kVb4mXnwXMHFYmkCEMXJwCMBGlqQz/69/4LyjzOxL2+uUE Ie3VfoVn+rLlClKFpa9lVShVyXonMvyVdzw0wfORZ9TT6hf5PgdEHtefk3DQWG9l/pRvmcI6YRV mAA== 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 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" only purges the RST queue of 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, and reproduced in a VM, with the reproducer of the previous commit, modified to use MPTCP sockets, on both sides. 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, 1151 left. Sockets: 64982 made, 5755 l= eft [...] result: namespaces: 1000 made, 923 taken down, 77 left Fixes: 76e2a55d1625 ("mptcp: better msk-level shutdown.") Cc: stable@vger.kernel.org Signed-off-by: Chris Mason [ Shorter comment. Add a Fixes tag. Commit message: how the issue was found, and its symptoms. ] 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 b375da1f17fe..fd88104f0631 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -4340,6 +4340,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:02 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=1795440335; b=JswmGWWFnpg4AnE3DnigcSWA0nPHioLZ3Jqq+BffDdMwgI9e0Yg/6odZXZZQRG/fAQyL r5fyzSGB6VO2bz8yP7/66ciJyCQ6Th1ADoO+6fPwLG/Gjt885r/DLDly3A6g0rc/h7l8V C9rL1ZyybK+YjjKXT/wm/4BYEfb/NJNJKpnIV3K9EvGHdpXJKV6kWL+Y4qrCPcPe9ky6b XeIaOyU+sLn7rQtrD6hrLPWSco0x0yFCwPPwYvR7XkH4MK0B8aQ7Ik12o545qHJTaeSrn TUHMfxkYAl98NlEhthRt65UX2HjlYGeK1mcpCpXPSDxTo0RdTPozl6GPMjrjxIlwA9w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795440335; 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=j6NoxPUSnIuQNQok+UdtQrawTTFukTWkIuqhw/dxpKQ=; b=wBoyJIkpxAErpJGT5ddRHvkNg3u2yG8gLXStBZZMmCOaQ2LoR1DC+sicsZg6hO1Gm7Il LU2qOo0OBq9ahly+ePDiGjS4kAysb/6MhR7I5qMZBM6ryBNcf91CFwwaqbGpNXijLQiMx +BDmLJct4feX7yFrqQ9WLUvAZtWhpjUC0VkYVrxS05l5x1bNGXb2VucjeZld7nrJ5x4nI MqcEnLArOaCjpCHvFRPDJNwT+dLxu5/YPGlrFKR7y8pXvggYyvuhfW8c4AkzsFa41qh/J T63JFdIB5q+hlzikyhrD97QtdcIa9lJLQIhYV6fapns3Z/stdxHmZxRV7EhouZVf6/A== 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=jBb+bgSg; 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 EAD01606A31F; Mon, 23 Nov 2026 13:25: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=jBb+bgSg Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB4F81F000D2; Mon, 23 Nov 2026 13:25:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795440334; bh=j6NoxPUSnIuQNQok+UdtQrawTTFukTWkIuqhw/dxpKQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=jBb+bgSgMY2lc48tNZAdlsxl56nZrYBG7+DAqYWHLKpkgdbYTR1PH8+ajZCxEUFYK MZ49Ht5t6ZojMkhMa0oPRA/44QpjjivN1G1+T3UTPERQTbroGBfVU+jRgt0H2OsK04 9YkXrX+R/exMIwSBLQaYvaDkql8+WTVQwRkZPm+QOPaemrTmylUUm+KkE3FUv0i9kv lQE7uSfeAQxcfh10cJ1qsPAxmpi5p4nr4Xe+inHqkux9ILNrHwd00VTB73VQV803ph ibzicA56I81zvR3bJjNr2OKaJfeDsaVAUMPo3RK3OSYhhR2sX5Z9SRqo4a3eGY/WgH pxRgiWJM8Yh6g== From: "Matthieu Baerts (NGI0)" Date: Mon, 23 Nov 2026 14:24:51 +0100 Subject: [PATCH net 03/10] 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: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-3-278042217e8d@kernel.org> References: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> In-Reply-To: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> To: Eric Dumazet , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Mat Martineau , Geliang Tang , Christoph Paasch , Florian Westphal Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, Davide Caratti , "Matthieu Baerts (NGI0)" , Chris Mason , stable@vger.kernel.org X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4207; i=matttbe@kernel.org; h=from:subject:message-id; bh=xK7mk0IXLH6lvQit6O/NTnaAI29UyNNxOopnuSz9I3s=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLJZ7HZdjnPY+ejGEsbJ7BbFmzfmdQZsk7sWJf3J4l7/0 XMKO47c6ChlYRDjYpAVU2SRbovMn/m8irfEy88CZg4rE8gQBi5OAZgI7y5Ghs77Uur37vyQDnfa OP2G8bu7yScSLu9MCbvOvjq79bTHR1lGhsYN2280l4jXzuK9tJabJclHR95pzyxZDX1HsTdFpxk U+QE= 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= ") Cc: stable@vger.kernel.org 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 fd88104f0631..50c294d925b0 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3677,6 +3677,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:02 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=1795440338; b=k1VmPEI7g0x2YYW1PDH6pDH8VVPsVR+MDyHnpHHeK4K1EKUNroQ+yioLDkhHpmeCfKxr BX3YkjYQjW6uli1qn7MfvE4yI9aiHX1W5AZj9lWlAgDqboVCZCrCWdJimopqv4q/yaHra IUBCzTzb9LEc61MeqF03IGOvPyn9wo4kJRQK6OQH0NDyRaMHl7ijPkqtcaBt8JX+hguh9 JXSzTQCd/OV0CWUAX9splDZ41EY4Dug1dpEPFM6pp6kCsGSAIsgps7OGK0dKg29Nzj69N 3vEbhT4RjmTw68NfgtAw+W4jM6hiQFA3HOwYQC4Rg8YRRtmmCRFLMNYRn0Hxe2ydPbw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795440338; 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=oy64PdZyhO4DtmF/zcDvZ3jcwcS/HhDwapf7h/PdNXg=; b=NY9xwx+w/XfbQhHhv76qIAI7cnBsmpE8cWKtdur3px9XnsPL1scsIFB4h/n5OSY/eSnp ogbAbBeYkjoRW7rVFQLdu7WWstK3FCHzyZfD7UaYf/DV5w0/Iws8oO2vFNGtJMrE+pf9u Lt5zQW9xdOLs6CVaH0RO1kEr3zdg7MoXxnJ+qugHR280ByMVPP9/mCEzT1Y9nsMgrWcqF Z9jObN0j0BYIkQcDSEati68mEgvQmnQILuIs+03LXuvTA2A2bNOB80O4iAh3NXRkdG0Ap S8vtmIFgIVca4i+yKrPP68NQmfld9DV7iYw790qYZSmWaVsXHXaUE5loQw++EVb4YZA== 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=Zn4qLv5F; 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 57561606A327; Mon, 23 Nov 2026 13:25:38 +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=Zn4qLv5F Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33E0C1F0089E; Mon, 23 Nov 2026 13:25:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795440337; bh=oy64PdZyhO4DtmF/zcDvZ3jcwcS/HhDwapf7h/PdNXg=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Zn4qLv5FdYdHJ94ANhkV1fjsIW6OFYteX7xUcBmxOSJvfZL8wkY8EwKBV2v/SqQIL MAWkddx20l+KCYBqcQQhIUv7a2Bn7Lourtwx/1BfbFwyQ1UCownh2k6Z3iDqnc/I5J LjPZr3NqtthkWxPP9eNGapWflCATW9cB7PPmcocEU8t1YPrHCd7YEcu3SHz1kXMm88 YpgDXobipHxjYAmEZc5YYuYI9a6sL2XtUlBuGZ3vBJ3boVCSKsIJYn1QITbHMzldI6 +/vROYvI30ieddzl0NFuPv90xO3VyaSCJc3Ya4AClMwq1ajkbJH1/agk07JEE7WpG8 42VXSpcgnPl/w== From: "Matthieu Baerts (NGI0)" Date: Mon, 23 Nov 2026 14:24:52 +0100 Subject: [PATCH net 04/10] mptcp: fix use-after-free of the subflow context on the delegated 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: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-4-278042217e8d@kernel.org> References: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> In-Reply-To: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> To: Eric Dumazet , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Mat Martineau , Geliang Tang , Christoph Paasch , Florian Westphal Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, Davide Caratti , "Matthieu Baerts (NGI0)" , Hyunwoo Kim , stable@vger.kernel.org X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=16707; i=matttbe@kernel.org; h=from:subject:message-id; bh=BfmlDaYNXU7G6mWiG3Vgi7hri1N3ZYChGlKVzTq4VH4=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLJZ7HZJTLyjeLpyxYKGZPlyKTnjQ3KLLulPby9Nj/gec fuG2ze+jlIWBjEuBlkxRRbptsj8mc+reEu8/Cxg5rAygQxh4OIUgIlYxzD8s1nzu0vqYmKx51KT lFD5df2uez7/DytffnWDko5Fb1qlCCPDBY+vcv8dz+5v5WRb1b3ntoSv9yEeu9ezhYtj/kh5GPR yAwA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Hyunwoo Kim mptcp_subflow_delegate() links the subflow context into a per-CPU napi list and takes a reference on the subflow socket. The context is a separate allocation, reached through icsk_ulp_data, and the list holds no reference to it. inet_csk_destroy_sock() runs sk_prot->destroy() regardless of the outstanding references. That path ends in tcp_cleanup_ulp(), which calls subflow_ulp_release(). subflow_ulp_release() frees the context with kfree_rcu() but does not remove it from the list. Once the grace period elapses and the context is actually freed, the next mptcp_napi_poll() dequeues that entry and mptcp_subflow_delegated_next() writes to the freed context with list_del_init(). That is the use-after-free. The decoded KASAN trace is: =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=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 BUG: KASAN: slab-use-after-free in __list_del_entry_valid_or_report (lib/l= ist_debug.c:49) Read of size 8 at addr ffff88800cc13cc8 by task poc/88 CPU: 3 UID: 65534 PID: 88 Comm: poc Not tainted 7.2.0-rc7 #1 PREEMPT(lazy) Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996= ), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 Call Trace: dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120) print_report (mm/kasan/report.c:378 mm/kasan/report.c:482) ? __pfx__raw_spin_lock_irqsave (include/asm-generic/qrwlock.h:122 (discri= minator 4)) ? __list_del_entry_valid_or_report (lib/list_debug.c:49) kasan_report (mm/kasan/report.c:595) ? __list_del_entry_valid_or_report (lib/list_debug.c:49) __list_del_entry_valid_or_report (lib/list_debug.c:49) mptcp_napi_poll (include/linux/list.h:132 include/linux/list.h:246 includ= e/linux/list.h:318 net/mptcp/protocol.h:787 net/mptcp/protocol.c:4620) ? call_timer_fn (kernel/time/timer.c:1748) __napi_poll (net/core/dev.c:7735) ? __pfx_delayed_work_timer_fn (include/linux/list.h:404 (discriminator 2)) net_rx_action (net/core/dev.c:7798 net/core/dev.c:7955) ? __pfx_net_rx_action (include/net/gro.h:525) ? _raw_spin_lock_irq (include/linux/instrumented.h:55 include/linux/atomi= c/atomic-instrumented.h:1301 include/asm-generic/qspinlock.h:111 include/li= nux/spinlock.h:187 include/linux/spinlock_api_smp.h:143 kernel/locking/spin= lock.c:174) ? __pfx__raw_spin_lock_irq (kernel/locking/spinlock.c:183) ? try_to_wake_up (include/linux/spinlock.h:571 kernel/sched/core.c:4292) handle_softirqs (kernel/softirq.c:622) ? __pfx_handle_softirqs (include/linux/wait_bit.h:77) ? __hrtimer_rearm_deferred (kernel/time/hrtimer.c:707 kernel/time/hrtimer= .c:2141 kernel/time/hrtimer.c:2161) do_softirq (kernel/softirq.c:523 (discriminator 20) kernel/softirq.c:510 = (discriminator 20)) __local_bh_enable_ip (kernel/softirq.c:450) inet_stream_connect (net/ipv4/af_inet.c:756) __sys_connect (net/socket.c:2154) ? __pfx___sys_connect (net/socket.c:2136) ? __sys_setsockopt (include/linux/file.h:63 include/linux/file.h:83 net/s= ocket.c:2385) __x64_sys_connect (net/socket.c:2160 net/socket.c:2157 net/socket.c:2157) ? fpregs_assert_state_consistent (include/linux/instrumented.h:82 include= /asm-generic/bitops/instrumented-non-atomic.h:141 include/linux/thread_info= .h:133 arch/x86/kernel/fpu/core.c:912) do_syscall_64 (arch/x86/entry/syscall_64.c:63 arch/x86/entry/syscall_64.c= :94) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) RIP: 0033:0x4216eb Code: 48 89 e5 48 83 ec 10 89 55 f8 48 89 75 f0 89 7d fc e8 b9 ec 02 00 8b= 55 f8 48 8b 75 f0 41 89 c0 8b 7d fc b8 2a 00 00 00 0f 05 <48> 3d 00 f0 ff = ff 77 2d 44 89 c7 89 45 fc e8 12 ed 02 00 8b 45 fc All code =3D=3D=3D=3D=3D=3D=3D=3D 0: 48 89 e5 mov %rsp,%rbp 3: 48 83 ec 10 sub $0x10,%rsp 7: 89 55 f8 mov %edx,-0x8(%rbp) a: 48 89 75 f0 mov %rsi,-0x10(%rbp) e: 89 7d fc mov %edi,-0x4(%rbp) 11: e8 b9 ec 02 00 call 0x2eccf 16: 8b 55 f8 mov -0x8(%rbp),%edx 19: 48 8b 75 f0 mov -0x10(%rbp),%rsi 1d: 41 89 c0 mov %eax,%r8d 20: 8b 7d fc mov -0x4(%rbp),%edi 23: b8 2a 00 00 00 mov $0x2a,%eax 28: 0f 05 syscall 2a:* 48 3d 00 f0 ff ff cmp $0xfffffffffffff000,%rax <-- trapping = instruction 30: 77 2d ja 0x5f 32: 44 89 c7 mov %r8d,%edi 35: 89 45 fc mov %eax,-0x4(%rbp) 38: e8 12 ed 02 00 call 0x2ed4f 3d: 8b 45 fc mov -0x4(%rbp),%eax Code starting with the faulting instruction =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=3D=3D=3D=3D=3D=3D=3D=3D 0: 48 3d 00 f0 ff ff cmp $0xfffffffffffff000,%rax 6: 77 2d ja 0x35 8: 44 89 c7 mov %r8d,%edi b: 89 45 fc mov %eax,-0x4(%rbp) e: e8 12 ed 02 00 call 0x2ed25 13: 8b 45 fc mov -0x4(%rbp),%eax RSP: 002b:00007fbe0147b1d0 EFLAGS: 00000293 ORIG_RAX: 000000000000002a RAX: ffffffffffffffda RBX: 000000000000000a RCX: 00000000004216eb RDX: 0000000000000010 RSI: 00007fbe0147b200 RDI: 000000000000000a RBP: 00007fbe0147b1e0 R08: 0000000000000000 R09: 0000000000000000 R10: 00007fbe0147b1f8 R11: 0000000000000293 R12: 00007fbe0147b1f8 R13: 00007fbe0157b678 R14: 00007fbe0147b1f4 R15: 00007fffd4bc16c0 Allocated by task 90: kasan_save_stack (mm/kasan/common.c:57) kasan_save_track (mm/kasan/common.c:78) __kasan_kmalloc (mm/kasan/common.c:398 mm/kasan/common.c:415) __kmalloc_cache_noprof (include/linux/kasan.h:263 mm/slub.c:5489) subflow_create_ctx (include/linux/slab.h:988 include/linux/slab.h:1309 ne= t/mptcp/subflow.c:1845) subflow_ulp_init (net/mptcp/subflow.c:1977) tcp_set_ulp (net/ipv4/tcp_ulp.c:146 net/ipv4/tcp_ulp.c:167) mptcp_subflow_create_socket (net/mptcp/subflow.c:1806) __mptcp_nmpc_sk.part.0 (net/mptcp/protocol.c:111 net/mptcp/protocol.c:143) mptcp_connect (net/mptcp/protocol.c:139 net/mptcp/protocol.c:4009) __inet_stream_connect (net/ipv4/af_inet.c:684) inet_stream_connect (net/ipv4/af_inet.c:755) __sys_connect (net/socket.c:2154) __x64_sys_connect (net/socket.c:2160 net/socket.c:2157 net/socket.c:2157) do_syscall_64 (arch/x86/entry/syscall_64.c:63 arch/x86/entry/syscall_64.c= :94) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) Freed by task 22: kasan_save_stack (mm/kasan/common.c:57) kasan_save_track (mm/kasan/common.c:78) kasan_save_free_info (mm/kasan/generic.c:584) __kasan_slab_free (mm/kasan/common.c:253 mm/kasan/common.c:285) kvfree_rcu_cb (include/linux/kasan.h:235 mm/slub.c:2677 mm/slub.c:6377 mm= /slub.c:6662) rcu_core (kernel/rcu/tree.c:2645 kernel/rcu/tree.c:2897) handle_softirqs (kernel/softirq.c:622) run_ksoftirqd (kernel/softirq.c:1076 kernel/softirq.c:1068) smpboot_thread_fn (kernel/smpboot.c:160) kthread (kernel/kthread.c:436) ret_from_fork (arch/x86/kernel/process.c:158) ret_from_fork_asm (arch/x86/entry/entry_64.S:245) Last potentially related work creation: kasan_save_stack (mm/kasan/common.c:57) kasan_record_aux_stack (mm/kasan/generic.c:556) __call_rcu_common.constprop.0 (kernel/rcu/tree.c:3159) tcp_cleanup_ulp (net/ipv4/tcp_ulp.c:124) tcp_v4_destroy_sock (net/ipv4/tcp_ipv4.c:2437) inet_csk_destroy_sock (net/ipv4/inet_connection_sock.c:1282) __tcp_close (net/ipv4/tcp.c:3299) __mptcp_close_ssk (net/mptcp/protocol.c:2648) mptcp_destroy_common (net/mptcp/protocol.c:3442 (discriminator 1)) mptcp_destroy (net/mptcp/protocol.c:3651) __mptcp_destroy_sock (net/mptcp/protocol.c:3284) __mptcp_close (net/mptcp/protocol.c:3386) mptcp_close (net/mptcp/protocol.c:3401) inet_release (net/ipv4/af_inet.c:442) __sock_release (net/socket.c:710) sock_close (net/socket.c:1501 (discriminator 1)) __fput (fs/file_table.c:512) fput_close_sync (fs/file_table.c:617) __x64_sys_close (fs/open.c:1511 fs/open.c:1496 fs/open.c:1496) do_syscall_64 (arch/x86/entry/syscall_64.c:63 arch/x86/entry/syscall_64.c= :94) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) Second to last potentially related work creation: kasan_save_stack (mm/kasan/common.c:57) kasan_record_aux_stack (mm/kasan/generic.c:556) kvfree_call_rcu (mm/slab_common.c:1288) tcp_cleanup_ulp (net/ipv4/tcp_ulp.c:124) tcp_v4_destroy_sock (net/ipv4/tcp_ipv4.c:2437) inet_csk_destroy_sock (net/ipv4/inet_connection_sock.c:1282) __tcp_close (net/ipv4/tcp.c:3299) __mptcp_close_ssk (net/mptcp/protocol.c:2648) mptcp_destroy_common (net/mptcp/protocol.c:3442 (discriminator 1)) mptcp_destroy (net/mptcp/protocol.c:3651) __mptcp_destroy_sock (net/mptcp/protocol.c:3284) __mptcp_close (net/mptcp/protocol.c:3386) mptcp_close (net/mptcp/protocol.c:3401) inet_release (net/ipv4/af_inet.c:442) __sock_release (net/socket.c:710) sock_close (net/socket.c:1501 (discriminator 1)) __fput (fs/file_table.c:512) fput_close_sync (fs/file_table.c:617) __x64_sys_close (fs/open.c:1511 fs/open.c:1496 fs/open.c:1496) do_syscall_64 (arch/x86/entry/syscall_64.c:63 arch/x86/entry/syscall_64.c= :94) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) The buggy address belongs to the object at ffff88800cc13c00 which belongs to the cache kmalloc-512 of size 512 The buggy address is located 200 bytes inside of freed 512-byte region [ffff88800cc13c00, ffff88800cc13e00) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0xcc10 head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x100000000000040(head|node=3D0|zone=3D1) page_type: f5(slab) raw: 0100000000000040 ffff888007042c80 dead000000000100 dead000000000122 raw: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000 head: 0100000000000040 ffff888007042c80 dead000000000100 dead000000000122 head: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000 head: 0100000000000002 ffffffffffffff01 00000000ffffffff 00000000ffffffff head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff88800cc13b80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ffff88800cc13c00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff88800cc13c80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff88800cc13d00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88800cc13d80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb =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=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 The freeing path cannot dequeue the entry itself: the list is per-CPU and only the CPU that queued the subflow may touch it, as tcp_release_cb_override() already notes. Delay the free instead. Add MPTCP_DELEGATE_DEAD. mptcp_subflow_free_ctx() sets it and frees the context only if the subflow is not scheduled, while mptcp_napi_poll() frees it if the dead bit is set when it clears the scheduled bit. Either mptcp_subflow_free_ctx() gets there first, sees the scheduled bit and leaves the free to mptcp_napi_poll(), or mptcp_napi_poll() gets there first, does not see the dead bit and mptcp_subflow_free_ctx() does the free. Also skip mptcp_subflow_process_delegated() once the dead bit is set. subflow_ulp_release() has already dropped the msk reference by then, so the pending actions must not run. Finally, move delegated_status out of struct_group(reset). mptcp_subflow_ctx_reset() clears that group on disconnect, and clearing the scheduled bit while the entry is still queued would let mptcp_subflow_free_ctx() free a context the napi list still points to. delegated_node is already outside the group. Fixes: b19bc2945b40 ("mptcp: implement delegated actions") Cc: stable@vger.kernel.org Signed-off-by: Hyunwoo Kim Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 13 ++++++++++--- net/mptcp/protocol.h | 18 ++++++++++++++++-- net/mptcp/subflow.c | 4 ++-- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 50c294d925b0..23d35f43b566 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2708,7 +2708,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct= sock *ssk, */ if (!inet_csk(ssk)->icsk_ulp_ops) { WARN_ON_ONCE(!sock_flag(ssk, SOCK_DEAD)); - kfree_rcu(subflow, rcu); + mptcp_subflow_free_ctx(subflow); } else { /* otherwise tcp will dispose of the ssk and subflow ctx */ __tcp_close(ssk, 0); @@ -4803,10 +4803,13 @@ static int mptcp_napi_poll(struct napi_struct *napi= , int budget) delegated =3D container_of(napi, struct mptcp_delegated_action, napi); while ((subflow =3D mptcp_subflow_delegated_next(delegated)) !=3D NULL) { struct sock *ssk =3D mptcp_subflow_tcp_sock(subflow); + long status; =20 bh_lock_sock_nested(ssk); if (!sock_owned_by_user(ssk)) { - mptcp_subflow_process_delegated(ssk, xchg(&subflow->delegated_status, 0= )); + status =3D xchg(&subflow->delegated_status, 0); + if (!(status & BIT(MPTCP_DELEGATE_DEAD))) + mptcp_subflow_process_delegated(ssk, status); } else { /* tcp_release_cb_override already processed * the action or will do at next release_sock(). @@ -4814,11 +4817,15 @@ static int mptcp_napi_poll(struct napi_struct *napi= , int budget) * CPU that scheduled it. */ smp_wmb(); - clear_bit(MPTCP_DELEGATE_SCHEDULED, &subflow->delegated_status); + status =3D set_mask_bits(&subflow->delegated_status, + BIT(MPTCP_DELEGATE_SCHEDULED), 0); } bh_unlock_sock(ssk); sock_put(ssk); =20 + if (status & BIT(MPTCP_DELEGATE_DEAD)) + kfree_rcu(subflow, rcu); + if (++work_done =3D=3D budget) return budget; } diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 7d226ee38315..7644651f01a8 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -553,8 +553,10 @@ DECLARE_PER_CPU(struct mptcp_delegated_action, mptcp_d= elegated_actions); #define MPTCP_DELEGATE_SEND 1 #define MPTCP_DELEGATE_ACK 2 #define MPTCP_DELEGATE_SNDBUF 3 +#define MPTCP_DELEGATE_DEAD 4 =20 -#define MPTCP_DELEGATE_ACTIONS_MASK (~BIT(MPTCP_DELEGATE_SCHEDULED)) +#define MPTCP_DELEGATE_ACTIONS_MASK (~(BIT(MPTCP_DELEGATE_SCHEDULED) | \ + BIT(MPTCP_DELEGATE_DEAD))) /* MPTCP subflow context */ struct mptcp_subflow_context { struct list_head node;/* conn_list of subflows */ @@ -628,11 +630,11 @@ struct mptcp_subflow_context { =20 u32 subflow_id; =20 - long delegated_status; unsigned long fail_tout; =20 ); =20 + long delegated_status; struct list_head delegated_node; /* link into delegated_action, protect= ed by local BH */ =20 u32 setsockopt_seq; @@ -671,6 +673,8 @@ mptcp_subflow_ctx_reset(struct mptcp_subflow_context *s= ubflow) memset(&subflow->reset, 0, sizeof(subflow->reset)); subflow->request_mptcp =3D 1; WRITE_ONCE(subflow->local_id, -1); + set_mask_bits(&subflow->delegated_status, + MPTCP_DELEGATE_ACTIONS_MASK, 0); } =20 /* Convert reset reasons in MPTCP to enum sk_rst_reason type */ @@ -808,6 +812,16 @@ mptcp_subflow_delegated_next(struct mptcp_delegated_ac= tion *delegated) return ret; } =20 +static inline void mptcp_subflow_free_ctx(struct mptcp_subflow_context *su= bflow) +{ + long old =3D set_mask_bits(&subflow->delegated_status, 0, + BIT(MPTCP_DELEGATE_DEAD)); + + /* a scheduled subflow is owned by mptcp_napi_poll(), which will free it = */ + if (!(old & BIT(MPTCP_DELEGATE_SCHEDULED))) + kfree_rcu(subflow, rcu); +} + void __mptcp_inherit_memcg(struct sock *sk, struct sock *ssk, gfp_t gfp); void __mptcp_inherit_cgrp_data(struct sock *sk, struct sock *ssk); =20 diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 6f07544bfe40..20d506235074 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -832,7 +832,7 @@ void mptcp_subflow_drop_ctx(struct sock *ssk) sock_put(ctx->conn); } =20 - kfree_rcu(ctx, rcu); + mptcp_subflow_free_ctx(ctx); } =20 void __mptcp_subflow_fully_established(struct mptcp_sock *msk, @@ -2098,7 +2098,7 @@ static void subflow_ulp_release(struct sock *ssk) =20 mptcp_subflow_ops_undo_override(ssk); if (release) - kfree_rcu(ctx, rcu); + mptcp_subflow_free_ctx(ctx); } =20 static void subflow_ulp_clone(const struct request_sock *req, --=20 2.55.0 From nobody Mon Nov 23 20:27:02 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=1795440341; b=LZZHARUUvA5r6fhT0xdlXmqAETHAVci9F4C5hz+PZKUismYFf/oSQNqmaB+ro1vPUmUr iip8XD364t9nlb1SWf+b91YfI+vm/rPkj/P7vB8E5u5njQm6AdSsdcjhP6IBorheXkc2Q LKeVa91Q+zBbJo/8l9DPjW066F+a5FbHuPaGiG7G4EQA6SoZ/L2ZA8DYTLe0e0CXG9iJK +M/We9QLZpdBNlbEa05vIjQZKmuc2XllY+nFpsC5YMEuv3W1k68sJvkb0H9hOAEpcCsz8 QXuqQyaRi6Ml+DNk74ry0Ow6zYr9whDzFAmHkOCCirJWs/H9HbkKO7vaSHh6s5+JPqQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795440341; 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=5yQazAnRvUhL1YPWsEfIdEVVovgootntAdurk94OIqg=; b=2hNgaxdOFzCiSHN87rNym8Vvx1V+zdsqW5RpGAu69oVU2cpqD2HEMPWW/6M+LSZaVn10 UjmirbC3Vdcw4782n81qpw/Azm/QigcpzPq2cy/2iMwUn4TWFthjVUbfJKgd1bM0bHo/H Eg+3yoOe0lL1xETNLl7/MFvg4XlE7OPCmjpbaVuxQUJvKOCtd9zwWj7Rqu67cxXsc/815 Hj3fzUUXPk6RZ8/fmnwOSONPc+eMG0c5g/0QV5yegWgN1CQIA21qaTTeS/zyXz6vImG0x anYxngvpI7TNUx/UNyiBMNhe5MERXwtrErfCZr2xFthoMxRj5sEREtitlQyOsYzwXxQ== 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=RO0EorJX; 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 D025F606A685; Mon, 23 Nov 2026 13:25: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=RO0EorJX Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AA5C1F0089E; Mon, 23 Nov 2026 13:25:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795440341; bh=5yQazAnRvUhL1YPWsEfIdEVVovgootntAdurk94OIqg=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=RO0EorJXxcRkVcVfYhjOHzl/udxH2Snsi6TtPB3SUNCTNb5ucgUm5mvq7T9WKa6XM k1AlPC6mc4M919tcH1/B2LoH+575+1jmZtQt4e3U+ppRl965CIjRbjsk33kI9p3xgq DLvOmmrQcky9+Thwl3tTjkuyYf3Aw226+LbeTdCQnoGZ1C8M6KsT8CL2WSpk8AIsi2 2ZT3gqB7gih/FjXsogxsJ5lLQHrjmAJ9CpkDO98U8FmqXkgZvWkKumIo4QW3BfyEnm u1zwickS/8cbuXjldh43vMSNCdEjh1rtc09TQiUE8sOW7eg8ZcEplNC4cWAjMmOQZS k/pwn2qj8Y+fg== From: "Matthieu Baerts (NGI0)" Date: Mon, 23 Nov 2026 14:24:53 +0100 Subject: [PATCH net 05/10] 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: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-5-278042217e8d@kernel.org> References: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> In-Reply-To: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> To: Eric Dumazet , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Mat Martineau , Geliang Tang , Christoph Paasch , Florian Westphal Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, Davide Caratti , "Matthieu Baerts (NGI0)" , Chris Mason , stable@vger.kernel.org X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3222; i=matttbe@kernel.org; h=from:subject:message-id; bh=XWQXbAqQ6Lz7CqdQOqSowGu9aekYFBuMgbNjjPTK0Zw=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLJZ7HbzLF97uPnC5/MveHYmPPq69PvfeX+MF7m8tXf3+ 3V0OU9xREcpC4MYF4OsmCKLdFtk/sznVbwlXn4WMHNYmUCGMHBxCsBEWi8y/DM/VPHT5+SSltaj AuwNs9KDRTubPVI7rsr+YVg6pe9z20yG/0E37fqsgwMWJR8s2cLSujd6zcT+dUUfOQ8ysM7X22H /nAEA 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") Cc: stable@vger.kernel.org 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 23d35f43b566..17451240c105 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2312,9 +2312,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:02 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=1795440345; b=SQZzidJZUzwE6OwZNjVMowGbz1hhSOYBBhMXX7f3n5Jl+p3VW7+mTg6uJqtkQB0Zp0A1 UUyzAgGx75n6MtkxOKbgWXW8lB13GQ54TICYz1Lm44xaFHwUc8ScuODGL6Bp6HK+3a6GU vPiufbUh19h/OIxT/NRJb3zDPAquN1JelIZJ2y4iZamFZ7da+DchtA4WDW1bavEoiMzX5 bsrD4v6PgaI+BwSmO7ub1gjPBcbdEViIMMBLH37bxy0R1Am5Q3sUBrJW+/P0eE5hNGX57 V8GMCxO8eYVhHvMAMH9ptLkQw753Gk9M2WYP9ZGG9RNxsJJKtzrt+UTvcwWublg2f8w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795440345; 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=dhOl6SMJcFEgG7JjGFeImeI+0PoTpGZsESAagy7OtWc=; b=0Mg8Ujm75xf8uQGqnpThXKbEBhAYlGD8vHIQQdyK8MC4IEBTfccFhhxN68AhczVIyG1E XWwxGhylawuXkBzx9TlxN/dYdn/8dGGIJwwmbPaOJ5r7P96ptzh0iXFjxNY3PCFkH6znv pKJLWOBnY5Zvjp28eoWl9nEdnaRltNNZ678q3hjjsb9QBWgxjQIpsJ2L5hHLKnZd861t9 Ob7Q+oVA052ZMMSt9rt43RNCfUTIL6dyUguqJNrKHKzZN3PKlk3Yrqol3NAYzmdX4cT69 aED/DHQ8hUB8uqtHpOGTky8VmPmfhzyVrC73DZhtWiXRGGlA3Q0Ii9t3ZilU6Qr2Tsw== 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=YOYCJAT+; 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 56BB4606A69A; Mon, 23 Nov 2026 13:25:45 +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=YOYCJAT+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id B25061F000EB; Mon, 23 Nov 2026 13:25:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795440345; bh=dhOl6SMJcFEgG7JjGFeImeI+0PoTpGZsESAagy7OtWc=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=YOYCJAT+1au2FoXWFlgrCw8LuyylzV6LeFXo3/9Ver4d4Qys5WFL0AYiWDwigGzGf 60wyZinnE1F7aSIg1MjpOfLqNIZOHuCNoEFYtkWzdbGLqXFy/VHa9OPVQ0p3iN78yH IcYtI3Ms67bBiDVGsdEQeQvgfS4iHAZ/YZxidtYc1MP2pHYLW6wDirVsYbp9qGB2h7 6vq0vydldoe2kivfymszceP78Zj23JjsS22V3ufm4Nri9+cFn3hOb+oe2M2FK3k9yV ILNip26Zr83bii0A1Jd8jAR7q8FNtRJJioyyQ+qL9qcAlXKiuyxssqW0LPwX8fenC3 vM06DyFd/rziQ== From: "Matthieu Baerts (NGI0)" Date: Mon, 23 Nov 2026 14:24:54 +0100 Subject: [PATCH net 06/10] 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: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-6-278042217e8d@kernel.org> References: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> In-Reply-To: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> To: Eric Dumazet , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Mat Martineau , Geliang Tang , Christoph Paasch , Florian Westphal Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, Davide Caratti , "Matthieu Baerts (NGI0)" , stable@vger.kernel.org X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3178; i=matttbe@kernel.org; h=from:subject:message-id; bh=idSA9++hWiOgEzQLbsTV71c4EwKKNFxFmkF/eqUJWig=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLJZ7PZYdN+e6PHmqsaK7teiz+pNHCMjm/tC3y6sLHVZF iK1LONoRykLgxgXg6yYIot0W2T+zOdVvCVefhYwc1iZQIYwcHEKwESC4xn+6bSU3/6/tGHnP+65 E8SufnwwQ/bRssNF89d/SFTK2NxbbcLIcJQj4c52j/KT29bk1bD9PXZBu3G24/O7PMKe29/ciXu 2kgUA 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") Cc: stable@vger.kernel.org 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 17451240c105..5339fd6a8d81 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2744,8 +2744,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:02 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=1795440349; b=ABQFW3kPN1nOOsbxH5UtTPksxcozHljBo5D8PMGgcLnRil3NdC7e7S2fGaakXElHgReq KHR3JaHPGEACiNy03fQzSn0A4WEuzbOtrlOGpG1ZH9kInzz1YINxCCfCpP4W3ljdIyI42 UoJ26JjY9HJx3cLx9On0XOcMhCzI7CFQv1CJgRorqHRfWFjTm9pWX4ZwgIqshZ6A+Unhg Rd3ivghm9xB05G2V85axkLs8dxDwg9QhqnaCPufKODN5JFQbh32niaRXGWeprwMDvEQdI gJZ8qpJW+s1cFoCCGoPE3WegOeNELDHFQoTRpJxFbJb+I6Bcq1oFe3oSEX+M13XZytw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795440349; 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=IrbQ8i8aTZJwqEFTPYxIAtIRVnnEMSD6z8Zy35LupKc=; b=osgD6juVLsgqh5Vp5Smf79cKjMiILKyG9z/mTFM23hxMOsNaGVot8lrambYftm3lmqqV smjnETNMSnP+LG1pLy/e/lXGlMmMbx86fZ77GFIbxdu/9X1ncqp7LLNa38XGljIAeneGm qwKgdsyZGt2fl5aPE21BPoJNwy3vzLk0OW/r0+mMY7aLvj4KbV+SuGFGGXZRuwlMaGHdI xL6X1V58ylwcNTH221jMruG+eO4lGls64RklmxAIMjNKsMWmk1alQJSXQd9e2DkYhaakj uSSV+BibBbngki41dcqZSCIRkv54WRKzDlFasDaogfdgSGMcXRuhrqb3lno5Oo63Q7Q== 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=DTcQleDY; 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 4ED6260A263E; Mon, 23 Nov 2026 13:25: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=DTcQleDY Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3305F1F00ADE; Mon, 23 Nov 2026 13:25:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795440348; bh=IrbQ8i8aTZJwqEFTPYxIAtIRVnnEMSD6z8Zy35LupKc=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=DTcQleDYln9ObBCw3rHUS1Wq2J948b5I00ifgB0Q79jUfmuhT2/+T81TYUt7qS1P6 kGyn5p6hG6znjV3QvdG169TAjcghuzReZHRG3wbmPecWvoJYD8qAhq222dqQoqgjzl 2GiRbgGDTMpExkf005u1KYW93GxJRqDDNNuG+zJxt/oFBEnBqHl0wMtUQbqp988L2T kI7UqK0ZnIAzkn98azH835LoHNsdoi/fexTYcMLJwQY8aos7XYrU7S8XqAUCU2BvWG nQY+CCrAlrWjYw/ttbdl4bHwli04g6ZhY9a134n1gNoQ3sTkQe3D6qGUNBZxeSitnE 9X1KAhcGQqGBA== From: "Matthieu Baerts (NGI0)" Date: Mon, 23 Nov 2026 14:24:55 +0100 Subject: [PATCH net 07/10] 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: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-7-278042217e8d@kernel.org> References: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> In-Reply-To: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> To: Eric Dumazet , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Mat Martineau , Geliang Tang , Christoph Paasch , Florian Westphal Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, Davide Caratti , "Matthieu Baerts (NGI0)" , stable@vger.kernel.org, Neal Cardwell , Kuniyuki Iwashima X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2491; i=matttbe@kernel.org; h=from:subject:message-id; bh=26GkYMliCyKie8HF17szUVNO9CI1DDDK2SXQg2Kmuhs=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLJZ7Pa+k59y9beyz88XJwxu3l92WJ1nOfOsxnkB+96L7 niu8kWxvqOUhUGMi0FWTJFFui0yf+bzKt4SLz8LmDmsTCBDGLg4BWAiWxkY/srPNDWrn/Nxf3Fh 5bFnjSy/JvRNNDjjO+/gpL/lyW+u3Q5nZPguN8dmPp/Vniwe37JJX9okpfqdNLOkbnbcCz31d53 GPDYA 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") Cc: stable@vger.kernel.org Signed-off-by: Matthieu Baerts (NGI0) --- Cc: Neal Cardwell Cc: Kuniyuki Iwashima --- 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 3144efad8c36..de23cdc89477 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1843,6 +1843,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 5675053625e6..5ed63d2d8976 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2422,7 +2422,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 @@ -2430,9 +2430,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:03 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=1795440352; b=uxPiiR3A9vJJSYdA2PqqpfdYsKHMJiI0MjbUBamHgbCC+c0BuS8O52m9Su9wv5/fXuzx CheAjn83WyJHln/Ps0BtBM2rAjibdgPY8KCuErKe8nZlX/1fbeTDOq76Fo37dvgYTmF00 acn0x+EuG8sybHvASZe1lSooUrQvu0FLiuBYiky45QxUxkxw1EnhgqNMjE76m2Ejtt+jp S6R6pUvUK6hQcumyjifVdfMhfYEPEasTUVPqhnsK4a8bHLoO16zUFYBgwQ3D+n3HYm4fN 15XhJfRxwfYz0W5nrbkkYFE09LqxVQGJeZpbyeVGfEwXyT4JKIMmbWwLpTKBXY1auIg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795440352; 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=agZbsxC8XRUaliCdELdXroftudvx5Dzam1Cf9BBH+64=; b=SUzfCRulywrFsnkinA/3GRBxaQJ3Hp1EdlsiLAmZOd2UlTmZSGkfcFKU7F9QhtTUXfWI P3+hgUlw+ZPVo7KQ3nYy8jPttK+9C6c/mUnHyJBO1wFaZ6m8s7RkfLEfNvKU/9QTz0dBJ tG7sHb7Pbur3axKtW6ImdKCoNn7/+ArtAYZcHq0bQBtAEtOvD40pB1S9O+rSQYaTGDAjX MONMJyXUuxlLOmQuxmFbNhBO93GVF4VDDlnvO1C3K83Sui+W3NhMZoX58IwBuFJcAfnZ1 8Mpoxj5EVol3ZZ8IHPoMdWbm5QrygEkZ7+IIsO6EfAkJGC8J2i/LkKtZfnn9/RKLO2w== 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="Xlicqqh/"; 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 A595F606A69E; Mon, 23 Nov 2026 13:25: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=Xlicqqh/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB11D1F02836; Mon, 23 Nov 2026 13:25:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795440352; bh=agZbsxC8XRUaliCdELdXroftudvx5Dzam1Cf9BBH+64=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Xlicqqh/Cw5bLJbN+HG52G3c4xNs1cTXM2eUWfaRMqdL8BsntEygAFQEJ8dRXPpmC 8Y81BOcGdTRlrsz4uDudVuS18KQNns1FMIC5YXeSjs2bdIDRYr6UfrVVNfeAZheAvn GHjOEMyW3ZDpQXeTry6Mh4iK2Z1uC3FFdy/OTfTdyBwXBzI+3R7jdXoBP+02I9uzf4 SV5CBphoyptb7mgzqdY7jujgjSYdcc2WZDivcZ1aeS5YEUrODG6qL+3dQsnDR0XU18 fRrGwX5GBgupI4zbj0bawQLKqt8memWF2YDnuNSAE1ZnOkFnzpaQlJFhpQDjz7qG1s r0Msn1ugu9QIg== From: "Matthieu Baerts (NGI0)" Date: Mon, 23 Nov 2026 14:24:56 +0100 Subject: [PATCH net 08/10] 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: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-8-278042217e8d@kernel.org> References: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> In-Reply-To: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> To: Eric Dumazet , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Mat Martineau , Geliang Tang , Christoph Paasch , Florian Westphal Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, Davide Caratti , "Matthieu Baerts (NGI0)" , Josef Bacik , stable@vger.kernel.org X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4454; i=matttbe@kernel.org; h=from:subject:message-id; bh=/+RpJZZCr+9fWGrIXW99TKLAy50OJBD8MN8jo5gWqtc=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLJZ7PY+49geMVVSJO1/wQ+W9ysC3k2Ya/fH5Dm/2t/Tu aHiW3QsOkpZGMS4GGTFFFmk2yLzZz6v4i3x8rOAmcPKBDKEgYtTACbS2MfwP8XG5vzrgL+c3Pk2 69QcjWfPMe8v7r3C+rDtzON7RScTnjD8d3PIusF7Yl662rRos38HGc4I8f23tNU0edch9XMv/2Q 9DgA= 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") Cc: stable@vger.kernel.org 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 20d506235074..3e674c21bdb2 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -844,6 +844,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, @@ -912,6 +928,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. @@ -1860,8 +1881,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:03 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=1795440356; b=OKPCtDQjUrhfjDHY7tRWu1DmFixYUsNVpUGbKKe6lCijjTZOinl5tpGA0gcQzb7yDrDu 4A542B6Epjw20FOz75xutc82Qr84b889n7RxW2hdnpx+EeFxXDGosxNfA1OXhiB1U4oGs NGn0XI1cRbcB52ego9xUNEipF6V+yiUZTPDlyNQ+HeKU5dCLwJalFz1nPFVj5FyOS3jCZ 75bDkJ/gleNxgkiq+LBWgV6O+LkgTmSM2Y7VVgGzdAGlQOaCGi5kLfun8YUBPQPkCxP60 oqQczVAd/DkLS/0qM4nEOlH7KuwoxAWTGfcAjS/bf/K8NhJVsogjnddAbgfOVXrKynA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795440356; 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=Vo5WUJPjTE8BWwdri/c1H0F7M+oopPW8vIab7gd30TY=; b=UitVBLQNrqim8H0iRRqE0iaqlHINoKmiurLx8OXWRX9i1qIAr4wq+EbExso4Vr6y+5cT vy8czpw2kx2Zep98HcCkVJF33sCIL4fhk1Q9Mgo6ykN1ZGHHN4wPk3IB3QXWvFWRDDCln +zcHU1bKVAz4RqlCKGON9twbEwtQGhAGQjuwhljBXep0xrF/yK2hWh6S15XOp2LdrZ91R vJFCChS4yX/bDGQoRzffNwBBxgbL3oiYNeziplAmdkSS4QQra6FxATLymyG2fVcfjfRje gu4cyQNXjj25Qae7KtodGr+fI7Yd0VYM7VluC7ztHoVlIPM+5MHNQLU2E2OEqyVKiCw== 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="Irmlc/mO"; 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 C749460A2600; Mon, 23 Nov 2026 13:25: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=Irmlc/mO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96E5A1F0283F; Mon, 23 Nov 2026 13:25:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795440356; bh=Vo5WUJPjTE8BWwdri/c1H0F7M+oopPW8vIab7gd30TY=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Irmlc/mObBKbg5o5DVhzTlWmm2RLuoFwetcxyrvsqnhMh3i1CY/FGxpQrGOE3XuQf wd3MbXeqaq57yn1dq0ToNmffm0Vc0S5LTbX3K2VUW+FfvUlDKf3ozjJQPbz62QyxQH CvbcSzVL3nTdTBHhsGXSCczIiVEoSBwZHKE4HNKs7RVD5ImsS1mqWJrkW9Y8MurchP rGhGwSCBC0si8xgVuvmZN2rym/4Aozm8BoKjvMlEGS45BjRtFVD3V1qCVjdGR5LoUj 8O/NN3gGYvFGbiwzxz4zvrUHvaSWSaYirMyjjEQ0LIX+sUhMih7PGwLKp0pAEfahNp +QwPX4naL/NFw== From: "Matthieu Baerts (NGI0)" Date: Mon, 23 Nov 2026 14:24:57 +0100 Subject: [PATCH net 09/10] 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: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-9-278042217e8d@kernel.org> References: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> In-Reply-To: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> To: Eric Dumazet , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Mat Martineau , Geliang Tang , Christoph Paasch , Florian Westphal Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, Davide Caratti , "Matthieu Baerts (NGI0)" , Chris Mason , stable@vger.kernel.org X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2879; i=matttbe@kernel.org; h=from:subject:message-id; bh=qc4IGFaSg5Eh0l/L4vMsKDmfSUE8oIAs7yqqnNJAt+o=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLJZ7PYdSFZWXst0r6p96835aXNS8uOPBu3SF9x4eJ2op dcP1kNnO0pZGMS4GGTFFFmk2yLzZz6v4i3x8rOAmcPKBDKEgYtTACZy2IDhn86CNXzGC9mn3ch8 McWj4qCI+dHgrVzM7xvfhX39s6xwz0xGhpb8e6ZS8SkXp36sO/qnyU3rgmnR8R5BbqtfdYcnHMo 4wQEA 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.") Cc: stable@vger.kernel.org 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 3e674c21bdb2..054ee992904e 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:03 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=1795440361; b=rSRP94BpseKb4DtlE5wQgdLg9tf5VQEOvGjDd/DXup24Q1xBM9XMK8XkSfOTqPUSIQXI dSRKaWcHiMADOzftdQSOra3o+X+a/QZBcLF5h0yrc6YqKDkxe4w584V7E89bL9AguY8dQ n/3H4mZt9q29v40Kmuv3O26De8mMakYXx6AQFC2r/139uJ6K5TJ1nigtN/CDFVp57Xpbd rhXEPVqRm6z5wEqKdkf77TVVlshT6o7GZXK5cpCbxbyH9ns844nXH8th4iZPCfJh4vKZ6 Y4nkqaQ1kiNIWFk31coOOusLsJ65x/poWxlsIT8/ddMRbcpzfcfMkm4pqTKOKthkskQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795440361; 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=OM9cxLva7+iCHRXvRYtfcJWoubk8pCI/HEM5nYTnVxw=; b=0Tp/gDKgwM63+TVgVst1+qu6Avlvk9HTQMCN9Qf6p0+H80jsQIne1gmahFLntWSQsbkM +v16I+zUy3aQxRKTFItsqHTT91a9ElIBpXaRfCgLR6qv2nnRYAO7V7r8OlnJGyG4gM76Q PZbGNSjMBogpRMZxDTNS3tz+p1PI9pwrBUfJ3C3Ql7/swakDvCm1Pp3KkNkqaJFnqXFED lqk7lL970up5gfhCC6QTPbjDnoKKZGmPahTnL7748rZGoZeWB6HeSEImGHArSyvLZqHJk 2pDcRhVtFqYficwVclLUoz0xWrq8jaga4AFvLhmKBAU89Rg0pELtVnasTEPs4atIfgQ== 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=GMTalLWH; 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 818E6606A338; Mon, 23 Nov 2026 13:26: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=GMTalLWH Received: by smtp.kernel.org (Postfix) with ESMTPSA id B55331F000EC; Mon, 23 Nov 2026 13:25:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795440360; bh=OM9cxLva7+iCHRXvRYtfcJWoubk8pCI/HEM5nYTnVxw=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=GMTalLWHlpBbiC1qadH//eEXuGf0DLWVEuQthel5DItykAlkId33T10DP0z3BIFd7 dOBGttsQ/9iIJk/4Wt9paltLPCdSkrJbMt5hqVXr0OI83XqGuXDM9jChr/DL/M4xQj 4xlidmLE0BHc/AdFmPtg4d4/HEhC6kRZD/Qv62071pZTeMcjJtX7eow8I1P4vZzA4H csrynoe8aq8MHbDFClGKdTIw0OX0pwth8HUepRqEqqnbj4vYmXOfh/ng/Lb//ARiwX laNmLoUMm/9PqpQ9O9XQdHrEnCi/E3/noT9EY4+dufymPestfDeER+5HJr8BrJldKs Sb9msHS+JorjQ== From: "Matthieu Baerts (NGI0)" Date: Mon, 23 Nov 2026 14:24:58 +0100 Subject: [PATCH net 10/10] 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: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-10-278042217e8d@kernel.org> References: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> In-Reply-To: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> To: Eric Dumazet , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Mat Martineau , Geliang Tang , Christoph Paasch , Florian Westphal Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, Davide Caratti , "Matthieu Baerts (NGI0)" , Chris Mason , stable@vger.kernel.org, Neal Cardwell , Kuniyuki Iwashima , Martin KaFai Lau , Daniel Borkmann , Alexei Starovoitov , Martin KaFai Lau , bpf@vger.kernel.org X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3565; i=matttbe@kernel.org; h=from:subject:message-id; bh=PbiCcpJTknsoj+MJd4lAx3wSs1KXnS473ThstyaOxCs=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLJZ7PbfDpQX1lSq/mMTlvy24fkK1QOP/68N5z0yY7l7I e+e5JjfHaUsDGJcDLJiiizSbZH5M59X8ZZ4+VnAzGFlAhnCwMUpABOJFWH4HyMceTyJP+/y04ch GhrfLx7/esP49sSwLj53n1qlsGuHZjIyrE42P6aU8914mW9P5+85RlpMLZH1YhMe1H2d8aFIL/Y NPwA= 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. The connection then fails, instead of corrupting the memory. 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.") Cc: stable@vger.kernel.org Signed-off-by: Chris Mason [ Shorter comment. Commit message: how the issue was found, its symptoms, and that the connection then fails. ] Signed-off-by: Matthieu Baerts (NGI0) --- Cc: Neal Cardwell Cc: Kuniyuki Iwashima Cc: Martin KaFai Lau Cc: Daniel Borkmann Cc: Alexei Starovoitov Cc: Martin KaFai Lau Cc: bpf@vger.kernel.org --- 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 89169c82431c..f39600ee3f17 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -312,7 +312,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