From: Sabrina Dubroca <sd@queasysnail.net>
To: Hyunwoo Kim <imv4bel@gmail.com>, Eyal Birger <eyal.birger@gmail.com>
Cc: steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net] xfrm: Fix work re-schedule after cancel in xfrm_nat_keepalive_net_fini()
Date: Tue, 10 Mar 2026 23:57:28 +0100 [thread overview]
Message-ID: <abCh2CgVS3Uw7W-_@krikkit> (raw)
In-Reply-To: <abBf_R81PYmafhWv@v4bel>
Please also CC the author, and maybe additional contributors, of the
patch that introduced the problem you're fixing.
2026-03-11, 03:16:29 +0900, Hyunwoo Kim wrote:
> After cancel_delayed_work_sync() is called from
> xfrm_nat_keepalive_net_fini(), xfrm_state_fini() flushes remaining
> states via __xfrm_state_delete(), which calls
> xfrm_nat_keepalive_state_updated() to re-schedule nat_keepalive_work.
Eyal, I'm wondering why __xfrm_state_delete() calls
xfrm_nat_keepalive_state_updated(). At this point the state has been
removed from the walk list so nat_keepalive_work() won't do
anything. Am I missing something?
> The following is a simple race scenario:
>
> cpu0 cpu1
>
> cleanup_net() [Round 1]
> ops_undo_list()
> xfrm_net_exit()
> xfrm_nat_keepalive_net_fini()
> cancel_delayed_work_sync(nat_keepalive_work);
> xfrm_state_fini()
> xfrm_state_flush()
> xfrm_state_delete(x)
> __xfrm_state_delete(x)
> xfrm_nat_keepalive_state_updated(x)
> schedule_delayed_work(nat_keepalive_work);
> rcu_barrier();
> net_complete_free();
> net_passive_dec(net);
> llist_add(&net->defer_free_list, &defer_free_list);
>
> cleanup_net() [Round 2]
> rcu_barrier();
> net_complete_free()
> kmem_cache_free(net_cachep, net);
> nat_keepalive_work()
> // on freed net
>
> To prevent this, cancel_delayed_work_sync() is replaced with
> disable_delayed_work_sync().
>
> Fixes: f531d13bdfe3 ("xfrm: support sending NAT keepalives in ESP in UDP states")
> Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
> ---
> net/xfrm/xfrm_nat_keepalive.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/xfrm/xfrm_nat_keepalive.c b/net/xfrm/xfrm_nat_keepalive.c
> index ebf95d48e86c..1856beee0149 100644
> --- a/net/xfrm/xfrm_nat_keepalive.c
> +++ b/net/xfrm/xfrm_nat_keepalive.c
> @@ -261,7 +261,7 @@ int __net_init xfrm_nat_keepalive_net_init(struct net *net)
>
> int xfrm_nat_keepalive_net_fini(struct net *net)
> {
> - cancel_delayed_work_sync(&net->xfrm.nat_keepalive_work);
> + disable_delayed_work_sync(&net->xfrm.nat_keepalive_work);
> return 0;
> }
>
> --
> 2.43.0
>
>
--
Sabrina
next prev parent reply other threads:[~2026-03-10 22:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-10 18:16 [PATCH net] xfrm: Fix work re-schedule after cancel in xfrm_nat_keepalive_net_fini() Hyunwoo Kim
2026-03-10 22:57 ` Sabrina Dubroca [this message]
2026-03-11 0:14 ` Eyal Birger
2026-03-11 9:26 ` Sabrina Dubroca
2026-03-11 10:31 ` Hyunwoo Kim
2026-03-11 13:00 ` Eyal Birger
2026-03-11 13:27 ` Sabrina Dubroca
2026-03-11 13:40 ` Hyunwoo Kim
2026-03-16 9:57 ` Steffen Klassert
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=abCh2CgVS3Uw7W-_@krikkit \
--to=sd@queasysnail.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eyal.birger@gmail.com \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=imv4bel@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=steffen.klassert@secunet.com \
/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