From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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 ; Fri, 4 Dec 2026 07:51:00 +0000 (UTC) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BEAE1F000C2; Fri, 4 Dec 2026 07:50:59 +0000 (UTC) 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== Subject: Re: [PATCH net] net/sched: cls_u32: fix hnode UAF in u32_change From: netdev-bot+sashiko@kernel.org To: alex000young@gmail.com 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 Date: Fri, 04 Dec 2026 07:50:58 +0000 Message-ID: <179637065896.3146.17927365221769258223@kernel.org> In-Reply-To: <20261201075058.64049-1-alex000young@gmail.com> References: <20261201075058.64049-1-alex000young@gmail.com> X-sashiko-severity: Critical Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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