net/sched: sch_cake: fix unintended tin override with cake_mq
Subsystems (4)
PATCH 1/1 net/sched: sch_cake: fix unintended tin override with cake_mq
CAKE allows overriding the tin selection through skb->priority: if the major number of skb->priority matches the qdisc handle, the minor number selects the tin. With cake_mq, the per-queue CAKE instances are created through qdisc_create_dflt() and never get a handle assigned, so sch->handle is 0 for all of them.
For forwarded IPv4 traffic, ip_forward() sets skb->priority from the TOS byte via rt_tos2priority() when net.ipv4.ip_forward_update_priority is enabled, which is the default. rt_tos2priority() returns 0, 2, 4 or 6, all with a major number of 0, which matches the handle of the cake_mq children. The minor number is then taken as a tin override and the DSCP mapping is skipped.
With diffserv4 and diffserv8 this puts packets into the wrong tins. For example, AF13 (TOS byte 0x38) under diffserv4:
ip_forward():
skb->priority = ip_tos2prio[(0x38 & 0x1E) >> 1]
= ip_tos2prio[12] = TC_PRIO_INTERACTIVE_BULK = 4
cake_select_tin():
TC_H_MAJ(4) == 0 == sch->handle
tin = bulk_order[4 - 1] = 3 -> Voicewhereas the DSCP table gives diffserv4[0x38 >> 2] = diffserv4[14] = 0, i.e. Best Effort. Likewise, AF21, AF31 and AF41 are demoted from Video to Best Effort. diffserv3 happens to be unaffected, because the only reachable override (priority 2) agrees with its DSCP table.
Fix this by matching skb->priority against the major number of the parent cake_mq qdisc when the instance is part of cake_mq.
---
Reproducer: client -> router -> server over veth, router forwarding with the default ip_forward_update_priority=1, cake_mq diffserv4 on the router's egress (2 txqs). Ping with -Q 0x38 (AF13), compare per-tin counters against plain cake:
Bulk Best Effort Video Voice
cake: 0 50 0 0 cake_mq before: 0 0 0 50 cake_mq after: 0 50 0 0
Setting ip_forward_update_priority=0 also hides the bug.
--- net/sched/sch_cake.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/sched/sch_cake.c +4 -2
@@ -1679,7 +1679,7 @@ static struct cake_tin_data *cake_select_tin(struct Qdisc *sch, {struct cake_sched_data *qd =qdisc_priv (sch);struct cake_sched_config *q = qd->config; -u32 tin, mark; +u32 tin, mark, handle;bool wash;u8 dscp;
@@ -1689,6 +1689,8 @@ static struct cake_tin_data *cake_select_tin(struct Qdisc *sch,*/ mark = (skb->mark & q->fwmark_mask) >> q->fwmark_shft; wash = !!(q->rate_flags &CAKE_FLAG_WASH ); + handle = q->is_shared ?TC_H_MAJ (sch->parent) : sch->handle; +if (wash) dscp =cake_handle_diffserv (skb, wash);
@@ -1698,7 +1700,7 @@ static struct cake_tin_data *cake_select_tin(struct Qdisc *sch,else if (mark && mark <= qd->tin_cnt) tin = qd->tin_order[mark -1 ]; -else if (TC_H_MAJ (skb->priority) == sch->handle && +else if (TC_H_MAJ (skb->priority) == handle &&TC_H_MIN (skb->priority) >0 &&TC_H_MIN (skb->priority) <= qd->tin_cnt) tin = qd->tin_order[TC_H_MIN (skb->priority) -1 ];
---
base-commit: e203d8a4751d48aa00eda31e3b320ba8e0d47dbf
change-id: 20261119-cake_mq_fix_incorrect_tin_override-dd85e1815baa
Quoted 28 lines · Jonas Köppeler
CAKE allows overriding the tin selection through
skb->priority: if the major number ofskb->prioritymatches the qdisc handle, the minor number selects the tin. Withcake_mq, the per-queue CAKE instances are created throughqdisc_create_dflt()and never get a handle assigned, sosch->handleis 0 for all of them.For forwarded IPv4 traffic,
ip_forward()setsskb->priorityfrom the TOS byte viart_tos2priority()when net.ipv4.ip_forward_update_priority is enabled, which is the default.rt_tos2priority()returns 0, 2, 4 or 6, all with a major number of 0, which matches the handle of thecake_mqchildren. The minor number is then taken as a tin override and the DSCP mapping is skipped.With diffserv4 and diffserv8 this puts packets into the wrong tins. For example, AF13 (TOS byte
0x38) under diffserv4:
ip_forward():skb->priority = ip_tos2prio[(0x38 & 0x1E) >> 1] = ip_tos2prio[12] = TC_PRIO_INTERACTIVE_BULK = 4 cake_select_tin(): TC_H_MAJ(4) == 0 == sch->handle tin = bulk_order[4 - 1] = 3 -> Voicewhereas the DSCP table gives diffserv4[0x38 >> 2] = diffserv4[14] = 0, i.e. Best Effort. Likewise, AF21, AF31 and AF41 are demoted from Video to Best Effort. diffserv3 happens to be unaffected, because the only reachable override (priority 2) agrees with its DSCP table.
Quoted 5 lines
Fix this by matching
skb->priorityagainst the major number of the parentcake_mqqdisc when the instance is part ofcake_mq.Fixes ebc65a873eff ("net/sched: sch_cake: Add cake_mq qdisc for using cake on mq devices")Signed-off-by Jonas Köppeler <[email protected]>
Paolo Abeni
maintainerQuoted 30 lines · Toke Høiland-Jørgensen
Quoted 28 lines · Jonas Köppeler
CAKE allows overriding the tin selection through
skb->priority: if the major number ofskb->prioritymatches the qdisc handle, the minor number selects the tin. Withcake_mq, the per-queue CAKE instances are created throughqdisc_create_dflt()and never get a handle assigned, sosch->handleis 0 for all of them.For forwarded IPv4 traffic,
ip_forward()setsskb->priorityfrom the TOS byte viart_tos2priority()when net.ipv4.ip_forward_update_priority is enabled, which is the default.rt_tos2priority()returns 0, 2, 4 or 6, all with a major number of 0, which matches the handle of thecake_mqchildren. The minor number is then taken as a tin override and the DSCP mapping is skipped.With diffserv4 and diffserv8 this puts packets into the wrong tins. For example, AF13 (TOS byte
0x38) under diffserv4:ip_forward(): skb->priority = ip_tos2prio[(0x38 & 0x1E) >> 1] = ip_tos2prio[12] = TC_PRIO_INTERACTIVE_BULK = 4 cake_select_tin(): TC_H_MAJ(4) == 0 == sch->handle tin = bulk_order[4 - 1] = 3 -> Voicewhereas the DSCP table gives diffserv4[0x38 >> 2] = diffserv4[14] = 0, i.e. Best Effort. Likewise, AF21, AF31 and AF41 are demoted from Video to Best Effort. diffserv3 happens to be unaffected, because the only reachable override (priority 2) agrees with its DSCP table.
Quoted 7 lines
Quoted 5 lines
Fix this by matching
skb->priorityagainst the major number of the parentcake_mqqdisc when the instance is part ofcake_mq.Fixes ebc65a873eff ("net/sched: sch_cake: Add cake_mq qdisc for using cake on mq devices")Signed-off-by Jonas Köppeler <[email protected]>
FYI, since this was broken since the beginning and does not look ultra-critical, I'm moving the patch to net-next.
/P
Quoted 34 lines · Paolo Abeni
Quoted 33 lines · Toke Høiland-Jørgensen
Quoted 31 lines · Jonas Köppeler
CAKE allows overriding the tin selection through
skb->priority: if the major number ofskb->prioritymatches the qdisc handle, the minor number selects the tin. Withcake_mq, the per-queue CAKE instances are created throughqdisc_create_dflt()and never get a handle assigned, sosch->handleis 0 for all of them.For forwarded IPv4 traffic,
ip_forward()setsskb->priorityfrom the TOS byte viart_tos2priority()when net.ipv4.ip_forward_update_priority is enabled, which is the default.rt_tos2priority()returns 0, 2, 4 or 6, all with a major number of 0, which matches the handle of thecake_mqchildren. The minor number is then taken as a tin override and the DSCP mapping is skipped.With diffserv4 and diffserv8 this puts packets into the wrong tins. For example, AF13 (TOS byte
0x38) under diffserv4:ip_forward(): skb->priority = ip_tos2prio[(0x38 & 0x1E) >> 1] = ip_tos2prio[12] = TC_PRIO_INTERACTIVE_BULK = 4 cake_select_tin(): TC_H_MAJ(4) == 0 == sch->handle tin = bulk_order[4 - 1] = 3 -> Voicewhereas the DSCP table gives diffserv4[0x38 >> 2] = diffserv4[14] = 0, i.e. Best Effort. Likewise, AF21, AF31 and AF41 are demoted from Video to Best Effort. diffserv3 happens to be unaffected, because the only reachable override (priority 2) agrees with its DSCP table.
Fix this by matching
skb->priorityagainst the major number of the parentcake_mqqdisc when the instance is part ofcake_mq.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Fixes ebc65a873eff ("net/sched: sch_cake: Add cake_mq qdisc for using cake on mq devices")Signed-off-by Jonas Köppeler <[email protected]>FYI, since this was broken since the beginning and does not look ultra-critical, I'm moving the patch to net-next.
Fine with me :)
-Toke
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 6 lines · On Thu, 19 Nov 2026 10:43:57 +0100 you wrote:
CAKE allows overriding the tin selection through
skb->priority: if the major number ofskb->prioritymatches the qdisc handle, the minor number selects the tin. Withcake_mq, the per-queue CAKE instances are created throughqdisc_create_dflt()and never get a handle assigned, sosch->handleis 0 for all of them.
Quoted 8 lines
For forwarded IPv4 traffic,
ip_forward()setsskb->priorityfrom the TOS byte viart_tos2priority()when net.ipv4.ip_forward_update_priority is enabled, which is the default.rt_tos2priority()returns 0, 2, 4 or 6, all with a major number of 0, which matches the handle of thecake_mqchildren. The minor number is then taken as a tin override and the DSCP mapping is skipped.[...]
Here is the summary with links:
- [net] net/sched: sch_cake: fix unintended tin override with cake_mq
https://git.kernel.org/netdev/net-next/c/7b75467462af
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html