]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
xfrm: Fix xfrm state cache insertion race
authorHerbert Xu <herbert@gondor.apana.org.au>
Fri, 12 Jun 2026 04:58:59 +0000 (12:58 +0800)
committerSteffen Klassert <steffen.klassert@secunet.com>
Wed, 17 Jun 2026 09:17:17 +0000 (11:17 +0200)
commitddd3d0132920319ac426e12456013eadbae67e15
treee1c8e4a41d57ef1408cac1ee61f8c2a7d4d405d1
parent8045c0df98d4f14c54e5cb875f1c9c0ce89fe4ff
xfrm: Fix xfrm state cache insertion race

The xfrm input state cache insertion code checks the validity of
the state before acquiring the global xfrm_state_lock.  Thus it's
possible for someone else to kill the state after it passed the
validity check, and then the insertion will add the dead state
to the cache.

Fix this by moving the validity check inside the lock.

This entire function is called on the input path, where BH must
be off (e.g., the caller of this function xfrm_input acquires
its spinlocks without disabling BH).

So there is no need to disable BH here or take the RCU read lock.
Remove both and replace them with an assertion that trips if BH
is accidentally enabled on some future calling path.

Fixes: 81a331a0e72d ("xfrm: Add an inbound percpu state cache.")
Reported-by: Zero Day Initiative <zdi-disclosures@trendmicro.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/xfrm/xfrm_state.c