nfp: hold IPsec RX state under the XArray lock
Subsystems (3)
PATCH 1/1 nfp: hold IPsec RX state under the XArray lock
nfp_net_ipsec_rx() drops the XArray lock before taking a reference to the xfrm_state it found. The delete path can erase the entry and drop the last state reference in that interval. RX can then try to increment a zero refcount after the state has been queued for destruction.
The driver queues firmware invalidation asynchronously; the delete path does not wait for the command to complete or drain pending RX processing.
The XFRM garbage collector waits for an RCU grace period before freeing the state. That delays reclamation but does not make acquiring a reference from zero valid.
Take the xfrm_state reference before releasing the XArray lock so xa_erase() cannot run between lookup and reference acquisition.
---
Found during source review at mainline 5dd1818b15d98d4a20806cd00b1b40320b06004f. The affected source is unchanged at 93f51579e7df248780214094418f205253383cc5.
The modified ipsec.o compiled in an x86 allmodconfig build. I have not tested this with NFP IPsec offload hardware or reproduced the race with a sanitizer. In particular, firmware invalidation and pending RX processing have not been exercised together on hardware.
drivers/net/ethernet/netronome/nfp/crypto/ipsec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/netronome/nfp/crypto/ipsec.c +2 -1
@@ -625,11 +625,12 @@ int nfp_net_ipsec_rx(struct nfp_meta_parsed *meta, struct sk_buff *skb)xa_lock (&nn->xa_ipsec); x =xa_load (&nn->xa_ipsec, saidx); +if (x) +xfrm_state_hold (x);xa_unlock (&nn->xa_ipsec);if (!x)return -EINVAL ; -xfrm_state_hold (x); sp->xvec[sp->len++] = x; sp->olen++; xo =xfrm_offload (skb);
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Tue, 22 Sep 2026 03:15:59 +0900 you wrote:
nfp_net_ipsec_rx()drops the XArray lock before taking a reference to thexfrm_stateit found. The delete path can erase the entry and drop the last state reference in that interval. RX can then try to increment a zero refcount after the state has been queued for destruction.The driver queues firmware invalidation asynchronously; the delete path does not wait for the command to complete or drain pending RX processing.
[...]
Here is the summary with links:
- [net] nfp: hold IPsec RX state under the XArray lock
https://git.kernel.org/netdev/net/c/1a983a4e14c6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html