🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #16869

[PATCH net 02/11] ipvs: avoid stack overflow from recursive connection expiration

#16869
From: Pablo Neira Ayuso
Date: Mon, 16 Nov 2026 00:43
134 lines
12660 bytes
From: Zihan Xi <zihanx@nebusec.ai>

When a controlled IPVS connection expires, its controller may be expired
synchronously if it has no remaining controlled connections. A chain of
controlled connections can then recurse through ip_vs_conn_expire() and
exhaust the kernel stack during namespace cleanup.

Continue expiration with the controller after the current connection has
been fully cleaned up instead of calling ip_vs_conn_del() recursively. Keep
the expiration walk under RCU, preserve the immediate-drop timeout for a
controller with its own controller, and switch to deletion mode before the
next iteration.

This keeps controlled-connection cleanup synchronous while using one stack
frame for the whole chain. The timer callback race during connection
deletion is handled by the preceding connection-deletion fix.

This patch depends on "ipvs: fix problems during connection deletion" to
protect the iterative controller cleanup from the timer callback race.

Fixes: f9200a52eedf ("ipvs: avoid expiring many connections from timer")
Cc: stable@vger.kernel.org
Reported-by: Vega <vega@nebusec.ai>
Co-developed-by: Luxing Yin <root@tr0jan.top>
Signed-off-by: Luxing Yin <root@tr0jan.top>
Signed-off-by: Zihan Xi <zihanx@nebusec.ai>
Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/ipvs/ip_vs_conn.c | 40 ++++++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index 86c5e6c7b5af..27db8d558a03 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -1336,9 +1336,23 @@ static void ip_vs_conn_rcu_free(struct rcu_head *head)
 	kmem_cache_free(ip_vs_conn_cachep, cp);
 }
 
-/* Try to delete connection while not holding reference.
+/* Try to steal the reference from the pending timer.
  * It can be called concurrently and always under RCU lock
  * to protect from connection deletion from others.
+ */
+static bool ip_vs_conn_del_reference(struct ip_vs_conn *cp)
+{
+	/* Steal reference from the pending timer */
+	if (!timer_delete(&cp->timer))
+		return false;
+
+	/* Drop cp->control chain too */
+	if (cp->control)
+		cp->timeout = 0;
+	return true;
+}
+
+/* Try to delete connection while not holding reference.
  * Used when we need to remove the connection immediately
  * and without overloading the timer processing.
  * OTOH, we use ip_vs_conn_expire_now() when we prefer to
@@ -1347,13 +1361,8 @@ static void ip_vs_conn_rcu_free(struct rcu_head *head)
  */
 static void ip_vs_conn_del(struct ip_vs_conn *cp)
 {
-	/* Steal reference from the pending timer */
-	if (timer_delete(&cp->timer)) {
-		/* Drop cp->control chain too */
-		if (cp->control)
-			cp->timeout = 0;
+	if (ip_vs_conn_del_reference(cp))
 		ip_vs_conn_expire(&cp->timer);
-	}
 }
 
 /* Connection is removed in the following steps:
@@ -1366,6 +1375,9 @@ static void ip_vs_conn_expire(struct timer_list *t)
 	struct ip_vs_conn *cp = timer_container_of(cp, t, timer);
 	struct netns_ipvs *ipvs = cp->ipvs;
 
+	rcu_read_lock();
+
+repeat:
 	/*
 	 *	do I control anybody?
 	 */
