netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Slavin Liu <slavin452@gmail.com>
To: Simon Horman <horms@verge.net.au>, Julian Anastasov <ja@ssi.bg>
Cc: Slavin Liu <slavin452@gmail.com>,
	Pablo Neira Ayuso <pablo@netfilter.org>,
	Jozsef Kadlecsik <kadlec@netfilter.org>,
	Florian Westphal <fw@strlen.de>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	lvs-devel@vger.kernel.org, netdev@vger.kernel.org,
	netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] IPVS: Fix use-after-free issue in ip_vs_unbind_app()
Date: Mon,  8 Sep 2025 14:54:58 +0800	[thread overview]
Message-ID: <20250908065458.536-1-slavin452@gmail.com> (raw)

When exiting a network namespace, in cleanup_net()->ops_undo_list(),
ip_vs_ftp_ops->exit() is called before ip_vs_core_ops->exit_batch().
The ip_vs_app ip_vs_ftp and its incarnations will be freed by unregister_ip_vs_app().
However, there could still be connections bound to ip_vs_ftp's incarnation.
cp->app points to the free'd incarnation, which will be accessed later by
__ip_vs_cleanup_batch()->ip_vs_conn_net_cleanup()->ip_vs_conn_flush()->ip_vs_conn_del()->
ip_vs_conn_expire()->ip_vs_unbind_app(), causing a uaf. This vulnarability can
lead to a local privilege escalation.

Reproduction steps:
1. create a ipvs service on (127.0.0.1:21)
2. create a ipvs destination on the service, to (127.0.0.1:<any>)
3. send a tcp packet to (127.0.0.1:21)
4. exit the network namespace

I think the fix should flush all connection to ftp before unregistration.
The simpler fix is to delete ip_vs_ftp_ops->exit, and defer the unregistration
of ip_vs_ftp to ip_vs_app_net_cleanup(), which will unregister all ip_vs_app.
It's after ip_vs_conn_net_cleanup() so there is no uaf issue. This patch
seems to solve the issue but has't been fully tested yet, and is also not graceful.

Signed-off-by: Slavin Liu <slavin452@gmail.com>
---
 net/netfilter/ipvs/ip_vs_ftp.c | 13 -------------
 1 file changed, 13 deletions(-)

diff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c
index d8a284999544..68def1106681 100644
--- a/net/netfilter/ipvs/ip_vs_ftp.c
+++ b/net/netfilter/ipvs/ip_vs_ftp.c
@@ -598,22 +598,9 @@ static int __net_init __ip_vs_ftp_init(struct net *net)
 	unregister_ip_vs_app(ipvs, &ip_vs_ftp);
 	return ret;
 }
-/*
- *	netns exit
- */
-static void __ip_vs_ftp_exit(struct net *net)
-{
-	struct netns_ipvs *ipvs = net_ipvs(net);
-
-	if (!ipvs)
-		return;
-
-	unregister_ip_vs_app(ipvs, &ip_vs_ftp);
-}
 
 static struct pernet_operations ip_vs_ftp_ops = {
 	.init = __ip_vs_ftp_init,
-	.exit = __ip_vs_ftp_exit,
 };
 
 static int __init ip_vs_ftp_init(void)
-- 
2.34.1


             reply	other threads:[~2025-09-08  6:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-08  6:54 Slavin Liu [this message]
2025-09-09 15:15 ` [PATCH 1/1] IPVS: Fix use-after-free issue in ip_vs_unbind_app() Julian Anastasov
2025-09-09 21:21 ` [PATCH v2] ipvs: Check ipvs->enable before unregistration in __ip_vs_ftp_exit() Slavin Liu
2025-09-10  9:39   ` Julian Anastasov
2025-09-11 14:40   ` [RFC PATCH v3] ipvs: Defer ip_vs_ftp unregister during netns cleanup Slavin Liu
2025-09-11 17:57     ` [PATCH v4] " Slavin Liu
2025-09-13 17:23       ` Julian Anastasov
2025-09-13 21:07         ` Florian Westphal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250908065458.536-1-slavin452@gmail.com \
    --to=slavin452@gmail.com \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=horms@verge.net.au \
    --cc=ja@ssi.bg \
    --cc=kadlec@netfilter.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvs-devel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).