Netdev List
 help / color / mirror / Atom feed
From: Julian Anastasov <ja@ssi.bg>
To: Chengfeng Ye <nicoyip.dev@gmail.com>
Cc: Simon Horman <horms@verge.net.au>,
	Pablo Neira Ayuso <pablo@netfilter.org>,
	Florian Westphal <fw@strlen.de>, Phil Sutter <phil@nwl.cc>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Hans Schillstrom <hans.schillstrom@ericsson.com>,
	netdev@vger.kernel.org, lvs-devel@vger.kernel.org,
	netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH net] ipvs: fix protocol data lifetime during namespace teardown
Date: Wed, 30 Sep 2026 20:21:24 +0300 (EEST)	[thread overview]
Message-ID: <be9d490c-f295-2119-b504-80842011ecce@ssi.bg> (raw)
In-Reply-To: <20260927062435.3690129-1-nicoyip.dev@gmail.com>


	Hello,

On Sun, 27 Sep 2026, Chengfeng Ye wrote:

> IPVS frees its per-net protocol data before control cleanup cancels
> defense work and unregisters the sysctl table. A defense worker can load
> a protocol data pointer, then namespace cleanup can unlink and free that
> object before the worker dereferences pd->pp or pd->next. The worker's
> securetcp_lock does not serialize with protocol cleanup. A concurrent
> defense-mode sysctl write can reach the same timeout update path.
> 
> KASAN reported:
> 
>   BUG: KASAN: slab-use-after-free in ip_vs_protocol_timeout_change
>   Workqueue: events_long defense_work_handler
>   Call Trace:
>    ip_vs_protocol_timeout_change+0x1b4/0x1e0
>    update_defense_level+0x63e/0xd80
>    defense_work_handler+0x1e/0xc0
>   Allocated by task 125:
>    ip_vs_protocol_net_init+0xda/0x2f0
>    __ip_vs_init+0x16b/0x240
>    setup_net+0xfc/0x310
>   Freed by task 12:
>    ip_vs_protocol_net_cleanup+0x1d6/0x2e0
>    __ip_vs_cleanup_batch+0x7d/0x100
>    cleanup_net+0x38c/0x770
> 
> Run control cleanup before protocol cleanup so that defense work and
> active sysctl handlers have finished before their protocol data is freed.
> Initialize protocols before exposing the control interface, and unwind
> in reverse order, to enforce the same lifetime on initialization failure.
> Protocol initialization and exit do not depend on control state.
> 
> Fixes: 9330419d9aa4 ("IPVS: netns, use ip_vs_proto_data as param.")
> Cc: stable@vger.kernel.org
> Signed-off-by: Chengfeng Ye <nicoyip.dev@gmail.com>

	Patch looks good to me for the nf tree, thanks!

Acked-by: Julian Anastasov <ja@ssi.bg>

	If you want to change the order of ip_vs_protocol_init()
and ip_vs_control_init() in ip_vs_init() for consistency, you
have to send another version or a nf-next patch.

> ---
>  net/netfilter/ipvs/ip_vs_core.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
> index fd503f0efb57..8a3c880fdb26 100644
> --- a/net/netfilter/ipvs/ip_vs_core.c
> +++ b/net/netfilter/ipvs/ip_vs_core.c
> @@ -2502,12 +2502,12 @@ static int __net_init __ip_vs_init(struct net *net)
>  	if (ip_vs_estimator_net_init(ipvs) < 0)
>  		goto estimator_fail;
>  
> -	if (ip_vs_control_net_init(ipvs) < 0)
> -		goto control_fail;
> -
>  	if (ip_vs_protocol_net_init(ipvs) < 0)
>  		goto protocol_fail;
>  
> +	if (ip_vs_control_net_init(ipvs) < 0)
> +		goto control_fail;
> +
>  	if (ip_vs_app_net_init(ipvs) < 0)
>  		goto app_fail;
>  
> @@ -2527,10 +2527,10 @@ static int __net_init __ip_vs_init(struct net *net)
>  conn_fail:
>  	ip_vs_app_net_cleanup(ipvs);
>  app_fail:
> -	ip_vs_protocol_net_cleanup(ipvs);
> -protocol_fail:
>  	ip_vs_control_net_cleanup(ipvs);
>  control_fail:
> +	ip_vs_protocol_net_cleanup(ipvs);
> +protocol_fail:
>  	ip_vs_estimator_net_cleanup(ipvs);
>  estimator_fail:
>  	net->ipvs = NULL;
> @@ -2547,8 +2547,8 @@ static void __net_exit __ip_vs_cleanup_batch(struct list_head *net_list)
>  		ipvs = net_ipvs(net);
>  		ip_vs_conn_net_cleanup(ipvs);
>  		ip_vs_app_net_cleanup(ipvs);
> -		ip_vs_protocol_net_cleanup(ipvs);
>  		ip_vs_control_net_cleanup(ipvs);
> +		ip_vs_protocol_net_cleanup(ipvs);
>  		ip_vs_estimator_net_cleanup(ipvs);
>  		IP_VS_DBG(2, "ipvs netns %d released\n", ipvs->gen);
>  		net->ipvs = NULL;
> -- 
> 2.43.0

Regards

--
Julian Anastasov <ja@ssi.bg>


      reply	other threads:[~2026-09-30 17:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-27  6:24 [PATCH net] ipvs: fix protocol data lifetime during namespace teardown Chengfeng Ye
2026-09-30 17:21 ` Julian Anastasov [this message]

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=be9d490c-f295-2119-b504-80842011ecce@ssi.bg \
    --to=ja@ssi.bg \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=hans.schillstrom@ericsson.com \
    --cc=horms@verge.net.au \
    --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=nicoyip.dev@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    --cc=phil@nwl.cc \
    --cc=stable@vger.kernel.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