Re: [PATCH] xfrm: protect __xfrm_state_delete against double-unhash of byseq/byspi

From: Steffen Klassert

Date: Wed Apr 29 2026 - 03:15:12 EST


On Tue, Apr 28, 2026 at 09:53:45AM +0200, Michal Kosiorek wrote:
...
>
> Reported-by: Michal Kosiorek <mkosiorek121@xxxxxxxxx>
> Tested-by: Michal Kosiorek <mkosiorek121@xxxxxxxxx>
> Signed-off-by: Michal Kosiorek <mkosiorek121@xxxxxxxxx>

Please add a 'Fixes:' tag so the patch can be backported
to the stable trees.

> ---
> net/xfrm/xfrm_state.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
> --- a/net/xfrm/xfrm_state.c
> +++ b/net/xfrm/xfrm_state.c
> @@ -758,16 +758,16 @@ int __xfrm_state_delete(struct xfrm_state *x)
>
> spin_lock(&net->xfrm.xfrm_state_lock);
> list_del(&x->km.all);
> - hlist_del_rcu(&x->bydst);
> - hlist_del_rcu(&x->bysrc);
> - if (x->km.seq)
> - hlist_del_rcu(&x->byseq);
> + hlist_del_init_rcu(&x->bydst);
> + hlist_del_init_rcu(&x->bysrc);
> + if (!hlist_unhashed(&x->byseq))
> + hlist_del_init_rcu(&x->byseq);
> if (!hlist_unhashed(&x->state_cache))
> hlist_del_rcu(&x->state_cache);
> if (!hlist_unhashed(&x->state_cache_input))
> hlist_del_rcu(&x->state_cache_input);
>
> - if (x->id.spi)
> - hlist_del_rcu(&x->byspi);
> + if (!hlist_unhashed(&x->byspi))
> + hlist_del_init_rcu(&x->byspi);
> net->xfrm.state_num--;
> xfrm_nat_keepalive_state_updated(x);
> spin_unlock(&net->xfrm.xfrm_state_lock);

This does not allpy to the ipsec tree. Please
rebase on the ipsec tree and resend.

Thanks!