Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net/sched: cls_u32: skip hash tables in u32_bind_class()
@ 2026-08-07  7:50 Zhang Changzhong
  2026-08-10 14:41 ` Jamal Hadi Salim
  2026-08-12  1:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Zhang Changzhong @ 2026-08-07  7:50 UTC (permalink / raw)
  To: Cong Wang, David S. Miller, netdev, linux-kernel
  Cc: Zhang Changzhong, Jamal Hadi Salim, Jiri Pirko, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Wei Yongjun

u32_walk() enumerates both struct tc_u_hnode and struct tc_u_knode
through the walker callback. u32_bind_class() unconditionally casts the
passed fh to tc_u_knode and accesses &n->res, so when fh is actually a
tc_u_hnode, which has no tcf_result member, this results in a
slab-out-of-bounds read of res->classid in tc_cls_bind_class().

The issue can be reproduced with the following commands:

    tc qdisc add dev lo root handle 1: hfsc
    tc class add dev lo parent 1: classid 1:1 hfsc sc rate 1000kbit
    tc filter add dev lo parent 1:1 protocol ip prio 1 u32 match u32 0 0 flowid 1:1
    tc class add dev lo parent 1: classid 1:2 hfsc sc rate 2000kbit

Fix this by skipping hash tables via the TC_U32_KEY(handle) check.

Fixes: 07d79fc7d94e ("net_sched: add reverse binding for tc class")
Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
---
 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 34d25f7..90ad80b 100644
--- a/net/sched/cls_u32.c
+++ b/net/sched/cls_u32.c
@@ -1250,6 +1250,9 @@ static void u32_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
 {
 	struct tc_u_knode *n = fh;
 
+	if (TC_U32_KEY(n->handle) == 0)
+		return;
+
 	tc_cls_bind_class(classid, cl, q, &n->res, base);
 }
 
-- 
2.9.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net/sched: cls_u32: skip hash tables in u32_bind_class()
  2026-08-07  7:50 [PATCH net] net/sched: cls_u32: skip hash tables in u32_bind_class() Zhang Changzhong
@ 2026-08-10 14:41 ` Jamal Hadi Salim
  2026-08-12  1:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Jamal Hadi Salim @ 2026-08-10 14:41 UTC (permalink / raw)
  To: Zhang Changzhong
  Cc: Cong Wang, David S. Miller, netdev, linux-kernel, Jiri Pirko,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Wei Yongjun

On Fri, Aug 7, 2026 at 2:58 AM Zhang Changzhong
<zhangchangzhong@huawei.com> wrote:
>
> u32_walk() enumerates both struct tc_u_hnode and struct tc_u_knode
> through the walker callback. u32_bind_class() unconditionally casts the
> passed fh to tc_u_knode and accesses &n->res, so when fh is actually a
> tc_u_hnode, which has no tcf_result member, this results in a
> slab-out-of-bounds read of res->classid in tc_cls_bind_class().
>
> The issue can be reproduced with the following commands:
>
>     tc qdisc add dev lo root handle 1: hfsc
>     tc class add dev lo parent 1: classid 1:1 hfsc sc rate 1000kbit
>     tc filter add dev lo parent 1:1 protocol ip prio 1 u32 match u32 0 0 flowid 1:1
>     tc class add dev lo parent 1: classid 1:2 hfsc sc rate 2000kbit
>
> Fix this by skipping hash tables via the TC_U32_KEY(handle) check.
>

Reproduced.
The commit message would be better with what the sashikos prescribed:
example to describe the type-confusion impact accurately (wrong-field
read/write + spurious refcount, OOB read only under the tracker
config) rather than "slab-out-of-bounds read" or "OOB store".
Dont want to push for v2:
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>

cheers,
jamal


> Fixes: 07d79fc7d94e ("net_sched: add reverse binding for tc class")
> Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
> ---
>  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 34d25f7..90ad80b 100644
> --- a/net/sched/cls_u32.c
> +++ b/net/sched/cls_u32.c
> @@ -1250,6 +1250,9 @@ static void u32_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
>  {
>         struct tc_u_knode *n = fh;
>
> +       if (TC_U32_KEY(n->handle) == 0)
> +               return;
> +
>         tc_cls_bind_class(classid, cl, q, &n->res, base);
>  }
>
> --
> 2.9.5
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net/sched: cls_u32: skip hash tables in u32_bind_class()
  2026-08-07  7:50 [PATCH net] net/sched: cls_u32: skip hash tables in u32_bind_class() Zhang Changzhong
  2026-08-10 14:41 ` Jamal Hadi Salim
@ 2026-08-12  1:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-08-12  1:40 UTC (permalink / raw)
  To: Zhang Changzhong
  Cc: xiyou.wangcong, davem, netdev, linux-kernel, jhs, jiri, edumazet,
	kuba, pabeni, weiyongjun1

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 7 Aug 2026 15:50:38 +0800 you wrote:
> u32_walk() enumerates both struct tc_u_hnode and struct tc_u_knode
> through the walker callback. u32_bind_class() unconditionally casts the
> passed fh to tc_u_knode and accesses &n->res, so when fh is actually a
> tc_u_hnode, which has no tcf_result member, this results in a
> slab-out-of-bounds read of res->classid in tc_cls_bind_class().
> 
> The issue can be reproduced with the following commands:
> 
> [...]

Here is the summary with links:
  - [net] net/sched: cls_u32: skip hash tables in u32_bind_class()
    https://git.kernel.org/netdev/net/c/6d3724e616fa

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-12  1:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-07  7:50 [PATCH net] net/sched: cls_u32: skip hash tables in u32_bind_class() Zhang Changzhong
2026-08-10 14:41 ` Jamal Hadi Salim
2026-08-12  1:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox