Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net/sched: cls_u32: fix hnode UAF in u32_change
@ 2026-12-01  7:50 zhuorao yang
  0 siblings, 0 replies; only message in thread
From: zhuorao yang @ 2026-12-01  7:50 UTC (permalink / raw)
  To: Jamal Hadi Salim, Jiri Pirko, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn
  Cc: netdev

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 <alex000young@gmail.com>
---

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-01  7:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  7:50 [PATCH net] net/sched: cls_u32: fix hnode UAF in u32_change zhuorao yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox