* Re: [PATCH net] net/sched: cls_u32: fix hnode UAF in u32_change
2026-12-01 7:50 [PATCH net] net/sched: cls_u32: fix hnode UAF in u32_change zhuorao yang
@ 2026-12-04 7:50 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 7:50 UTC (permalink / raw)
To: alex000young; +Cc: jhs, jiri, davem, edumazet, kuba, pabeni, willemb, netdev
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 1 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Critical] In u32_change() (net/sched/cls_u32.c), the patch adds an
unconditional `refcount_dec(&ht->refcnt)` under the shared `erridr`…
- [Medium] The patch releases the pinned hash node with a plain
`refcount_dec()` (u32_change() lines 1220 and 1240).
--
net/sched: cls_u32: fix hnode UAF in u32_change
This patch takes a reference on the hash node in u32_change() before
u32_set_parms() and drops it on both the success and error paths. The goal
is to keep a concurrent RTM_DELTFILTER from freeing the hnode while RTNL is
dropped to load an action module.
> diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
> index 91f4e64587852..5066403233350 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);
[Severity: Medium]
Can this plain refcount_dec(), or the one under erridr, drop the last
reference to ht?
u32_init() adds every tcf_proto's root_ht to the shared tp_c->hlist. In
u32_change(), a TCA_U32_HASH value that is not TC_U32_ROOT goes through
this lookup:
ht = u32_lookup_ht(tp->data, TC_U32_HTID(htid));
There is no is_root or ownership check. The lookup can return the root_ht
of another u32 tcf_proto (a different prio) that shares the same
tc_u_common and has refcnt 1. This patch then raises it to 2.
Suppose action initialization drops RTNL for request_module(), and a
concurrent RTM_DELTFILTER removes the other tcf_proto. u32_destroy() then
runs:
if (root_ht && refcount_dec_and_test(&root_ht->refcnt))
u32_destroy_hnode(tp, root_ht, extack);
The count goes from 2 to 1 and u32_destroy_hnode() is skipped. The root ht
is left orphaned on tp_c->hlist.
The refcount_dec() here or at erridr then takes it from 1 to 0. That warns
with REFCOUNT_DEC_LEAK and saturates the counter.
After that, u32_delete() refuses the orphaned ht because is_root is set. The
teardown loop's refcount_dec_and_test() in u32_destroy() never reaches zero
either, so the hnode is leaked. On the success path, the leaked hnode also
holds the new knode.
The commit message says:
This makes a concurrent deletion return -EBUSY.
In this case the deletion of the other tcf_proto goes ahead instead of
returning -EBUSY.
Could the final release handle being the last reference, for example with
refcount_dec_and_test() followed by destroying the hnode? Or should
u32_change() avoid pinning another tcf_proto's root this way?
> 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);
[Severity: Critical]
Is this refcount_dec() balanced on every path that reaches erridr?
The matching refcount_inc() is only taken right before u32_set_parms().
Several earlier exits in u32_change() reach erridr after the handle has
been allocated but before that increment. The first one is:
if (tb[TCA_U32_SEL] == NULL) {
NL_SET_ERR_MSG_MOD(extack, "Selector not specified");
err = -EINVAL;
goto erridr;
}
These exits do the same:
- the short TCA_U32_SEL length check
- the offshift >= 16 check
- the kzalloc_flex() failure
- the n->pf percpu allocation failure (via errfree)
- the tcf_exts_init() failure (via errout)
- the pcpu_success allocation failure (via errout)
So a single RTM_NEWTFILTER that names an existing hash node (the root
included) and omits TCA_U32_SEL drops a reference that was never taken. No
race is needed.
If ht->refcnt is 1 (a fresh divisor table, or tp->root), it goes from 1 to
0. refcount_dec() warns with REFCOUNT_DEC_LEAK and saturates the counter,
and after that u32_delete() and u32_destroy() can never free the hnode.
If a knode links to the hnode through TCA_U32_LINK, refcnt is 2 and drops
to 1. A later RTM_DELTFILTER on that hnode then passes this check in
u32_delete():
if (refcount_dec_if_one(&ht->refcnt)) {
u32_destroy_hnode(tp, ht, extack);
u32_destroy_hnode() calls kfree_rcu() on the hnode while the linking
knode's ht_down still points at it. u32_classify() would then read freed
memory, and __u32_destroy_key() would run this on the freed hnode:
if (ht && refcount_dec_and_test(&ht->refcnt))
kfree(ht);
Would it work to take the reference right after the handle is allocated,
before the first goto erridr? Alternatively, the early exits could use a
label that skips the decrement.
> return err;
> }
>
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201075058.64049-1-alex000young%40gmail.com
^ permalink raw reply [flat|nested] 2+ messages in thread