Skip to contentSkip to conversation

net_sched: Prevent creation of classes with TC_H_ROOT

PATCH Applied Cong Wang 4 participants 9 messages Mar 6, 2025 – Mar 12, 2025

Subsystems (4)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

cover net_sched: Prevent creation of classes with TC_H_ROOT

This patchset contains a bug fix and its TDC test case.

---

Cong Wang (2):
net_sched: Prevent creation of classes with TC_H_ROOT selftests/tc-testing: Add a test case for DRR class with TC_H_ROOT

 net/sched/sch_api.c                           |  6 +++++
 .../tc-testing/tc-tests/qdiscs/drr.json       | 25 +++++++++++++++++++
 2 files changed, 31 insertions(+)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/2 net_sched: Prevent creation of classes with TC_H_ROOT

The function qdisc_tree_reduce_backlog() uses TC_H_ROOT as a termination condition when traversing up the qdisc tree to update parent backlog counters. However, if a class is created with classid TC_H_ROOT, the traversal terminates prematurely at this class instead of reaching the actual root qdisc, causing parent statistics to be incorrectly maintained. In case of DRR, this could lead to a crash as reported by Mingi Cho.

Prevent the creation of any Qdisc class with classid TC_H_ROOT (0xFFFFFFFF) across all qdisc types, as suggested by Jamal.

---
 net/sched/sch_api.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/sched/sch_api.c +6 -0
index e3e91cf867eb..6c625dcd0651 100644
@@ -2254,6 +2254,12 @@ static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n,
 		return -EOPNOTSUPP;
 	}
 
+	/* Prevent creation of traffic classes with classid TC_H_ROOT */
+	if (clid == TC_H_ROOT) {
+		NL_SET_ERR_MSG(extack, "Cannot create traffic class with classid TC_H_ROOT");
+		return -EINVAL;
+	}
+
 	new_cl = cl;
 	err = -EOPNOTSUPP;
 	if (cops->change)
Signature · 1 line
2.34.1
reviewer
#2 lore raw
Quoted 7 lines · Cong Wang

The function qdisc_tree_reduce_backlog() uses TC_H_ROOT as a termination condition when traversing up the qdisc tree to update parent backlog counters. However, if a class is created with classid TC_H_ROOT, the traversal terminates prematurely at this class instead of reaching the actual root qdisc, causing parent statistics to be incorrectly maintained. In case of DRR, this could lead to a crash as reported by Mingi Cho.

Quoted 5 lines

Prevent the creation of any Qdisc class with classid TC_H_ROOT (0xFFFFFFFF) across all qdisc types, as suggested by Jamal.

Hi Cong,

This change looks good to me.
But could we get a fixes tag?`

...

maintainer
#3 lore raw
Quoted 14 lines · Simon Horman
Quoted 7 lines · Cong Wang

The function qdisc_tree_reduce_backlog() uses TC_H_ROOT as a termination condition when traversing up the qdisc tree to update parent backlog counters. However, if a class is created with classid TC_H_ROOT, the traversal terminates prematurely at this class instead of reaching the actual root qdisc, causing parent statistics to be incorrectly maintained. In case of DRR, this could lead to a crash as reported by Mingi Cho.

Quoted 5 lines

Prevent the creation of any Qdisc class with classid TC_H_ROOT (0xFFFFFFFF) across all qdisc types, as suggested by Jamal.

Quoted 6 lines

Hi Cong,

This change looks good to me.
But could we get a fixes tag?`

...

Should be:

Fixes 066a3b5b2346 ("[NET_SCHED] sch_api: fix

qdisc_tree_decrease_qlen() loop")

right?

/P

reviewer Reviewed-by
#4 lore raw
Quoted 22 lines · Paolo Abeni
Quoted 19 lines · Simon Horman
Quoted 7 lines · Cong Wang

The function qdisc_tree_reduce_backlog() uses TC_H_ROOT as a termination condition when traversing up the qdisc tree to update parent backlog counters. However, if a class is created with classid TC_H_ROOT, the traversal terminates prematurely at this class instead of reaching the actual root qdisc, causing parent statistics to be incorrectly maintained. In case of DRR, this could lead to a crash as reported by Mingi Cho.

Quoted 5 lines

Prevent the creation of any Qdisc class with classid TC_H_ROOT (0xFFFFFFFF) across all qdisc types, as suggested by Jamal.

Hi Cong,

This change looks good to me.
But could we get a fixes tag?`

Quoted 6 lines
Quoted 1 line

...

Should be:

Fixes 066a3b5b2346 ("[NET_SCHED] sch_api: fix

qdisc_tree_decrease_qlen() loop")

Thanks.

Looking at that, I might have gone for the following commit, which is a fix for the above one. But either way is fine by me.

commit 2e95c4384438 ("net/sched: stop qdisc_tree_reduce_backlog on TC_H_ROOT")

author
#5 lore raw
Quoted 30 lines · Simon Horman
Quoted 22 lines · Paolo Abeni
Quoted 19 lines · Simon Horman
Quoted 7 lines · Cong Wang

The function qdisc_tree_reduce_backlog() uses TC_H_ROOT as a termination condition when traversing up the qdisc tree to update parent backlog counters. However, if a class is created with classid TC_H_ROOT, the traversal terminates prematurely at this class instead of reaching the actual root qdisc, causing parent statistics to be incorrectly maintained. In case of DRR, this could lead to a crash as reported by Mingi Cho.

Quoted 5 lines

Prevent the creation of any Qdisc class with classid TC_H_ROOT (0xFFFFFFFF) across all qdisc types, as suggested by Jamal.

Hi Cong,

This change looks good to me.
But could we get a fixes tag?`

Quoted 6 lines
Quoted 1 line

...

Should be:

Fixes 066a3b5b2346 ("[NET_SCHED] sch_api: fix

qdisc_tree_decrease_qlen() loop")

Quoted 6 lines

Thanks.

Looking at that, I might have gone for the following commit, which is a fix for the above one. But either way is fine by me.

commit 2e95c4384438 ("net/sched: stop qdisc_tree_reduce_backlog on TC_H_ROOT")

Indeed it is. Sorry for forgetting about it.

Thanks a lot!

author
#6 lore raw

PATCH 2/2 selftests/tc-testing: Add a test case for DRR class with TC_H_ROOT

In reply to Cong Wang

Integrate the reproduer from Mingi to TDC.

All test results:

1..4
ok 1 0385 - Create DRR with default setting
ok 2 2375 - Delete DRR with handle
ok 3 3092 - Show DRR class
ok 4 4009 - Reject creation of DRR class with classid TC_H_ROOT

---
 .../tc-testing/tc-tests/qdiscs/drr.json       | 25 +++++++++++++++++++
 1 file changed, 25 insertions(+)
tools/testing/selftests/tc-testing/tc-tests/qdiscs/drr.json +25 -0
index 7126ec3485cb..2b61d8d79bde 100644
@@ -61,5 +61,30 @@
         "teardown": [
             "$TC qdisc del dev $DUMMY handle 1: root"
         ]
+    },
+    {
+        "id": "4009",
+        "name": "Reject creation of DRR class with classid TC_H_ROOT",
+        "category": [
+            "qdisc",
+            "drr"
+        ],
+        "plugins": {
+            "requires": "nsPlugin"
+        },
+        "setup": [
+            "$TC qdisc add dev $DUMMY root handle ffff: drr",
+            "$TC filter add dev $DUMMY parent ffff: basic classid ffff:1",
+            "$TC class add dev $DUMMY parent ffff: classid ffff:1 drr",
+            "$TC filter add dev $DUMMY parent ffff: prio 1 u32 match u16 0x0000 0xfe00 at 2 flowid ffff:ffff"
+        ],
+        "cmdUnderTest": "$TC class add dev $DUMMY parent ffff: classid ffff:ffff drr",
+        "expExitCode": "2",
+        "verifyCmd": "$TC class show dev $DUMMY",
+        "matchPattern": "class drr ffff:ffff",
+        "matchCount": "0",
+        "teardown": [
+            "$TC qdisc del dev $DUMMY root"
+        ]
     }
 ]
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 2/2
#7 lore raw

Re: [Patch net 2/2] selftests/tc-testing: Add a test case for DRR class with TC_H_ROOT

Quoted 4 lines · Cong Wang

Integrate the reproduer from Mingi to TDC.

All test results:

Quoted 8 lines

1..4
ok 1 0385 - Create DRR with default setting
ok 2 2375 - Delete DRR with handle
ok 3 3092 - Show DRR class
ok 4 4009 - Reject creation of DRR class with classid TC_H_ROOT

#8 lore raw
In reply to Cong Wang
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Thu, 6 Mar 2025 15:23:53 -0800 you wrote:

This patchset contains a bug fix and its TDC test case.

---

Cong Wang (2):
net_sched: Prevent creation of classes with TC_H_ROOT selftests/tc-testing: Add a test case for DRR class with TC_H_ROOT

[...]

Here is the summary with links:
- [net,1/2] net_sched: Prevent creation of classes with TC_H_ROOT

    https://git.kernel.org/netdev/net/c/0c3057a5a04d
  - [net,2/2] selftests/tc-testing: Add a test case for DRR class with TC_H_ROOT
    https://git.kernel.org/netdev/net/c/bb7737de5f59

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html