🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25976

[PATCH net 4/9] mptcp: count orphans as TCP does

#25976
From: "Matthieu Baerts (NGI0)"
Date: Wed, 02 Dec 2026 21:29
105 lines
12010 bytes
The MPTCP sockets orphaned by close() were not counted in
tcp_orphan_count, contrary to TCP: tcp_max_orphans did not limit them,
and they were not visible in /proc/net/sockstat.

This is all the more needed since commit "mptcp: keep an orphan while it
can send its data": an orphan can then be kept longer than its close
timeout, e.g., as Sashiko noticed, by a peer acking the data at the TCP
level only, without moving the DATA_ACK.

Count them, and as TCP does, reset an orphan when there are too many
orphans, or when TCP uses too much memory: at close(), and when its
close timeout expires while it is kept to send its data. This is similar
to what tcp_out_of_resources() does from the TCP timers, without the
stricter limit for the stalled orphans. These resets are counted in
TCPAbortOnMemory, not in a new MPTCP counter: the MPTCP orphans now
share the TCP orphan count and limits.

This has been found by a review agent, and validated with a script
closing 8 connections whose peer doesn't read, with tcp_max_orphans set
to 4: the MPTCP orphans were all kept, without being counted, while
other orphans were reset. Now, only 5 or 6 are kept, vs 4 or 5 with TCP,
which also checks the limit from the timers of its orphans.

Fixes: e16163b6e2b7 ("mptcp: refactor shutdown and close")
Cc: stable@vger.kernel.org
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/protocol.c | 24 ++++++++++++++++++++++--
 net/mptcp/protocol.h |  1 +
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 96b3baef341f..fc8aad7e2fde 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2840,6 +2840,16 @@ static bool mptcp_subflow_probe_timed_out(struct sock *ssk)
 	return ret;
 }
 
+/* As TCP orphans: limited in number and memory */
+static bool mptcp_orphan_oom(struct sock *sk)
+{
+	if (!tcp_check_oom(sk, 0))
+		return false;
+
+	NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY);
+	return true;
+}
+
 /* Before its DATA_FIN, keep an orphan while a subflow can send its data */
 static bool mptcp_orphan_keep(struct sock *sk)
 {
@@ -2857,7 +2867,7 @@ static bool mptcp_orphan_keep(struct sock *sk)
 		    tcp_jiffies32 - READ_ONCE(tcp_sk(ssk)->rcv_tstamp) <
 		    2 * TCP_RTO_MAX &&
 		    !mptcp_subflow_probe_timed_out(ssk))
-			return true;
+			return !mptcp_orphan_oom(sk);
 	}
 
 	return false;
@@ -3490,6 +3500,9 @@ static void __mptcp_destroy_sock(struct sock *sk)
 	sk_stream_kill_queues(sk);
 	xfrm_sk_free_policy(sk);
 
+	if (test_and_clear_bit(MPTCP_ORPHAN_COUNTED, &msk->flags))
+		tcp_orphan_count_dec();
+
 	sock_put(sk);
 }
 
@@ -3579,8 +3592,15 @@ bool __mptcp_close(struct sock *sk, long timeout)
 	/* all the subflows are closed, only timeout can change the msk
 	 * state, let's not keep resources busy for no reasons
 	 */
-	if (subflows_alive == 0)
+	if (subflows_alive == 0) {
 		mptcp_set_state(sk, TCP_CLOSE);
+	} else if (sk->sk_state != TCP_CLOSE) {
+		/* as TCP orphans: counted, and limited */
+		tcp_orphan_count_inc();
+		set_bit(MPTCP_ORPHAN_COUNTED, &msk->flags);
+		if (mptcp_orphan_oom(sk))
+			mptcp_do_fastclose(sk);
+	}
 
 	sock_hold(sk);
 	pr_debug("msk=%p state=%d\n", sk, sk->sk_state);
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 7644651f01a8..05bf9c3f11b4 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -117,6 +117,7 @@
 #define MPTCP_FALLBACK_DONE	2
 #define MPTCP_WORK_CLOSE_SUBFLOW 3
 #define MPTCP_RTX_ENABLED	4
