]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xfrm: remove rcu/state_hold from xfrm_state_lookup_spi_proto
authorSabrina Dubroca <sd@queasysnail.net>
Mon, 9 Mar 2026 10:32:38 +0000 (11:32 +0100)
committerSteffen Klassert <steffen.klassert@secunet.com>
Thu, 12 Mar 2026 06:15:33 +0000 (07:15 +0100)
xfrm_state_lookup_spi_proto is called under xfrm_state_lock by
xfrm_alloc_spi, no need to take a reference on the state and pretend
to be under RCU.

Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/xfrm/xfrm_state.c

index 27192b11be43b24a251e44fb07ed31f54a6da97d..f28cbe249c05fa93fc0665bf9a7cd9cb766c4eb1 100644 (file)
@@ -1703,18 +1703,12 @@ static struct xfrm_state *xfrm_state_lookup_spi_proto(struct net *net, __be32 sp
        struct xfrm_state *x;
        unsigned int i;
 
-       rcu_read_lock();
        for (i = 0; i <= net->xfrm.state_hmask; i++) {
-               hlist_for_each_entry_rcu(x, &net->xfrm.state_byspi[i], byspi) {
-                       if (x->id.spi == spi && x->id.proto == proto) {
-                               if (!xfrm_state_hold_rcu(x))
-                                       continue;
-                               rcu_read_unlock();
+               hlist_for_each_entry(x, xfrm_state_deref_prot(net->xfrm.state_byspi, net) + i, byspi) {
+                       if (x->id.spi == spi && x->id.proto == proto)
                                return x;
-                       }
                }
        }
-       rcu_read_unlock();
        return NULL;
 }
 
@@ -2616,7 +2610,6 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high,
                        err = 0;
                        goto unlock;
                }
-               xfrm_state_put(x0);
                spin_unlock_bh(&net->xfrm.xfrm_state_lock);
 
 next: