net/sched: teql: Enforce hierarchy placement
Subsystems (4)
Jamal Hadi Salim
maintainercover net/sched: teql: Enforce hierarchy placement
GangMin Kim <[email protected]> managed to create a UAF on qfq by inserting teql as a child qdisc and exploiting a qlen sync issue.
teql is not intended to be used as a child qdisc. Lets enforce that rule in patch #1. Although patch #1 fixes the issue, we prevent another potential qlen exploit in qfq in patch #2 by enforcing the child's active status is not determined by inspecting the qlen. In patch #3 we add a tdc test case.
Jamal Hadi Salim (2):
net/sched: Enforce that teql can only be used as root qdisc net/sched: qfq: Use cl_is_active to determine whether class is active
in qfq_rm_from_ag
Victor Nogueira (1):
selftests/tc-testing: Try to add teql as a child qdisc
net/sched/sch_qfq.c | 2 +- net/sched/sch_teql.c | 5 ++++ .../tc-testing/tc-tests/qdiscs/teql.json | 25 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
Jamal Hadi Salim
maintainerPATCH 1/3 net/sched: Enforce that teql can only be used as root qdisc
Design intent of teql is that it is only supposed to be used as root qdisc. We need to check for that constraint.
Although not important, I will describe the scenario that unearthed this issue for the curious.
GangMin Kim <[email protected]> managed to concot a scenario as follows:
ROOT qdisc 1:0 (QFQ)
├── class 1:1 (weight=15, lmax=16384) netem with delay 6.4s └── class 1:2 (weight=1, lmax=1514) teql
GangMin sends a packet which is enqueued to 1:1 (netem).
Any invocation of dequeue by QFQ from this class will not return a packet until after 6.4s. In the meantime, a second packet is sent and it lands on 1:2. teql's enqueue will return success and this will activate class 1:2. Main issue is that teql only updates the parent visible qlen (sch->q.qlen) at dequeue. Since QFQ will only call dequeue if peek succeeds (and teql's peek always returns NULL), dequeue will never be called and thus the qlen will remain as 0. With that in mind, when GangMin updates 1:2's lmax value, the qfq_change_class calls qfq_deact_rm_from_agg. Since the child qdisc's qlen was not incremented, qfq fails to deactivate the class, but still frees its pointers from the aggregate. So when the first packet is rescheduled after 6.4 seconds (netem's delay), a dangling pointer is accessed causing GangMin's causing a UAF.
--- net/sched/sch_teql.c | 5 +++++ 1 file changed, 5 insertions(+)
net/sched/sch_teql.c +5 -0
@@ -178,6 +178,11 @@ static int teql_qdisc_init(struct Qdisc *sch, struct nlattr *opt,if (m->dev == dev)return -ELOOP ; +if (sch->parent !=TC_H_ROOT ) { +NL_SET_ERR_MSG_MOD (extack,"teql can only be used as root" ); +return -EOPNOTSUPP ; + } + q->m = m;skb_queue_head_init (&q->q);
Signature · 1 line
2.34.1
Jamal Hadi Salim
maintainerPATCH 2/3 net/sched: qfq: Use cl_is_active to determine whether class is active in qfq_rm_from_ag
In reply to Jamal Hadi SalimThis is more of a preventive patch to make the code more consistent and to prevent possible exploits that employ child qlen manipulations on qfq. use cl_is_active instead of relying on the child qdisc's qlen to determine class activation.
--- net/sched/sch_qfq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_qfq.c +1 -1
@@ -373,7 +373,7 @@ static void qfq_rm_from_agg(struct qfq_sched *q, struct qfq_class *cl)/* Deschedule class and remove it from its parent aggregate. */ static void qfq_deact_rm_from_agg (struct qfq_sched *q,struct qfq_class *cl) { -if (cl->qdisc->q.qlen >0 )/* class is active */ +if (cl_is_active (cl))/* class is active */ qfq_deactivate_class (q, cl);qfq_rm_from_agg (q, cl);
Signature · 1 line
2.34.1
Jamal Hadi Salim
maintainerPATCH 3/3 selftests/tc-testing: Try to add teql as a child qdisc
In reply to Jamal Hadi SalimFrom: Victor Nogueira <[email protected]>
Add a selftest that attempts to add a teql qdisc as a qfq child. Since teql _must_ be added as a root qdisc, the kernel should reject this.
--- .../tc-testing/tc-tests/qdiscs/teql.json | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+)
tools/testing/selftests/tc-testing/tc-tests/qdiscs/teql.json +25 -0
@@ -81,5 +81,30 @@ "$TC qdisc del dev $DUMMY handle 1: root", "$IP link del dev $DUMMY" ] + }, + { + "id": "124e", + "name": "Try to add teql as a child qdisc", + "category": [ + "qdisc", + "ets", + "tbf" + ], + "plugins": { + "requires": [ + "nsPlugin" + ] + }, + "setup": [ + "$TC qdisc add dev $DUMMY root handle 1: qfq", + "$TC class add dev $DUMMY parent 1: classid 1:1 qfq weight 15 maxpkt 16384" + ], + "cmdUnderTest": "$TC qdisc add dev $DUMMY parent 1:1 handle 2:1 teql0", + "expExitCode": "2", + "verifyCmd": "$TC -s -j qdisc ls dev $DUMMY parent 1:1", + "matchJSON": [], + "teardown": [ + "$TC qdisc del dev $DUMMY root handle 1:" + ] } ]
Signature · 1 line
2.34.1
Quoted 7 lines · Jamal Hadi Salim
GangMin Kim <[email protected]> managed to create a UAF on qfq by inserting teql as a child qdisc and exploiting a qlen sync issue.
teql is not intended to be used as a child qdisc. Lets enforce that rule in patch #1. Although patch #1 fixes the issue, we prevent another potential qlen exploit in qfq in patch #2 by enforcing the child's active status is not determined by inspecting the qlen. In patch #3 we add a tdc test case.
Is teql still used by anyone? If not, maybe it is time to remove it.
Regards,
Cong
Jamal Hadi Salim
maintainerQuoted 12 lines · Cong Wang
Quoted 7 lines · Jamal Hadi Salim
GangMin Kim <[email protected]> managed to create a UAF on qfq by inserting teql as a child qdisc and exploiting a qlen sync issue.
teql is not intended to be used as a child qdisc. Lets enforce that rule in patch #1. Although patch #1 fixes the issue, we prevent another potential qlen exploit in qfq in patch #2 by enforcing the child's active status is not determined by inspecting the qlen. In patch #3 we add a tdc test case.Is teql still used by anyone? If not, maybe it is time to remove it.
qfq is a better candidat - because it is a magnet for hierachical set ups by bounty hunters. And i have emailed the author several times with zero responses.
Teql is stable and used by from what i have personally seen small home/business routers to aggregate multiple isp links.
cheers,
jamal
Quoted 2 lines
Regards,
Cong
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 8 lines · On Wed, 14 Jan 2026 11:02:40 -0500 you wrote:
GangMin Kim <[email protected]> managed to create a UAF on qfq by inserting teql as a child qdisc and exploiting a qlen sync issue.
teql is not intended to be used as a child qdisc. Lets enforce that rule in patch #1. Although patch #1 fixes the issue, we prevent another potential qlen exploit in qfq in patch #2 by enforcing the child's active status is not determined by inspecting the qlen. In patch #3 we add a tdc test case.[...]
Here is the summary with links:
- [net,1/3] net/sched: Enforce that teql can only be used as root qdisc
https://git.kernel.org/netdev/net/c/50da4b9d07a7 - [net,2/3] net/sched: qfq: Use cl_is_active to determine whether class is active in qfq_rm_from_ag https://git.kernel.org/netdev/net/c/d837fbee9245 - [net,3/3] selftests/tc-testing: Try to add teql as a child qdisc https://git.kernel.org/netdev/net/c/2460f31e6e44
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html