On Mon, Nov 30, 2026 at 7:52 AM Jedrzej Jagielski
<jedr…@intel.com> wrote:
>
> When a new filter is created with TCA_U32_LINK, u32_set_parms() resolves
> the linked hash table and increments its reference count, storing it in
> n->ht_down.
>
> If u32_replace_hw_knode() subsequently fails, execution jumps to the
> errunbind label which frees the node with kfree(n) but never drops the
> reference on n->ht_down. This leaves the tc_u_hnode refcount permanently
> elevated, preventing it from being freed when the hash table is later
> deleted.
>
> Drop the ht_down reference at errunbind before freeing the node.
>
> This is a forward fix for currently dead code, which will be uncovered
> by the upcoming patch "net/sched: cls_u32: feed u32_replace_hw_knode()
> with correct set of flags".
>
> Fixes: d34e3e181395 ("net: cls_u32: Add support for skip-sw flag to tc u32 classifier.")
> Cc: stab…@vger.kernel.org
> Reported-by: Sashiko <sash…@kernel.org>
> Closes: https://sashiko.dev/#/patchset/2026…%40intel.com
> Signed-off-by: Jedrzej Jagielski <jedr…@intel.com>
Reviewed-by: Jamal Hadi Salim <j…@mojatatu.com>
cheers,
jamal
> ---
> net/sched/cls_u32.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
> index 91f4e6458785..c544c8e4e876 100644
> --- a/net/sched/cls_u32.c
> +++ b/net/sched/cls_u32.c
> @@ -891,7 +891,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
> struct netlink_ext_ack *extack)
> {
> struct tc_u_common *tp_c = tp->data;
> - struct tc_u_hnode *ht;
> + struct tc_u_hnode *ht, *ht_down;
> struct tc_u_knode *n;
> struct tc_u32_sel *s;
> struct nlattr *opt = tca[TCA_OPTIONS];
> @@ -1221,6 +1221,9 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
>
> errunbind:
> u32_unbind_filter(tp, n, tb);
> + ht_down = rtnl_dereference(n->ht_down);
> + if (ht_down && refcount_dec_and_test(&ht_down->refcnt))
> + kfree(ht_down);
>
> #ifdef CONFIG_CLS_U32_MARK
> free_percpu(n->pcpu_success);
> --
> 2.31.1
>