Re: [PATCH] xfrm: force flush upon NETDEV_UNREGISTER event
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Date: 2026-01-22 13:08:28
Also in:
linux-security-module
Subsystem:
networking [general], networking [ipsec], the rest · Maintainers:
"David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Steffen Klassert, Herbert Xu, Linus Torvalds
On 2026/01/22 20:32, Steffen Klassert wrote:
On Thu, Jan 22, 2026 at 08:28:31PM +0900, Tetsuo Handa wrote:quoted
On 2026/01/22 20:15, Steffen Klassert wrote:quoted
Hm, I'd say we should not try to offload to a device that does not support NETIF_F_HW_ESP.I was about to post the patch below, but you are suggesting that "do not allow calling xfrm_dev_state_add()/xfrm_dev_policy_add() if (dev->features & NETIF_F_HW_ESP) == 0" ?As said, I think this is the correct way to do it. But let's wait on opinions from the hardware people.
OK. I guess something like below. net/xfrm/xfrm_device.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/net/xfrm/xfrm_device.c b/net/xfrm/xfrm_device.c
index 52ae0e034d29..19aa61609d24 100644
--- a/net/xfrm/xfrm_device.c
+++ b/net/xfrm/xfrm_device.c@@ -292,6 +292,13 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x, dst_release(dst); } + if (!(dev->features & NETIF_F_HW_ESP)) { + NL_SET_ERR_MSG(extack, "Device doesn't support offload"); + xso->dev = NULL; + dev_put(dev); + return -EINVAL; + } + if (!dev->xfrmdev_ops || !dev->xfrmdev_ops->xdo_dev_state_add) { xso->dev = NULL; dev_put(dev);
@@ -367,7 +374,8 @@ int xfrm_dev_policy_add(struct net *net, struct xfrm_policy *xp, if (!dev) return -EINVAL; - if (!dev->xfrmdev_ops || !dev->xfrmdev_ops->xdo_dev_policy_add) { + if (!dev->xfrmdev_ops || !dev->xfrmdev_ops->xdo_dev_policy_add || + !(dev->features & NETIF_F_HW_ESP)) { xdo->dev = NULL; dev_put(dev); NL_SET_ERR_MSG(extack, "Policy offload is not supported");
On 2026/01/22 20:15, Steffen Klassert wrote:
quoted
But I have a question regarding security_xfrm_state_delete()/security_xfrm_policy_delete(). xfrm_dev_state_flush_secctx_check() calls security_xfrm_state_delete() which can make xfrm_dev_state_flush() no-op by returning an error value. xfrm_dev_policy_flush_secctx_check() calls security_xfrm_policy_delete() which can make xfrm_dev_policy_flush() no-op by returning an error value. Since xfrm_dev_state_flush()/xfrm_dev_policy_flush() are called by NETDEV_UNREGISTER event (which is a signal for releasing all resources that prevent "struct net_device" references from dropping), making xfrm_dev_state_flush()/xfrm_dev_policy_flush() no-op (by allowing security_xfrm_state_delete()/security_xfrm_policy_delete() to return an error) is a denial-of-service bug.This means that the calling task doesn't have the permission to delete the state, some LSM has a policy the does not grant this permission.
But NETDEV_UNREGISTER event can fire without explicit request from a user.
Roughly speaking, current behavior is that
while (security_xfrm_state_delete() != 0) {
schedule_timeout_uninterruptible(10 * HZ);
pr_emerg("unregister_netdevice: waiting for %s to become free. Usage count = %d\n",
dev->name, netdev_refcnt_read(dev));
}
while (security_xfrm_policy_delete() != 0) {
schedule_timeout_uninterruptible(10 * HZ);
pr_emerg("unregister_netdevice: waiting for %s to become free. Usage count = %d\n",
dev->name, netdev_refcnt_read(dev));
}
might be executed upon e.g. termination of a userspace process.
quoted
Therefore, I wonder what are security_xfrm_state_delete() and security_xfrm_policy_delete() for. Can I kill xfrm_dev_state_flush_secctx_check() and xfrm_dev_policy_flush_secctx_check() ?This might violate a LSM policy then.
But LSM policy that results in system hung upon automatic cleanup logic is so stupid. I want to kill xfrm_dev_state_flush_secctx_check() and xfrm_dev_policy_flush_secctx_check() in order to eliminate possibility of system hung.