+#define MPTCP_ORPHAN_COUNTED	5
 
 /* MPTCP socket release cb flags */
 #define MPTCP_PUSH_PENDING	1

-- 
2.55.0
Technical Details
Message-ID: <20261202-net-mptcp-misc-fixes-7-4-rc7-v1-4-9f03efcb1a17@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376064-linux-kernel-netdev=dewy.ru
References: <20261202-net-mptcp-misc-fixes-7-4-rc7-v1-0-9f03efcb1a17@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376064-linux-kernel-netdev=dewy.ru
From: matttbe@kernel.org ("Matthieu Baerts (NGI0)")
Newsgroups: linux.kernel.netdev
Subject: [PATCH net 4/9] mptcp: count orphans as TCP does
Date: Wed, 02 Dec 2026 22:29:34 +0100
Organization: Usenet Network
Message-ID: <20261202-net-mptcp-misc-fixes-7-4-rc7-v1-4-9f03efcb1a17@kernel.org>
References: <20261202-net-mptcp-misc-fixes-7-4-rc7-v1-0-9f03efcb1a17@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="2066055"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:PgsJIgw76qroMRHIR3fYAnTPRLs= sha256:rZzlv2IGJKULOTpwI9KgfZJe7Ya4V+llR5O0xavEiSw=
	sha1:PlxU5kGGHNFzFDng/JLImsKteeE= sha256:Uh0ZgAc6mfeB/F4W4sImKZRhmXATg+vKzgdR1dndiF4=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id ACD0C117737; Thu,  3 Dec 2026 00:32:37 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id Ezb6qTb2VP81;
	Thu,  3 Dec 2026 00:32:35 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-376064-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 95DB3117723; Thu,  3 Dec 2026 00:32:25 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 0A595244DB; Wed,  2 Dec 2026 21:32:20 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796247131;
	b=EXo6oKk3V5TJvRnlJZSbEZFncBb10kQVDD/4u4jGjimeaKBZkj6lkndZiIb0LQWQKICa
	 rMybFrl+jP+ZYXLDVvPoUPpeAJTpTXR9sWxQ83edk+VU7xUKuUQS95cEjVK+ujrQE5DKh
	 xP59q4f78iixp6UALCAFFMT6k8G5dlSKPq5J1k/3ZdaJKvGYBuKNu2Ip6Qeouzfg0q0fD
	 HMOX1B5aWKvbAoiFmLqSRRMk0nuomDHiv54LSgHUoboBqZqtJJJIZyJby7SsjtF/7xJFe
	 QfY3I9OqG3BmG+I0BWPN+rW7LQff76X0xRrOZ0mZAYagSYvt5kUEwrjOfgS0mYdkQxg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796247131;
	h=X-Original-To:Received:Received:DKIM-Signature:From:Date:Subject:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc:
	 X-Mailer:X-Developer-Signature:X-Developer-Key;
	bh=u2bf0jjqHgh4O0E12PwCIkTQklMDtPRdhhCZQc2OIMI=;
	b=qFdFyKMfB1wTavHEOC3xbDlV5kzxTS5p7AuiSo7zxnuO6qVMmZ0Br4N8XP6HHErEvboi
	 BTqofWTP7uZg/Ddr4btf10YYsELOEVhpp/neNuIOLc7BhR8YehlcwDGPNN+8Dda1mdddw
	 tkA0ZwsdQjL7w2rrdgrDzxIglZyexx1FQpTaq3rKA2PfUlyA5z7zcTeaZYpPCjkrNkWTn
	 XTuBPOwNDp8Yt2SPZ/4ObbIHdSvLHIOE4j62pr5Iq58fvc0pED6+eh+dQRCWIX1YPYF9P
	 S+dgfPhqDEGIvL/bAzq2hpmRqvAg/Q8VQHbFE6ZqdyNLjLn+s2hOAnq4jYjEWFslPGw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ZSxuhZ58;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 878F0606A6B5;
	Wed,  2 Dec 2026 21:32:11 +0000 (UTC)
