Netdev List
 help / color / mirror / Atom feed
From: zhuorao yang <alex000young@gmail.com>
To: Jamal Hadi Salim <jhs@mojatatu.com>,
	Jiri Pirko <jiri@resnulli.us>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>
Cc: netdev@vger.kernel.org
Subject: [PATCH net] net/sched: cls_u32: fix hnode UAF in u32_change
Date: Tue,  1 Dec 2026 15:50:58 +0800	[thread overview]
Message-ID: <20261201075058.64049-1-alex000young@gmail.com> (raw)

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


                 reply	other threads:[~2026-12-01  7:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201075058.64049-1-alex000young@gmail.com \
    --to=alex000young@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox