u32_change() looks up a non-root hash node and keeps only a bare pointer while it allocates a filter handle in that node. The subsequent action initialization can drop RTNL to request an unregistered action module. A concurrent RTM_DELTFILTER can then delete and eventually free the hash node. When action initialization fails, the error cleanup removes the handle from the hash node's IDR through the stale pointer, causing a use-after-free read and write. Hold a reference on the hash node from before action initialization until all uses of the pointer on both the success and error paths are complete. This makes a concurrent deletion return -EBUSY. Fixes: e7614370d6f0 ("net_sched: use idr to allocate u32 filter handles") Signed-off-by: zhuorao yang --- Vulnerability report Affected versions: Linux 7.4.0-rc5 at fe6ff8d5d675c01793b9f051d16055dd4aa75244; the defect dates to v4.15 and applies to later kernels with CONFIG_NET_CLS_U32. Trigger conditions: CONFIG_NET_CLS_U32 and CONFIG_NET_CLS_ACT, with CAP_NET_ADMIN in the target network namespace. An RTM_NEWTFILTER request selects a non-root hash node and references an unregistered tc action, so request_module() drops RTNL. A concurrent RTM_DELTFILTER can delete the hash node during that window. Reproducer status: A QEMU test with a test-only modprobe delay showed that the unpatched kernel deletes the hash node and later runs idr_remove() through the stale pointer; kprobes recorded the destroyed IDR and the later access. With the patch, concurrent deletion returns -EBUSY and the error path only accesses the live hash node. Reproducer material is available to maintainers on request. Reproducer material is intentionally withheld from this public message. AI assistance: DeepSeek identified the issue and drafted the patch. The submitter reviewed the code and certified the Developer Certificate of Origin. net/sched/cls_u32.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 91f4e6458785..506640323335 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -1188,6 +1188,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, } #endif + refcount_inc(&ht->refcnt); err = u32_set_parms(net, tp, n, tb, tca[TCA_RATE], flags, n->flags, extack); @@ -1216,6 +1217,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, rcu_assign_pointer(*ins, n); tp_c->knodes++; *arg = n; + refcount_dec(&ht->refcnt); return 0; } @@ -1235,6 +1237,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, kfree(n); erridr: idr_remove(&ht->handle_idr, handle); + refcount_dec(&ht->refcnt); return err; } -- 2.56.0