FAILED: patch "[PATCH] Revert "xfrm: destroy xfrm_state synchronously on net exit" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 2a198bbec6913ae1c90ec963750003c6213668c7
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025072924-postbox-exorcism-f636@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 2a198bbec6913ae1c90ec963750003c6213668c7 Mon Sep 17 00:00:00 2001
From: Sabrina Dubroca <[email protected]>
Date: Fri, 4 Jul 2025 16:54:34 +0200
Subject: [PATCH] Revert "xfrm: destroy xfrm_state synchronously on net exit
path"
This reverts commit f75a2804da391571563c4b6b29e7797787332673.
With all states (whether user or kern) removed from the hashtables during deletion, there's no need for synchronous destruction of states. xfrm6_tunnel states still need to have been destroyed (which will be the case when its last user is deleted (not destroyed)) so that xfrm6_tunnel_free_spi removes it from the per-netns hashtable before the netns is destroyed.
This has the benefit of skipping one synchronize_rcu per state (in __xfrm_state_destroy(sync=true)) when we exit a netns.
include/net/xfrm.h +3 -9
@@ -915,7 +915,7 @@ static inline void xfrm_pols_put(struct xfrm_policy **pols, int npols)xfrm_pol_put (pols[i]); } -void __xfrm_state_destroy (struct xfrm_state *,bool ); +void __xfrm_state_destroy (struct xfrm_state *);static inline void __xfrm_state_put (struct xfrm_state *x) {
@@ -925,13 +925,7 @@ static inline void __xfrm_state_put(struct xfrm_state *x)static inline void xfrm_state_put (struct xfrm_state *x) {if (refcount_dec_and_test (&x->refcnt)) -__xfrm_state_destroy (x, false); -} - -static inline void xfrm_state_put_sync (struct xfrm_state *x) -{ -if (refcount_dec_and_test (&x->refcnt)) -__xfrm_state_destroy (x, true); +__xfrm_state_destroy (x); }static inline void xfrm_state_hold (struct xfrm_state *x)
@@ -1769,7 +1763,7 @@ struct xfrmk_spdinfo {struct xfrm_state *xfrm_find_acq_byseq (struct net *net,u32 mark,u32 seq,u32 pcpu_num);int xfrm_state_delete (struct xfrm_state *x); -int xfrm_state_flush (struct net *net,u8 proto,bool task_valid,bool sync); +int xfrm_state_flush (struct net *net,u8 proto,bool task_valid);int xfrm_dev_state_flush (struct net *net,struct net_device *dev,bool task_valid);int xfrm_dev_policy_flush (struct net *net,struct net_device *dev,bool task_valid);
net/ipv6/xfrm6_tunnel.c +1 -1
@@ -334,7 +334,7 @@ static void __net_exit xfrm6_tunnel_net_exit(struct net *net)struct xfrm6_tunnel_net *xfrm6_tn =xfrm6_tunnel_pernet (net);unsigned int i; -xfrm_state_flush (net,0 , false, true); +xfrm_state_flush (net,IPSEC_PROTO_ANY , false);xfrm_flush_gc ();for (i =0 ; i <XFRM6_TUNNEL_SPI_BYADDR_HSIZE ; i++)
net/key/af_key.c +1 -1
@@ -1766,7 +1766,7 @@ static int pfkey_flush(struct sock *sk, struct sk_buff *skb, const struct sadb_mif (proto ==0 )return -EINVAL ; - err =xfrm_state_flush (net, proto, true, false); + err =xfrm_state_flush (net, proto, true); err2 =unicast_flush_resp (sk, hdr);if (err || err2) {if (err == -ESRCH )/* empty table - go quietly */
net/xfrm/xfrm_state.c +9 -14
@@ -592,7 +592,7 @@ void xfrm_state_free(struct xfrm_state *x) }EXPORT_SYMBOL (xfrm_state_free); -static void ___xfrm_state_destroy (struct xfrm_state *x) +static void xfrm_state_gc_destroy (struct xfrm_state *x) {if (x->mode_cbs && x->mode_cbs->destroy_state) x->mode_cbs->destroy_state (x);
@@ -631,7 +631,7 @@ static void xfrm_state_gc_task(struct work_struct *work)synchronize_rcu ();hlist_for_each_entry_safe (x, tmp, &gc_list, gclist) -___xfrm_state_destroy (x); +xfrm_state_gc_destroy (x); }static enum hrtimer_restart xfrm_timer_handler (struct hrtimer *me)
@@ -795,19 +795,14 @@ void xfrm_dev_state_free(struct xfrm_state *x) }#endif -void __xfrm_state_destroy (struct xfrm_state *x,bool sync) +void __xfrm_state_destroy (struct xfrm_state *x) {WARN_ON (x->km.state !=XFRM_STATE_DEAD ); -if (sync) { -synchronize_rcu (); -___xfrm_state_destroy (x); - }else { -spin_lock_bh (&xfrm_state_gc_lock); -hlist_add_head (&x->gclist, &xfrm_state_gc_list); -spin_unlock_bh (&xfrm_state_gc_lock); -schedule_work (&xfrm_state_gc_work); - } +spin_lock_bh (&xfrm_state_gc_lock); +hlist_add_head (&x->gclist, &xfrm_state_gc_list); +spin_unlock_bh (&xfrm_state_gc_lock); +schedule_work (&xfrm_state_gc_work); }EXPORT_SYMBOL (__xfrm_state_destroy);
@@ -922,7 +917,7 @@ xfrm_dev_state_flush_secctx_check(struct net *net, struct net_device *dev, bool }#endif -int xfrm_state_flush (struct net *net,u8 proto,bool task_valid,bool sync) +int xfrm_state_flush (struct net *net,u8 proto,bool task_valid) {int i, err =0 , cnt =0 ;
@@ -3283,7 +3278,7 @@ void xfrm_state_fini(struct net *net)unsigned int sz;flush_work (&net->xfrm.state_hash_work); -xfrm_state_flush (net,0 , false, true); +xfrm_state_flush (net,IPSEC_PROTO_ANY , false);flush_work (&xfrm_state_gc_work);WARN_ON (!list_empty (&net->xfrm.state_all));
net/xfrm/xfrm_user.c +1 -1
@@ -2635,7 +2635,7 @@ static int xfrm_flush_sa(struct sk_buff *skb, struct nlmsghdr *nlh,struct xfrm_usersa_flush *p =nlmsg_data (nlh);int err; - err =xfrm_state_flush (net, p->proto, true, false); + err =xfrm_state_flush (net, p->proto, true);if (err) {if (err == -ESRCH )/* empty table */ return 0 ;
Sasha Levin
maintainerPATCH 1/2 xfrm: delete x->tunnel as we delete x
From: Sabrina Dubroca <[email protected]>
[ Upstream commit b441cf3f8c4b8576639d20c8eb4aa32917602ecd ]
The ipcomp fallback tunnels currently get deleted (from the various lists and hashtables) as the last user state that needed that fallback is destroyed (not deleted). If a reference to that user state still exists, the fallback state will remain on the hashtables/lists, triggering the WARN in xfrm_state_fini. Because of those remaining references, the fix in commit f75a2804da39 ("xfrm: destroy xfrm_state synchronously on net exit path") is not complete.
We recently fixed one such situation in TCP due to defered freeing of skbs (commit 9b6412e6979f ("tcp: drop secpath at the same time as we currently drop dst")). This can also happen due to IP reassembly: skbs with a secpath remain on the reassembly queue until netns destruction. If we can't guarantee that the queues are flushed by the time xfrm_state_fini runs, there may still be references to a (user) xfrm_state, preventing the timely deletion of the corresponding fallback state.
Instead of chasing each instance of skbs holding a secpath one by one, this patch fixes the issue directly within xfrm, by deleting the fallback state as soon as the last user state depending on it has been deleted. Destruction will still happen when the final reference is dropped.
A separate lockdep class for the fallback state is required since we're going to lock x->tunnel while x is locked.
--- include/net/xfrm.h | 1 - net/ipv4/ipcomp.c | 2 ++ net/ipv6/ipcomp6.c | 2 ++ net/ipv6/xfrm6_tunnel.c | 2 +- net/xfrm/xfrm_ipcomp.c | 1 - net/xfrm/xfrm_state.c | 19 ++++++++----------- 6 files changed, 13 insertions(+), 14 deletions(-)
include/net/xfrm.h +0 -1
@@ -424,7 +424,6 @@ int xfrm_input_register_afinfo(const struct xfrm_input_afinfo *afinfo);int xfrm_input_unregister_afinfo (const struct xfrm_input_afinfo *afinfo);void xfrm_flush_gc (void ); -void xfrm_state_delete_tunnel (struct xfrm_state *x);struct xfrm_type {struct module *owner;
net/ipv4/ipcomp.c +2 -0
@@ -54,6 +54,7 @@ static int ipcomp4_err(struct sk_buff *skb, u32 info) }/* We always hold one tunnel user reference to indicate a tunnel */ +static struct lock_class_key xfrm_state_lock_key;static struct xfrm_state *ipcomp_tunnel_create (struct xfrm_state *x) {struct net *net =xs_net (x);
@@ -62,6 +63,7 @@ static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x) t =xfrm_state_alloc (net);if (!t) goto out; +lockdep_set_class (&t->lock, &xfrm_state_lock_key); t->id.proto =IPPROTO_IPIP ; t->id.spi = x->props.saddr.a4;
net/ipv6/ipcomp6.c +2 -0
@@ -71,6 +71,7 @@ static int ipcomp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,return 0 ; } +static struct lock_class_key xfrm_state_lock_key;static struct xfrm_state *ipcomp6_tunnel_create (struct xfrm_state *x) {struct net *net =xs_net (x);
@@ -79,6 +80,7 @@ static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x) t =xfrm_state_alloc (net);if (!t) goto out; +lockdep_set_class (&t->lock, &xfrm_state_lock_key); t->id.proto =IPPROTO_IPV6 ; t->id.spi =xfrm6_tunnel_alloc_spi (net, (xfrm_address_t *)&x->props.saddr);
net/ipv6/xfrm6_tunnel.c +1 -1
@@ -334,8 +334,8 @@ static void __net_exit xfrm6_tunnel_net_exit(struct net *net)struct xfrm6_tunnel_net *xfrm6_tn =xfrm6_tunnel_pernet (net);unsigned int i; -xfrm_flush_gc ();xfrm_state_flush (net,0 , false, true); +xfrm_flush_gc ();for (i =0 ; i <XFRM6_TUNNEL_SPI_BYADDR_HSIZE ; i++)WARN_ON_ONCE (!hlist_empty (&xfrm6_tn->spi_byaddr[i]));
net/xfrm/xfrm_ipcomp.c +0 -1
@@ -315,7 +315,6 @@ void ipcomp_destroy(struct xfrm_state *x)struct ipcomp_data *ipcd = x->data;if (!ipcd)return ; -xfrm_state_delete_tunnel (x);mutex_lock (&ipcomp_resource_mutex);ipcomp_free_data (ipcd);mutex_unlock (&ipcomp_resource_mutex);
net/xfrm/xfrm_state.c +8 -11
@@ -748,6 +748,7 @@ void __xfrm_state_destroy(struct xfrm_state *x, bool sync) }EXPORT_SYMBOL (__xfrm_state_destroy); +static void xfrm_state_delete_tunnel (struct xfrm_state *x);int __xfrm_state_delete (struct xfrm_state *x) {struct net *net =xs_net (x);
@@ -775,6 +776,8 @@ int __xfrm_state_delete(struct xfrm_state *x)xfrm_dev_state_delete (x); +xfrm_state_delete_tunnel (x); +/* All xfrm_state objects are created by xfrm_state_alloc. * The xfrm_state_alloc call gives a reference, and that * is what we are dropping here.
@@ -878,10 +881,7 @@ int xfrm_state_flush(struct net *net, u8 proto, bool task_valid, bool sync) err =xfrm_state_delete (x);xfrm_audit_state_delete (x, err ?0 :1 , task_valid); -if (sync) -xfrm_state_put_sync (x); -else -xfrm_state_put (x); +xfrm_state_put (x);if (!err) cnt++;
@@ -2994,20 +2994,17 @@ void xfrm_flush_gc(void) }EXPORT_SYMBOL (xfrm_flush_gc); -/* Temporarily located here until net/xfrm/xfrm_tunnel.c is created */ -void xfrm_state_delete_tunnel (struct xfrm_state *x) +static void xfrm_state_delete_tunnel (struct xfrm_state *x) {if (x->tunnel) {struct xfrm_state *t = x->tunnel; -if (atomic_read (&t->tunnel_users) ==2 ) +if (atomic_dec_return (&t->tunnel_users) ==1 )xfrm_state_delete (t); -atomic_dec (&t->tunnel_users); -xfrm_state_put_sync (t); +xfrm_state_put (t); x->tunnel =NULL ; } } -EXPORT_SYMBOL (xfrm_state_delete_tunnel);u32 xfrm_state_mtu (struct xfrm_state *x,int mtu) {
@@ -3207,8 +3204,8 @@ void xfrm_state_fini(struct net *net)unsigned int sz;flush_work (&net->xfrm.state_hash_work); -flush_work (&xfrm_state_gc_work);xfrm_state_flush (net,0 , false, true); +flush_work (&xfrm_state_gc_work);WARN_ON (!list_empty (&net->xfrm.state_all));
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 2/2 Revert "xfrm: destroy xfrm_state synchronously on net exit path"
From: Sabrina Dubroca <[email protected]>
[ Upstream commit 2a198bbec6913ae1c90ec963750003c6213668c7 ]
This reverts commit f75a2804da391571563c4b6b29e7797787332673.
With all states (whether user or kern) removed from the hashtables during deletion, there's no need for synchronous destruction of states. xfrm6_tunnel states still need to have been destroyed (which will be the case when its last user is deleted (not destroyed)) so that xfrm6_tunnel_free_spi removes it from the per-netns hashtable before the netns is destroyed.
This has the benefit of skipping one synchronize_rcu per state (in __xfrm_state_destroy(sync=true)) when we exit a netns.
--- include/net/xfrm.h | 12 +++--------- net/ipv6/xfrm6_tunnel.c | 2 +- net/key/af_key.c | 2 +- net/xfrm/xfrm_state.c | 23 +++++++++-------------- net/xfrm/xfrm_user.c | 2 +- 5 files changed, 15 insertions(+), 26 deletions(-)
include/net/xfrm.h +3 -9
@@ -850,7 +850,7 @@ static inline void xfrm_pols_put(struct xfrm_policy **pols, int npols)xfrm_pol_put (pols[i]); } -void __xfrm_state_destroy (struct xfrm_state *,bool ); +void __xfrm_state_destroy (struct xfrm_state *);static inline void __xfrm_state_put (struct xfrm_state *x) {
@@ -860,13 +860,7 @@ static inline void __xfrm_state_put(struct xfrm_state *x)static inline void xfrm_state_put (struct xfrm_state *x) {if (refcount_dec_and_test (&x->refcnt)) -__xfrm_state_destroy (x, false); -} - -static inline void xfrm_state_put_sync (struct xfrm_state *x) -{ -if (refcount_dec_and_test (&x->refcnt)) -__xfrm_state_destroy (x, true); +__xfrm_state_destroy (x); }static inline void xfrm_state_hold (struct xfrm_state *x)
@@ -1704,7 +1698,7 @@ struct xfrmk_spdinfo {struct xfrm_state *xfrm_find_acq_byseq (struct net *net,u32 mark,u32 seq,u32 pcpu_num);int xfrm_state_delete (struct xfrm_state *x); -int xfrm_state_flush (struct net *net,u8 proto,bool task_valid,bool sync); +int xfrm_state_flush (struct net *net,u8 proto,bool task_valid);int xfrm_dev_state_flush (struct net *net,struct net_device *dev,bool task_valid);int xfrm_dev_policy_flush (struct net *net,struct net_device *dev,bool task_valid);
net/ipv6/xfrm6_tunnel.c +1 -1
@@ -334,7 +334,7 @@ static void __net_exit xfrm6_tunnel_net_exit(struct net *net)struct xfrm6_tunnel_net *xfrm6_tn =xfrm6_tunnel_pernet (net);unsigned int i; -xfrm_state_flush (net,0 , false, true); +xfrm_state_flush (net,IPSEC_PROTO_ANY , false);xfrm_flush_gc ();for (i =0 ; i <XFRM6_TUNNEL_SPI_BYADDR_HSIZE ; i++)
net/key/af_key.c +1 -1
@@ -1766,7 +1766,7 @@ static int pfkey_flush(struct sock *sk, struct sk_buff *skb, const struct sadb_mif (proto ==0 )return -EINVAL ; - err =xfrm_state_flush (net, proto, true, false); + err =xfrm_state_flush (net, proto, true); err2 =unicast_flush_resp (sk, hdr);if (err || err2) {if (err == -ESRCH )/* empty table - go quietly */
net/xfrm/xfrm_state.c +9 -14
@@ -531,7 +531,7 @@ void xfrm_state_free(struct xfrm_state *x) }EXPORT_SYMBOL (xfrm_state_free); -static void ___xfrm_state_destroy (struct xfrm_state *x) +static void xfrm_state_gc_destroy (struct xfrm_state *x) {hrtimer_cancel (&x->mtimer);del_timer_sync (&x->rtimer);
@@ -569,7 +569,7 @@ static void xfrm_state_gc_task(struct work_struct *work)synchronize_rcu ();hlist_for_each_entry_safe (x, tmp, &gc_list, gclist) -___xfrm_state_destroy (x); +xfrm_state_gc_destroy (x); }static enum hrtimer_restart xfrm_timer_handler (struct hrtimer *me)
@@ -732,19 +732,14 @@ void xfrm_dev_state_free(struct xfrm_state *x) }#endif -void __xfrm_state_destroy (struct xfrm_state *x,bool sync) +void __xfrm_state_destroy (struct xfrm_state *x) {WARN_ON (x->km.state !=XFRM_STATE_DEAD ); -if (sync) { -synchronize_rcu (); -___xfrm_state_destroy (x); - }else { -spin_lock_bh (&xfrm_state_gc_lock); -hlist_add_head (&x->gclist, &xfrm_state_gc_list); -spin_unlock_bh (&xfrm_state_gc_lock); -schedule_work (&xfrm_state_gc_work); - } +spin_lock_bh (&xfrm_state_gc_lock); +hlist_add_head (&x->gclist, &xfrm_state_gc_list); +spin_unlock_bh (&xfrm_state_gc_lock); +schedule_work (&xfrm_state_gc_work); }EXPORT_SYMBOL (__xfrm_state_destroy);
@@ -859,7 +854,7 @@ xfrm_dev_state_flush_secctx_check(struct net *net, struct net_device *dev, bool }#endif -int xfrm_state_flush (struct net *net,u8 proto,bool task_valid,bool sync) +int xfrm_state_flush (struct net *net,u8 proto,bool task_valid) {int i, err =0 , cnt =0 ;
@@ -3204,7 +3199,7 @@ void xfrm_state_fini(struct net *net)unsigned int sz;flush_work (&net->xfrm.state_hash_work); -xfrm_state_flush (net,0 , false, true); +xfrm_state_flush (net,IPSEC_PROTO_ANY , false);flush_work (&xfrm_state_gc_work);WARN_ON (!list_empty (&net->xfrm.state_all));
net/xfrm/xfrm_user.c +1 -1
@@ -2568,7 +2568,7 @@ static int xfrm_flush_sa(struct sk_buff *skb, struct nlmsghdr *nlh,struct xfrm_usersa_flush *p =nlmsg_data (nlh);int err; - err =xfrm_state_flush (net, p->proto, true, false); + err =xfrm_state_flush (net, p->proto, true);if (err) {if (err == -ESRCH )/* empty table */ return 0 ;
Signature · 1 line
2.39.5
Re: [PATCH 6.12.y 1/2] xfrm: delete x->tunnel as we delete x
In reply to Sasha LevinHi Sasha/Greg,
Quoted 3 lines · Sasha Levin
From: Sabrina Dubroca <[email protected]>
[ Upstream commit
b441cf3f8c4b8576639d20c8eb4aa32917602ecd]
Quoted 3 lines · Sasha Levin
From: Sabrina Dubroca <[email protected]>
[ Upstream commit
2a198bbec6913ae1c90ec963750003c6213668c7]
Can you wait a bit before taking those 2 patches into stable? A couple of syzbot reports landed today, one is definitely related to this series [1], the others probably are as well [2][3]. The patches should be dropped from all stable branches for now.
[1] https://lore.kernel.org/netdev/[email protected]/
[2] https://lore.kernel.org/netdev/[email protected]/
[3] https://lore.kernel.org/netdev/[email protected]/
Thanks,
Signature · 1 line
Sabrina
Sasha Levin
maintainerRe: [PATCH 6.12.y 1/2] xfrm: delete x->tunnel as we delete x
Quoted 11 lines · Sabrina Dubroca
Hi Sasha/Greg,
Quoted 3 lines · Sasha Levin
From: Sabrina Dubroca <[email protected]>
[ Upstream commit
b441cf3f8c4b8576639d20c8eb4aa32917602ecd]Quoted 2 lines · Sasha Levin
From: Sabrina Dubroca <[email protected]>
Quoted 7 lines
Quoted 1 line
[ Upstream commit
2a198bbec6913ae1c90ec963750003c6213668c7]Can you wait a bit before taking those 2 patches into stable? A couple of syzbot reports landed today, one is definitely related to this series [1], the others probably are as well [2][3]. The patches should be dropped from all stable branches for now.
I've dropped both from 6.15.
Signature · 2 lines
Thanks, Sasha