Article View: linux.kernel.netdev
Article #26819Re: [PATCH net] net/sched: cls_u32: fix hnode UAF in u32_change
From: netdev-bot+sashiko
Date: Fri, 04 Dec 2026 07:50
Date: Fri, 04 Dec 2026 07:50
150 lines
13233 bytes
13233 bytes
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
Technical Details
Message-ID:
<179637065896.3146.17927365221769258223@kernel.org>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377170-linux-kernel-netdev=dewy.ruReferences:
<20261201075058.64049-1-alex000young@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377170-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] net/sched: cls_u32: fix hnode UAF in u32_change Date: Fri, 04 Dec 2026 07:50:58 +0000 Organization: Usenet Network Message-ID: <179637065896.3146.17927365221769258223@kernel.org> References: <20261201075058.64049-1-alex000young@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2708593"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:XkpeyHxmRhKygxyXKTnEXvL5uZI= sha256:wLfPU+4HApIXKXrdEeY8KTorm2+YIelUOCAiu9Xif1s= sha1:ZmzJJKPKJG11Bz+WG/Z8z8R9BdI= sha256:0uiOjMvFkywr2it9F0gd+fmuthRu7SjGCTKQCLdtKLo= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 0DBFC117B58; Fri, 4 Dec 2026 10:51:15 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.739 X-Spam-Status: No, score=-3.739 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F6y_MkRTLgtX; Fri, 4 Dec 2026 10:51:11 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-377170-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 88BB5117B46; Fri, 4 Dec 2026 10:51:03 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 260A725C34; Fri, 4 Dec 2026 07:51:02 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796370661; b=KUqL9c4wNqwJCFx9HBCIpXVIyReSRQ1fSMd3chobglYZHGTXY2EdEfioywa46ZUSjH+K P+g4Xjv6Ce7WesYAEyV1a9mpeW24r1uXusmxNzhvziv2gm358GVzieU3cM6G7ObN+Elfy yMn5DqolVnuaqi0q8IvGJ5A851HihtzUsGcaC2KGNdMOzxFecyOAhXrVPGTtyMMpxwjYO xL2HrgR6/GDjJ/hus+1qYD+QMgWBKio79X+HCdMLB4DD5+rVUQUzm0Dt4SDcweKLVaBNs BcaUEKYCcsXhCwKTfDF5mF+QQGdbUUroyw0PsOTdiwDTIC3YMZRss3JdCzZtNHw5uqA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796370661; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=vd6HvPEYo2xw0R6JupJJGIEclV+oUQdN+8pC9vZg3M8=; b=LuO2Nxx7qx3LxIpqztaV5J+WHN58PhkmkbpomKYkqVtJxM7PJ0C3lNRCcja3Ht32jQKH purXjT69/yStImUjgBzX0nKyTiHGGGWLBdqHd6dM8eFSNG+pRtqWFIqaryBc8IExVfF+E YyEfSGnWgrpmP9WmbUgsmL+wkZ9pkUa+LxafLyMPI3dukMEE9Kc9cayrwa5qR6shEKO+B WKnXuTbVfooS6+2+7qGCUZ9nH0M//sCa9xLw0/ehMKtOlxPWHeDOFmCeUAZ5zSAMQIKVI qFcY1ojOcMJnNLD1RsNZCCY/ooVIXh6GnSb891GV/Y2jvoEeZ/WvtpaYb0l0dq3Unsg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QW3SN0rT; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3F14D606A335; Fri, 4 Dec 2026 07:51:01 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QW3SN0rT X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796370660; b=P+dJBvNYF4TUpjiWiCfJX/9VYJdfVCYr5yYkjjWEB+VP44onVVL8qb9uPw8ndgqmu4f7 zwQNxM1KHqFk1ItQ0kviN3ELY5IllgKXg/R+Y8pZBVqEMzWuA2x8JcVq8o2V52hJy/jRF gMqkVKGcezE9xnqAl1Q8lc5SjPta86p8XqLXHV6AnDhOiYMwIXYScPA3AGSvt5wSRvF7X 2ra9QOk4Le11ma4rtoKNKxH2BX8Jx/YbKtIdXKqrKVBjtC/8xMxAr8NxiA1VScjYiU1AV ASsUZfonr17IAdzzL+xdQGV6ChLlI8ht9GA/2Fi+DJ1h9gIUe10FlchcPl0FFszN7AQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796370660; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=vd6HvPEYo2xw0R6JupJJGIEclV+oUQdN+8pC9vZg3M8=; b=tyqwO1sYP9eTBQ1r9cuu6hlv7Tp8qlM2VxWIgXCvqIffUsy3V9K0nE6nFpGBngruBhW2 y+Ngcv6F4wgtMy0NOulDKWqCok0ajKdCE6CuojxFvPDUjJQArZL7du4ULS+OyVJvB9dKp w8WWu1dfeRl/WD2WGaF5DFCROxgDRB9+Xi62B4rReZlDqP9k6yLRtKRVsINCy/cggwkPH ldq5OMICHPRK1Cf7/9Idtn7vCPonAfl9+n1IY2VPPWM9OO0dZAJIXW6fflx+EyGQ16lvp OaxN86Vk+7k2dZCZKxbCB1101IO9fmHGMP9MIiGho2toj6n+8acP9fMBGPb/SqxO6ZA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QW3SN0rT; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A7B0606A32C for <netdev@vger.kernel.org>; Fri, 4 Dec 2026 07:51:00 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BEAE1F000C2; Fri, 4 Dec 2026 07:50:59 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796370659; bh=vd6HvPEYo2xw0R6JupJJGIEclV+oUQdN+8pC9vZg3M8=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=QW3SN0rTQIEt0fMZpkit6XzCs6kfpY22kjajy+42NaQIMbzOiTXeuoKYntBQKFBQS sMGKUtH3lkJ47CvdNz+JHrYwa/RgitRKQmFf5vbjNrq1vbFsFG81mmQQbx3VCKJQFW lwHgWl2xbfNgXRz7gFE70C27Nvh1FfbsyZoZGZly8C9pM3fkhK4q7mDjQRftqxVGPU 2Y9S6eQ+sox4PQ3aKCgE4Tp7ACVxKOuV0oUZetJx1WKmWKjxJR+idwMXvwCX3yo4D7 6qAJZHLVzlO8hhsuXpVJSUIL78+I+qaepzWLrKiBrJV7JdyBvLtYSm+kW7lpSeEgRS R1btTIUjn6A6w== X-Cc: jhs@mojatatu.com, jiri@resnulli.us, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, netdev@vger.kernel.org X-In-Reply-To: <20261201075058.64049-1-alex000young@gmail.com> X-sashiko-severity: Critical X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list