From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB96C31D72A; Mon, 27 Oct 2025 18:53:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761591218; cv=none; b=Wc53Dxpt6snEBTFfiVwzPu8wKDrrKDANjNuNqec0If0Ppkr+Nkcak+kZshus5Owb6CwF+UoQl2zT32FNFYfTg/IGIRvvSJl65SzyhH6n/Yf5aFKIrFqaPg6FH9zJqNXrkRGOm9ECfuwxKnY+Q1ML7dqriXzd0DCQjTdw6SvHBs0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761591218; c=relaxed/simple; bh=hqCs2OyO0xdlY0Dg+gIr9O4MwEjTX/uI/g948ks7Lbs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nD4Vc3r31HA+LxHW80zREQE0WfZf6+HPLb8dATjy11x40y6td4Ei7wUyDrg8GjIpcpiaawkUP1FjJ6s2OOFhNwqbgX6GVXOlsQ7wv8thhQg9cHGkilYPnNqY/7bCWPm1TAb3xihi6Ke6pRr2MqsorCOPGBENkvjbosOMP0Kmx38= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=lgEEQcCB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="lgEEQcCB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C00FC4CEF1; Mon, 27 Oct 2025 18:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1761591218; bh=hqCs2OyO0xdlY0Dg+gIr9O4MwEjTX/uI/g948ks7Lbs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lgEEQcCBLRnJNwIAE91DDjKsIBfjYg+9fUkfmX7qn/CwvGMb0PE+V7+zCFoYdmTPz OeJ4o2sDRnkgl+4eiUQgmiWBr7ehBEZSvZkxLYCn7W1HCCNpdG3SmuXmP/3z/8qMlY MP/8h69TjuZkNBWNGw15WkRIKRIhwn/v99T8n1xs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Julian Anastasov , Slavin Liu , Florian Westphal , Sasha Levin Subject: [PATCH 5.10 075/332] ipvs: Defer ip_vs_ftp unregister during netns cleanup Date: Mon, 27 Oct 2025 19:32:08 +0100 Message-ID: <20251027183526.603272980@linuxfoundation.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251027183524.611456697@linuxfoundation.org> References: <20251027183524.611456697@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Slavin Liu [ Upstream commit 134121bfd99a06d44ef5ba15a9beb075297c0821 ] On the netns cleanup path, __ip_vs_ftp_exit() may unregister ip_vs_ftp before connections with valid cp->app pointers are flushed, leading to a use-after-free. Fix this by introducing a global `exiting_module` flag, set to true in ip_vs_ftp_exit() before unregistering the pernet subsystem. In __ip_vs_ftp_exit(), skip ip_vs_ftp unregister if called during netns cleanup (when exiting_module is false) and defer it to __ip_vs_cleanup_batch(), which unregisters all apps after all connections are flushed. If called during module exit, unregister ip_vs_ftp immediately. Fixes: 61b1ab4583e2 ("IPVS: netns, add basic init per netns.") Suggested-by: Julian Anastasov Signed-off-by: Slavin Liu Signed-off-by: Julian Anastasov Signed-off-by: Florian Westphal Signed-off-by: Sasha Levin --- net/netfilter/ipvs/ip_vs_ftp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c index cf925906f59b6..67d0d4f1f0db1 100644 --- a/net/netfilter/ipvs/ip_vs_ftp.c +++ b/net/netfilter/ipvs/ip_vs_ftp.c @@ -53,6 +53,7 @@ enum { IP_VS_FTP_EPSV, }; +static bool exiting_module; /* * List of ports (up to IP_VS_APP_MAX_PORTS) to be handled by helper * First port is set to the default port. @@ -607,7 +608,7 @@ static void __ip_vs_ftp_exit(struct net *net) { struct netns_ipvs *ipvs = net_ipvs(net); - if (!ipvs) + if (!ipvs || !exiting_module) return; unregister_ip_vs_app(ipvs, &ip_vs_ftp); @@ -629,6 +630,7 @@ static int __init ip_vs_ftp_init(void) */ static void __exit ip_vs_ftp_exit(void) { + exiting_module = true; unregister_pernet_subsys(&ip_vs_ftp_ops); /* rcu_barrier() is called by netns */ } -- 2.51.0