@@ -1375,19 +1387,18 @@ static void ip_vs_conn_expire(struct timer_list *t)
 	/* Unlink conn if not referenced anymore */
 	if (likely(ip_vs_conn_unlink(cp))) {
 		struct ip_vs_conn *ct = cp->control;
+		bool next = false;
 
 		/* does anybody control me? */
 		if (ct) {
-			rcu_read_lock();
 			ip_vs_control_del(cp);
 			/* Drop CTL or non-assured TPL if not used anymore */
 			if (!cp->timeout && !atomic_read(&ct->n_control) &&
 			    (!(ct->flags & IP_VS_CONN_F_TEMPLATE) ||
 			     !(ct->state & IP_VS_CTPL_S_ASSURED))) {
 				IP_VS_DBG(4, "drop controlling connection\n");
-				ip_vs_conn_del(ct);
+				next = ip_vs_conn_del_reference(ct);
 			}
-			rcu_read_unlock();
 		}
 
 		if ((cp->flags & IP_VS_CONN_F_NFCT) &&
@@ -1414,7 +1425,11 @@ static void ip_vs_conn_expire(struct timer_list *t)
 		else
 			call_rcu(&cp->rcu_head, ip_vs_conn_rcu_free);
 		atomic_dec(&ipvs->conn_count);
-		return;
+		if (next) {
+			cp = ct;
+			goto repeat;
+		}
+		goto out;
 	}
 
   expire_later:
@@ -1429,6 +1444,9 @@ static void ip_vs_conn_expire(struct timer_list *t)
 		ip_vs_sync_conn(ipvs, cp, sysctl_sync_threshold(ipvs));
 
 	__ip_vs_conn_put_timer(cp);
+
+out:
+	rcu_read_unlock();
 }
 
 /* Modify timer, so that it expires as soon as possible.
-- 
2.47.3
Technical Details
Message-ID: <20261116004404.2821183-3-pablo@netfilter.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363951-linux-kernel-netdev=dewy.ru
References: <20261116004404.2821183-1-pablo@netfilter.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363951-linux-kernel-netdev=dewy.ru
From: pablo@netfilter.org (Pablo Neira Ayuso)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net 02/11] ipvs: avoid stack overflow from recursive connection expiration
Date: Mon, 16 Nov 2026 01:43:55 +0100
Organization: Usenet Network
Message-ID: <20261116004404.2821183-3-pablo@netfilter.org>
References: <20261116004404.2821183-1-pablo@netfilter.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1945180"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ZweIjLdswKMjCqRgziD1n6s8UuU= sha256:ijpe7gPevQcuLJ/i3R/22HWZunSXdfPsGZntoYM4ADc=
	sha1:gabOjRQfM+19edfXcD6raQZYQeg= sha256:Qfe0vLx0ZX1cFlUN6DaUTcd7MKoixNMJ68fBb3eeI3Q=
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 165A0114AB9; Mon, 16 Nov 2026 03:45:08 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=netfilter.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 0MB5esAFpPe2;
	Mon, 16 Nov 2026 03:45:05 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-363951-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=netfilter.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id BFD8F114AD0; Mon, 16 Nov 2026 03:44:56 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 2637335197; Mon, 16 Nov 2026 00:44:29 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail;
	t=1794789862;
	b=WeMAZ50eLtZ11/LforcLJ9nb4VGrQbDyXKmhgJGBH84iKVj6o2MK64Y7hfKSTQGBpBq1
	 KDRSL9YUjw68t/3KYuBP0ris01xzsUDRDuSY2Q4jA7bfpqDJjReq6w0yov+r3U3LUr1L6
	 92hTbSdywhR93u4QeL2/wgfaXE1aZGJrhpbpVBtaldSlKS38cww6QL+ebrDALBFEwplcl
	 i8RfGx/5Ii/+c6xwmGuhTlB+jsbziOB8fpizGzQ2ry7pjRxti/QRcqTyPGOqMkryos5Lb
	 IN6LcPUlU63vPS+wRg99LuX6MOhMCyVk8kd9hWQlgBnpBwh/Nujr9Djdak96CcY7uoA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794789862;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:To:
	 Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=DqYZNzAk0qOqQDAvzyRhmwlg8184xMVw/vNC+P20nIA=;
	b=Hyny/HMaIG96U1IyD/qVQvqbb7IoWuRjKggmhqYIWSn3jb78fJzW2NBqsDuO9pCScVdi
	 aV00FtYzhaJQL0aMvSLD7ROrZxYAM2y1rplEZlfJv9TDHLvzEZPcSUefXHwfx8xwwMmja
	 SV4ipQ/DeuEOFsueorzRk8wUBj6MU1JpzybQik20/+bKweE5EQNfNOMrXnI+y3KbTItGu
	 M8/8eWFwsS+mXbGH1Lk21fexxjMviFQOR1Ls2Kgno3Uw6VjpSCCNL2qOUNlOW6qSFtB4X
	 rcCvfxYSCz2e7kFJB+lB9URmrRjBbAx8V2esfaGnNm+DOY8R7FOj/KG9tik0N2LqKFg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=netfilter.org header.i=@netfilter.org header.a=rsa-sha256 header.s=2025 header.b=WUWJHLUR;
	dmarc=none header.from=netfilter.org;
	spf=pass smtp.mailfrom=netfilter.org;
	arc=fail 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 DA9CE60A2600;
	Mon, 16 Nov 2026 00:44:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=netfilter.org header.i=@netfilter.org header.a=rsa-sha256 header.s=2025 header.b=WUWJHLUR
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.70.190.124
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794789857;
	b=XS027jtN+VAOEZoOrn/U1X4hlNDzjWMCLRPmYP/4deRoca06KJVhU1dSufjm8abfa3wP
	 na5e5qX7HkhZLcKX/zmO4DW8w8bX74UPyrnkEYGMRATcsAWw5KJExX1fFDJhUrA2uCaRm
	 r8RhA5d9kKePHE1ajR97tmlE5PAY0uYKneSzGRIUnd/zBtjiOxplhPPWtCSnvkb//O1NS
	 RksYyHhIMkPKeq8KRnCgVlCSpgtkQvJkFywQUQDIi1e3TT3Mpa7Z7aPlzgqNDO/yZiO4o
	 UWB/8vc0yxXwYXn3fqVcpWyJayrL8LXiZZhMGDgA6Jqf+66oUuWDuW2e4txZ91pjFgw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794789857;
	h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding:X-Spam-Status:X-Spam-Checker-Version;
	bh=DqYZNzAk0qOqQDAvzyRhmwlg8184xMVw/vNC+P20nIA=;
	b=LgBAxRGY0oynVTgpR207bF0K84lBRCW3Qt84E6KxtYSL37fJ0+kwSgoKOwNfK/qstkZ3
	 Dkm1wd2fPE/JyMERKDK/Df6j/U8833T28uPfro+S3w6q3vCdxArQqrwRF4Hxy57/i30VY
	 VJ5EqcAIZ8g6WXqVwiLsfaTtk62TIyjlMfb+p2QWuOaSAj+MQgipzwnzVPQfGmnr17isr
	 QZw2A9SebvbhB3KmfAEiya+hky3IhvK/tw7z+DQB4tXX0NjyS87vVbzpOLlIF9N1gY3LY
	 mgBpCR0BBuSXrlfg117GifzWJuhXhiDJcisYdh+HHY7ZyAFGijb9sBTTfw319r/gFZA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=netfilter.org;
	spf=pass smtp.mailfrom=netfilter.org;
	dkim=pass header.d=netfilter.org header.i=@netfilter.org header.a=rsa-sha256 header.s=2025 header.b=WUWJHLUR;
	arc=none smtp.remote-ip=217.70.190.124
X-Received: from mail.netfilter.org (mail.netfilter.org [217.70.190.124])
	(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 9000A606A33A;
	Mon, 16 Nov 2026 00:44:16 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9000A606A33A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=netfilter.org
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netfilter.org;
	s=2025; t=1794789854;
	bh=DqYZNzAk0qOqQDAvzyRhmwlg8184xMVw/vNC+P20nIA=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
	b=WUWJHLURYNpRgRmxlVnFiow8o941my/t2JgLoVo9KPofa+FRDku+iVYXYKCWzIcsj
	 hst18/2KRB8WEOZLvBDjpAg0UJRd+saUcUzrg/VuNIVbOCzd7h4lWr+4nupjnauzpk
	 U9fXjRuVymQtNU5eI2Ct55Qt5fUJiczGz+y/449TKQ0VLOpa1z0KBMWiiU7ZqXXdlU
	 9kF764wE2kfjUUa2c7SmzkJWU3mvKnBh7HGGMJCqhBs6doVzJHPUNAH/DVjxYyiCbf
	 o8XX57pBaCPCSAXCJJTcHSoqBjq2/tqTo960TrBkcYeHzxwiuZPAZTGyCzVNTrFgwg
	 c/kzmIZXZM+sw==
X-Received: from localhost.localdomain (mail-agni [217.70.190.124])
	by mail.netfilter.org (Postfix) with ESMTPSA id 02DBD6005F;
	Mon, 16 Nov 2026 01:44:13 +0100 (CET)
X-Cc: davem@davemloft.net,
	netdev@vger.kernel.org,
	kuba@kernel.org,
	pabeni@redhat.com,
	edumazet@kernel.org,
	horms@kernel.org,
	fw@strlen.de,
	ja@ssi.bg
X-Mailer: git-send-email 2.47.3
X-In-Reply-To: <20261116004404.2821183-1-pablo@netfilter.org>
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