X-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=ZSxuhZ58
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796247122;
	b=Wjh7HUNiLKA0nsixy86aOKFqsKSnVY1tjzxwxW3GDjsDKBSBst1m71UCV8WD+oOglioL
	 prO88n1+im5NcDgo1cVIB0JvX8hMne7zoLCswkNjJjIFGkS2IrQ2QEps9PdZ3zOXqKlkk
	 DhB3oyEGHyuMZDRQ3suK+gnlW5rr3Tk7dV/Bs+QJxbrJ3vUA6Qfh+M90kKFFuwMBUht9g
	 jHXnEMWx1o4tm84zOGApP9rnNWtcPxWp2JnNpP+LRJ6R8kHGiSnmcUWqTnf/t1ay81DxJ
	 lVVoyvw96MgVP32m4SCnz5pUT6FoUWMRdKwdJcqhxYuwsBcba7B4icuRPJNzk1tK7MA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796247122;
	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=u2bf0jjqHgh4O0E12PwCIkTQklMDtPRdhhCZQc2OIMI=;
	b=F76eyU1dYFHy/fVZYV9upyxqILSr35j21Szh425iZ3WpfOd1RVp9xFjJK5Mo8iL+Qu1t
	 l+OSztWo0uMOXLx7z3i2IoJPG3G4HdMCNAVwNL0mV/FRs71qB23jljbm4dvP9z97Xo4Og
	 JSt8la/KcsnPFvBa2HeRIffiijYTVvp0jDNqMSLKfMYeQrA7Qk3epiXZIj91Vg1xsGres
	 AemmyscykZ3hkFAKEwlffWXWR9b4aDqe0MXVdxIqSC7SusU5FqkYeDb9fJ6Z4njhRvcw7
	 aX4FcigzJBiwJynwvvBQKhlacToTiOr5sn0j3kJ/Qbu0asy5cbyJxAFYOWy7FXTwxFw==
X-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=ZSxuhZ58;
	arc=none smtp.remote-ip=100.103.45.18
X-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 99300606A32C;
	Wed,  2 Dec 2026 21:32:02 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22E161F0089B;
	Wed,  2 Dec 2026 21:31:59 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796247122;
	bh=u2bf0jjqHgh4O0E12PwCIkTQklMDtPRdhhCZQc2OIMI=;
	h=From:Date:Subject:References:In-Reply-To:To:Cc;
	b=ZSxuhZ589FM7PjyibaGKFQsj6bQr7yLG8lEN61sqUFuJfFXmCbUunptH1W0IIohj6
	 y1VXHlg+uj3TOLn/vB7NPcxUtCSrjDu5pgNVJ+3uCP4mdoQECZbsKP2meXcJdrOc09
	 xbIpE+vONkDmWQ1RKQxrEWifEom3rrlkQomyDL/SdjR35zAiEzBt/HSKzDONtFXHi9
	 t9GqjbNxbdu6AmKFUo+nGxLEtqqrzYzRQCzz2VR2z/Y7LtRpXetPrP0gE4uX4BRGEX
	 /Kg2wPKXTw0KW5XWCWmqvuddpg+UdRsdhzJqe5fztYGQy3xioVlWjeZVKFAeyGe7xx
	 XaRSK84e042Ew==
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261202-net-mptcp-misc-fixes-7-4-rc7-v1-0-9f03efcb1a17@kernel.org>
X-Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, 
 "Matthieu Baerts (NGI0)" <matttbe@kernel.org>, stable@vger.kernel.org
X-Mailer: b4 0.16.0
X-Developer-Signature: v=1; a=openpgp-sha256; l=3756; i=matttbe@kernel.org;
 h=from:subject:message-id; bh=sSAB7RD9RGdiCvZe2ar3HxWs8pDGmr0zoTs2PMc/vEc=;
 b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLIF+uwfKLIFm5xQMfKbY/on36s5xKOS74Ni0+cPYXN/V
 stIOOV0lLIwiHExyIopski3RebPfF7FW+LlZwEzh5UJZAgDF6cATGRaASPD5jkz5/6w5RH3XH3t
 acuxtRMts2QZemVXlC+8/vTanZ2hEgx/pVqdJz3e5x22XIDpqMWS/HMRB/0Ftk7u0lczqlF18C/
 mBAA=
X-Developer-Key: i=matttbe@kernel.org; a=openpgp;
 fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073