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

From: Steffen Klassert <[email-masked]>
Date: Wed, 29 Apr 2026 10:42:02 +0200

On Wed, Apr 29, 2026 at 10:29:10AM +0200, Michal Kosiorek wrote:
...
> 
> Fixes: fe9f1d8779cb ("xfrm: add state hashtable keyed by seq")
> Fixes: 7b4dc3600e48 ("[XFRM]: Do not add a state whose SPI is zero to
> the SPI hash.")
> Reported-by: Michal Kosiorek <[email-masked]>
> Tested-by: Michal Kosiorek <[email-masked]>
> Cc: [email-masked]
> Signed-off-by: Michal Kosiorek <[email-masked]>
> ---
>  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
> index 1748d374abca..686014d39429 100644
> --- a/net/xfrm/xfrm_state.c
> +++ b/net/xfrm/xfrm_state.c
> @@ -818,17 +818,17 @@ 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 looks still odd, the indentation seems to be wrong.
It does not apply, maybe your mail client malformed
the patch.