From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796221191; b=cHOJbiqDuZd31UFquEduDe2LmS0s8+77jsX5A4wtiV763WxJrEKBlq3SgTNJCS2lGlAB dzr35OSGaomVZzc/T5Z1Pzg0f4DL1NBlgG8CNr+l9JyptPuMVbi7ubhZMgO9i5mMdB7Rd v+jMM/B6zXrCFR5bw0PAxmn6cyY8S+g8zWDvYZU/CUI4hpB0BGernQnUrAdvmoWSWm7N3 ueDo8y1P5x7oAccZ4pTomZASb0loh4aeygb/H+H/MCBKPkzA0GUbH3b+Iv3EDUSw5z/7Z UAtdR2v/SiPErpYbXLj9hZZu6+18Aq8rAP9aBiQCe9LVGq784lf9PCis8U/mnxEXMxA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221191; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=EFAserwwtbnR73PrATXErVpHpFBqhFH8+07AQJlJqBs=; b=R340HeKzxouPUoIN5zSL9VK804k7fhNB/oFDdoSU6OID9Vi44aYYBQGKL2KRJeXQrnbo f2W6JPw0Bco8UWfZNAXrHlwsUUZ/IYrZWFkgB1uHKKKe9CwHICVF0sRKMWteJq3+jT6jE 86JNjlc2Ya5NzAu+Ja66IydXSn1umvifPxtnuDRS1jvpNJlbC5gfHjstc3Pr2v7FCFlMq NTG8a62Fb2RLcJHvRMzpubXY1JDRULX8jBssRW1jg/BiHkplHSIklypodwfrB09Fhytoc TTstmWgtG06thRo5KB2tbER3BFYqjewznBMoSGZsiLp/qXHGug85Y/RYfyHhtzPuJjQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=OqG2xUtg; 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 58CCC606A327 for ; Wed, 2 Dec 2026 14:19:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=OqG2xUtg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64BE81F00897; Wed, 2 Dec 2026 14:19:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796221190; bh=EFAserwwtbnR73PrATXErVpHpFBqhFH8+07AQJlJqBs=; h=Subject:To:Cc:From:Date; b=OqG2xUtgS1/r13o/wwKt2ON8uIkcNG3rUf5A7xaIz20kkbxDc6phU1sCdlPDnrZza BtcXnHiuwcHCWwPpRLRTPgQDYYn0M4d2eOF9esqC7PBdu1dHjVr3/3ny59LDTuEcOo BY1rXxOtaT/QIMAWdi22ROxU6jPINW7IExFJNGgA= Subject: FAILED: patch "[PATCH] ipvs: avoid stack overflow from recursive connection" failed to apply to 6.1-stable tree To: zihanx@nebusec.ai,ja@ssi.bg,pablo@netfilter.org,root@tr0jan.top,vega@nebusec.ai Cc: From: Date: Wed, 02 Dec 2026 14:14:14 +0100 Message-ID: <2026120214-payable-outback-0558@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.1-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y git checkout FETCH_HEAD git cherry-pick -x d4e4cd04de2c47ed05f837a26edd20c56be3f097 # git commit -s git send-email --to '' --in-reply-to '2026120214-payable-outback-0558@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..' Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From d4e4cd04de2c47ed05f837a26edd20c56be3f097 Mon Sep 17 00:00:00 2001 From: Zihan Xi Date: Mon, 5 Oct 2026 13:06:18 +0000 Subject: [PATCH] ipvs: avoid stack overflow from recursive connection expiration 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 Co-developed-by: Luxing Yin Signed-off-by: Luxing Yin Signed-off-by: Zihan Xi Signed-off-by: Julian Anastasov Signed-off-by: Pablo Neira Ayuso 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.