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=1796381516; b=0f1lVguf6EE0dsqR4gPOJ2qDCTS2zOd4MzG6AbP/WZBBilc3r+cezmlBwvHxlU3y7h5H Y5lMRoO6pLEGywLsuC3X7OAXycA6M0ZihuLD2ww0aAWuXHQsF4y79Yh39AU8gCuUztg6P chZ7iQuPLIsUI/SZVUMsTN+aOPBmq3WHk8swXd8u9h0tqzQwCU6BvVHdZcjT7gkZGyGjS oDuhF+SxqxvYWpUu3aG4lbzYKyLju/y4KzjLBRApxbSRKI2IawadLAVyxGFnPqP6VBzN+ TuqwtUbby7s/RYZavlVLLbGCT6K4ozkLrPh6buFdw2uCerzer00X5vno4B4QBodYCCQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381516; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=1Xb3aZiivwzjPNUvfFgUFWc2P+2HE5KQQACgxpd27IY=; b=nJ66JXOYLiO+gO7ccNqfq6FqbTqiH5Zv1Lyx9jPs9RVdm7KAAx5z02ZZKvNroIqo7w0K 7eH8e81JuGgM0RouTP6SK+lbkHZs9DwoE2dEguZKmfpPBGSPq26U8tXdEooYqyBDcdVL/ +RwvfpqLD7uZRc12N6I4/z/1igN1Ab38ljLaNveAfA5sZsqriUV8KOLKzgo7MB41I/5g0 O2lTOeRIz6cbM1HDSutxEgAIgz0fy2dyI3ToOpKshD8LcDOud4I5/BsjTPHDQbgjy4SD5 tV+LTEA9fJcuO2JTcBZljEOdqiupUFazZKG2RCrN4nE9Dx2Q23Vwq3FMG38Eom+hszQ== 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=ST6mKnhK; 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 45DB1606A683; Fri, 4 Dec 2026 10:51:56 +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=ST6mKnhK Received: by smtp.kernel.org (Postfix) with ESMTPSA id B91701F00897; Fri, 4 Dec 2026 10:51:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381516; bh=1Xb3aZiivwzjPNUvfFgUFWc2P+2HE5KQQACgxpd27IY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ST6mKnhKOZKO+dZ+3+coyUK68pxZsyuSCiOB8XTkOjabr3DSK3b7kglBFhinjiGYl tgYziP02UjoxforAIS3Q5f3OLP75KPrZIW5PIpJNwaJ314ir7d4udrDyOtjJQIS/BQ +GJJT4BA/LyM4X1QX2WL8a7vmkb6sXRO1Xv3vk8M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Vega , Luxing Yin , Zihan Xi , Julian Anastasov , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 7.3 737/742] ipvs: avoid stack overflow from recursive connection expiration Date: Fri, 4 Dec 2026 19:10:01 +0900 Message-ID: <20261204100654.687159596@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zihan Xi [ Upstream commit d4e4cd04de2c47ed05f837a26edd20c56be3f097 ] 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 Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/netfilter/ipvs/ip_vs_conn.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) --- a/net/netfilter/ipvs/ip_vs_conn.c +++ b/net/netfilter/ipvs/ip_vs_conn.c @@ -1338,9 +1338,23 @@ static void ip_vs_conn_rcu_free(struct r 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 @@ -1349,13 +1363,8 @@ static void ip_vs_conn_rcu_free(struct r */ 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: @@ -1368,6 +1377,9 @@ static void ip_vs_conn_expire(struct tim 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? */ @@ -1377,19 +1389,18 @@ static void ip_vs_conn_expire(struct tim /* 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) && @@ -1416,7 +1427,11 @@ static void ip_vs_conn_expire(struct tim 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: @@ -1431,6 +1446,9 @@ static void ip_vs_conn_expire(struct tim 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.