net/sched: etf: propagate dequeue drops to parents
Subsystems (4)
PATCH 1/1 net/sched: etf: propagate dequeue drops to parents
From: Riley Kitchen <[email protected]>
etf_dequeue_timesortedlist() drops expired packets via timesortedlist_drop(), but that path only decrements ETF's own qlen and backlog. It never calls qdisc_tree_reduce_backlog(), so a classful parent keeps accounting packets that no longer exist.
With ETF installed below QFQ, this leaves QFQ with a nonzero qlen after its last active aggregate has drained. qfq_dequeue() then skips its empty-queue early return, qfq_choose_next_agg() returns NULL, and qfq_peek_skb() dereferences the NULL aggregate, panicking the kernel. An unprivileged (uid 1000) process can trigger this deterministically after creating user and network namespaces; no race and no modified kernel are required.
Count the packets and bytes dropped in timesortedlist_drop() and call qdisc_tree_reduce_backlog() once the local queue state is consistent, so classful ancestors see the removal.
The issue was found and the fix developed with AI assistance. A standalone C reproducer, run as uid 1000 with no kernel changes, panicked v7.3 and mainline d135ab453a74 under KASAN; with this fix the reproducer exits cleanly and parent and child backlogs both reach zero. The reproducer is available privately on request.
--- net/sched/sch_etf.c | 4 ++++ 1 file changed, 4 insertions(+)
net/sched/sch_etf.c +4 -0
@@ -201,6 +201,7 @@ static int etf_enqueue_timesortedlist(struct sk_buff *nskb, struct Qdisc *sch,static void timesortedlist_drop (struct Qdisc *sch,struct sk_buff *skb,ktime_t now) { +unsigned int dropped_pkts =0 , dropped_bytes =0 ;struct etf_sched_data *q =qdisc_priv (sch);struct sk_buff *to_free =NULL ;struct sk_buff *tmp =NULL ;
@@ -220,6 +221,8 @@ static void timesortedlist_drop(struct Qdisc *sch, struct sk_buff *skb,report_sock_error (skb,ECANCELED ,SO_EE_CODE_TXTIME_MISSED ); + dropped_pkts++; + dropped_bytes +=qdisc_pkt_len (skb);qdisc_qstats_backlog_dec (sch, skb);qdisc_drop (skb, sch, &to_free);qdisc_qstats_overlimit (sch);
@@ -227,6 +230,7 @@ static void timesortedlist_drop(struct Qdisc *sch, struct sk_buff *skb, }kfree_skb_list (to_free); +qdisc_tree_reduce_backlog (sch, dropped_pkts, dropped_bytes); }static void timesortedlist_remove (struct Qdisc *sch,struct sk_buff *skb)
Signature · 1 line
2.43.0
Quoted 25 lines
From: Riley Kitchen <[email protected]>
etf_dequeue_timesortedlist()drops expired packets viatimesortedlist_drop(), but that path only decrements ETF's own qlen and backlog. It never callsqdisc_tree_reduce_backlog(), so a classful parent keeps accounting packets that no longer exist.With ETF installed below QFQ, this leaves QFQ with a nonzero qlen after its last active aggregate has drained.
qfq_dequeue()then skips its empty-queue early return,qfq_choose_next_agg()returns NULL, andqfq_peek_skb()dereferences the NULL aggregate, panicking the kernel. An unprivileged (uid 1000) process can trigger this deterministically after creating user and network namespaces; no race and no modified kernel are required.Count the packets and bytes dropped in
timesortedlist_drop()and callqdisc_tree_reduce_backlog()once the local queue state is consistent, so classful ancestors see the removal.The issue was found and the fix developed with AI assistance. A standalone C reproducer, run as uid 1000 with no kernel changes, panicked v7.3 and mainline
d135ab453a74under KASAN; with this fix the reproducer exits cleanly and parent and child backlogs both reach zero. The reproducer is available privately on request.
Quoted 4 lines
Fixes 25db26a91364 ("net/sched: Introduce the ETF Qdisc")Signed-off-by Riley Kitchen <[email protected]>---
It seems that ETF under QFQ won't work well, as ETF can drop packets and is not work conserving. But the patch looks good:
Cheers,
Signature · 1 line
Vinicius
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 1 · High: 1 · Medium: 1 (1) · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Critical] This patch adds a call to qdisc_tree_reduce_backlog() inside ETF's ->dequeue().
- [High] net/sched: etf: timesortedlist_drop() corrupts parent qfq_dequeue() state
- [Medium] The fix does not reach taprio, which is the usual parent for software-mode ETF, so taprio keeps counting packets that no longer…
Pre-existing issues:
- [Medium] When QFQ sits between ETF and another classful qdisc (DRR, ETS or HFSC above QFQ), the grandparent is never told that QFQ became…
--
net/sched: etf: propagate dequeue drops to parents
This patch makes timesortedlist_drop() count the expired packets and bytes it drops on ETF's dequeue path. It then calls qdisc_tree_reduce_backlog() so that classful parents update their qlen and backlog. The goal is to fix a NULL dereference in qfq_peek_skb() when ETF sits below QFQ.
Quoted 4 lines
net/sched/sch_etf.c +0
-0
[ ... ]
net/sched/sch_etf.c static void timesortedlist_drop(struct Qdisc *sch, struct sk_buff *skb, · line 234
Quoted 6 lines
net/sched/sch_etf.c +1
-0@@ -227,6 +230,7 @@ static void timesortedlist_drop(struct Qdisc *sch, struct sk_buff *skb, }kfree_skb_list (to_free); +qdisc_tree_reduce_backlog (sch, dropped_pkts, dropped_bytes); }
[Severity: High]
Does this fully close the qfq_peek_skb() NULL dereference, or does it only move it to other QFQ topologies? The new call runs from inside the parent's dequeue. qfq_dequeue() in net/sched/sch_qfq.c does not expect its own qlen and aggregate state to change underneath it.
The first problem is that qfq_dequeue() lowers its qlen around the child dequeue:
qdisc_qlen_dec(sch);
skb = agg_dequeue(in_serv_agg, cl, len);
if (!skb) {
qdisc_qlen_inc(sch);
return NULL;
}Take Root_QFQ -> Child_QFQ -> ETF. ETF holds one expired packet and one packet whose txtime is in the future, so both QFQ instances have qlen == 2. Root_QFQ peeks Child_QFQ through qdisc_peek_dequeued(), which runs qfq_dequeue() on Child_QFQ. etf_peek_timesortedlist() returns the expired head without looking at its txtime, so Child_QFQ sees len > 0 and continues:
qfq_dequeue(Root_QFQ)
qfq_peek_skb()
qdisc_peek_dequeued(Child_QFQ)
qfq_dequeue(Child_QFQ) /* Child qlen 2 -> 1 */
agg_dequeue()
etf_dequeue_timesortedlist()
timesortedlist_drop()
qdisc_tree_reduce_backlog()
/* Child qlen 1 -> 0 */
qfq_qlen_notify() /* deactivates Child's class */
/* Root qlen 2 -> 1 */
qdisc_qlen_inc() /* Child qlen 0 -> 1 */Child_QFQ still holds the future packet. However, notify was computed from its temporarily lowered qlen, so Root_QFQ deactivated the class anyway, and qfq_deactivate_agg() set q->in_serv_agg to NULL. Root_QFQ is left with qlen == 1 and no active aggregate.
Back in Root_QFQ's qfq_dequeue(), len is 0 and the active list of the local in_serv_agg is empty. The "sch->q.qlen == 0" early return is skipped, qfq_choose_next_agg() returns NULL, and qfq_peek_skb() dereferences it. That is the panic the commit message describes, one level further up.
The reverse happens when the drops empty Child_QFQ. Its qlen wraps to 0xFFFFFFFF during the walk, so notify is false at the next level and the ancestor keeps an empty class active.
The second problem is the local in_serv_agg in qfq_dequeue(). Take an intermediate qdisc that uses qdisc_peek_dequeued(), for example QFQ -> TBF -> ETF. There the drop happens during QFQ's own qfq_peek_skb() instead of inside agg_dequeue().
Suppose that drop drains TBF and the in-service aggregate agg1. qfq_qlen_notify() then reaches qfq_deactivate_agg(), which already moves q->in_serv_agg to the next aggregate, agg2, through qfq_choose_next_agg(). qfq_dequeue() still has agg1 in its local variable. It sees len == 0, an empty active list and a nonzero qlen, so it calls qfq_choose_next_agg() a second time. agg2 has already been removed from the schedule. Without a third aggregate this call returns NULL, and the next qfq_peek_skb() dereferences it.
The same unprivileged user can build both topologies in its own namespaces, just like QFQ -> ETF. Should qfq_dequeue() be changed to cope with drops reported from inside a child's dequeue or peek? For example, it could lower qlen only after agg_dequeue() succeeds and reload q->in_serv_agg after qfq_peek_skb(). Or should ETF report these drops in a way that does not re-enter the parent while the parent is in the middle of its own dequeue?
[Severity: Critical]
This call now runs from inside ETF's ->dequeue(). If the drops leave ETF empty, the parent's qlen_notify runs while the parent is still inside its own dequeue. Can this make htb_dequeue_tree() in net/sched/sch_htb.c loop forever?
Take two HTB leaf classes, A and B, in the same row (level 0, same prio, HTB_CAN_SEND). Each has an ETF child. All of A's packets have expired (delta=0 guarantees this). B holds one packet with a txtime far in the future. hprio->ptr points at A.
htb_dequeue_tree() picks start once:
start = cl = htb_lookup_leaf(hprio, prio);
A's qlen is nonzero, so the "fix start if we just deleted it" branch is skipped. HTB then calls A's dequeue:
htb_dequeue_tree()
etf_dequeue_timesortedlist()
timesortedlist_drop()
qdisc_tree_reduce_backlog() /* ETF qlen is 0, notify = true */
htb_qlen_notify()
htb_deactivate()
htb_deactivate_prios()
htb_remove_class_from_row() /* A is erased from the row */
ETF returns NULL. HTB advances ptr, and htb_lookup_leaf() returns B. B's ETF also returns NULL because its packet is not yet eligible. ptr then reaches NULL, and htb_lookup_leaf() goes back to the leftmost class, which is B again.
A is no longer in the row, so this condition never becomes false:
} while (cl != start);
The loop holds the root qdisc lock with BH disabled. It only ends when B's head packet becomes eligible, and is_packet_valid() puts no upper limit on txtime.
Before this patch, A stayed in the row during the walk. The loop went A -> B -> A == start and exited.
The commit message says an unprivileged user can put ETF under a classful parent inside its own namespaces. Doesn't that make this HTB lockup reachable in the same way as the QFQ NULL dereference being fixed?
In principle, other children that notify from dequeue (the codel family) can hit the same HTB pattern. Codel rarely empties its queue through drops, though, while ETF does so every time under these conditions.
[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch. Does the walk still miss the grandparent when QFQ is the intermediate qdisc, for example DRR -> QFQ -> ETF?
qfq_dequeue() temporarily lowers its own qlen around the child dequeue:
qdisc_qlen_dec(sch);
skb = agg_dequeue(in_serv_agg, cl, len);
if (!skb) {
qdisc_qlen_inc(sch);
return NULL;
}Suppose ETF's expired packets are all of QFQ's backlog (QFQ qlen == n). qdisc_tree_reduce_backlog() then notifies QFQ correctly and sets QFQ's qlen to (n - 1) - n = 0xFFFFFFFF. On the next hop it computes:
notify = !sch->q.qlen;
which is false. The grandparent's qlen and backlog are reduced, but it gets no qlen_notify. After qfq_dequeue() puts QFQ's qlen back to 0, the grandparent still has the QFQ class on its active list.
drr_dequeue() peeks the first active class and qfq_dequeue() returns NULL, so the code takes the goto out path:
skb = cl->qdisc->ops->peek(cl->qdisc);
if (skb == NULL) {
qdisc_warn_nonwc(__func__, cl->qdisc);
goto out;
}The other DRR classes with queued packets then starve until new traffic reaches the QFQ class. ETS non-strict bands and HFSC appear to stall on the stale class in the same way.
ETF did not notify the grandparent before this patch either, so the behaviour is no worse. Does the statement "so classful ancestors see the removal" still hold when QFQ is in the middle?
[Severity: Medium]
Does this new call reach taprio, which is the usual parent for software-mode ETF?
taprio_graft() always sets TCQ_F_NOPARENT on the child, including in software and txtime-assist mode:
new->flags |= TCQ_F_ONETXQUEUE | TCQ_F_NOPARENT;
In those modes, taprio_enqueue_one() increments taprio's own qlen and backlog. taprio_dequeue_from_txq() decrements them only when the child returns an skb:
skb = qdisc_dequeue_peeked(child); if (unlikely(!skb)) return NULL; qdisc_bstats_update(sch, skb); qdisc_qstats_backlog_dec(sch, skb); qdisc_qlen_dec(sch);
When timesortedlist_drop() runs under taprio, the new walk stops at once in qdisc_tree_reduce_backlog():
if (sch->flags & TCQ_F_NOPARENT) break;
ETF then returns NULL, so taprio's sch->q.qlen and qstats.backlog grow with every expired packet. The visible result is wrong tc statistics, not a crash, because taprio does not use its qlen for scheduling.
The commit message says a parent will no longer "keep accounting packets that no longer exist". Would taprio need a change too, such as not setting TCQ_F_NOPARENT in software mode, or computing taprio's qlen from its children instead of keeping a separate count?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261104135707.725-1-me%40riley.kitchen
Thanks for the review. I checked all four points against net (d8a4f4c59da5) and they hold up; I'll respin.
- [Critical, HTB loop] Confirmed. Two sibling ETF leaves under HTB in the same row, one with only expired packets and one holding a single future-txtime packet: ETF's drop calls qdisc_tree_reduce_backlog() -> htb_qlen_notify() -> htb_deactivate(), which removes the class from the row while htb_dequeue_tree() is walking it. The class is dequeued via the skb == NULL path, not the top "qlen == 0" branch, so the
"if (cl == start) start = next" fixup never runs; 'start' is left pointing at the removed class and "while (cl != start)" never terminates. The sibling never empties (its packet is not yet eligible) and never yields a packet, so the loop spins holding the root qdisc lock with BH disabled. That is worse than the NULL deref this patch is trying to fix.
- [High, QFQ] Confirmed. In Root_QFQ -> Child_QFQ -> ETF, the notify fired from inside the child dequeue drives Child_QFQ's qlen to 0 (qfq_dequeue() has already done qdisc_qlen_dec() around the child dequeue) and deactivates its class in Root_QFQ, so qfq_deactivate_agg() nulls q->in_serv_agg while Root_QFQ's qfq_dequeue() still holds the old in_serv_agg in a local. Root is left with qlen == 1 and no in-service aggregate, skips the "qlen == 0" early return, and qfq_choose_next_agg() -> NULL -> qfq_peek_skb(NULL). The patch moves the exact panic it fixes up one level rather than removing the class.
- [Medium, DRR/ETS/HFSC over QFQ] Confirmed. qfq_dequeue() lowers its own qlen around the child dequeue, so reducing it by the full drop count underflows to ~0U transiently; notify at the grandparent hop is then false and the stale QFQ class is left on the grandparent's active list. The commit message's "classful ancestors see the removal" does not hold with QFQ in the middle.
- [Medium, taprio] Confirmed. taprio_graft() sets TCQ_F_NOPARENT on the child in software and txtime-assist mode, so qdisc_tree_reduce_backlog() breaks on the first hop and never reaches taprio. For the usual software-ETF parent the patch is a no-op, and taprio's qlen/backlog still grow with every expired packet.
More broadly this is the same hazard that 52f1da34c9f4, 097f6fc7b1 and 15cd0c93bf ("net/sched: {codel,fq_codel,dualpi2}: Do not call qdisc_tree_reduce_backlog during peek before restoring qlen", Jun 2026)
addressed: calling qdisc_tree_reduce_backlog() from a child's dequeue/peek can deactivate the parent's class underneath the parent's own dequeue. ETF hits it deterministically because it empties via drops and returns NULL. A codel-style "defer until the qlen is restored" is not enough here, since ETF returns NULL after dropping and the class is still deactivated mid-walk.
So I don't think ETF can safely propagate these drops inline. The original qfq_peek_skb() NULL deref looks like it wants a parent-side fix - qfq_dequeue() / qfq_peek_skb() tolerating in_serv_agg becoming NULL during a child dequeue - and htb_dequeue_tree() has the same latent exposure to a class self-deactivating mid-walk (the codel family can hit it too, just rarely). I'll rework in that direction. If you'd prefer the fix live in the parents (qfq/htb) or be handled a different way in etf, I'm happy to follow your steer.
pw-bot: cr
Quoted 254 lines · On Sun, Nov 8, 2026 at 6:57 AM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 1 · High: 1 · Medium: 1 (1) · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Critical] This patch adds a call to
qdisc_tree_reduce_backlog()inside ETF's ->dequeue().
- [High] net/sched: etf:timesortedlist_drop()corrupts parentqfq_dequeue()state
- [Medium] The fix does not reach taprio, which is the usual parent for software-mode ETF, so taprio keeps counting packets that no longer…Pre-existing issues:
- [Medium] When QFQ sits between ETF and another classful qdisc (DRR, ETS or HFSC above QFQ), the grandparent is never told that QFQ became…--
net/sched: etf: propagate dequeue drops to parents
This patch makes
timesortedlist_drop()count the expired packets and bytes it drops on ETF's dequeue path. It then callsqdisc_tree_reduce_backlog()so that classful parents update their qlen and backlog. The goal is to fix a NULL dereference inqfq_peek_skb()when ETF sits below QFQ.Quoted 4 lines
net/sched/sch_etf.c +0
-0[ ... ]
net/sched/sch_etf.c static void timesortedlist_drop(struct Qdisc *sch, struct sk_buff *skb, · line 234
Quoted 6 lines
net/sched/sch_etf.c +1
-0@@ -227,6 +230,7 @@ static void timesortedlist_drop(struct Qdisc *sch, struct sk_buff *skb, }kfree_skb_list (to_free); +qdisc_tree_reduce_backlog (sch, dropped_pkts, dropped_bytes); }[Severity: High]
Does this fully close theqfq_peek_skb()NULL dereference, or does it only move it to other QFQ topologies? The new call runs from inside the parent's dequeue.qfq_dequeue()innet/sched/sch_qfq.cdoes not expect its own qlen and aggregate state to change underneath it.The first problem is that
qfq_dequeue()lowers its qlen around the child dequeue:qdisc_qlen_dec(sch); skb = agg_dequeue(in_serv_agg, cl, len); if (!skb) { qdisc_qlen_inc(sch); return NULL; }Take
Root_QFQ->Child_QFQ-> ETF. ETF holds one expired packet and one packet whose txtime is in the future, so both QFQ instances have qlen == 2.Root_QFQpeeksChild_QFQthroughqdisc_peek_dequeued(), which runsqfq_dequeue()onChild_QFQ.etf_peek_timesortedlist()returns the expired head without looking at its txtime, soChild_QFQsees len > 0 and continues:
qfq_dequeue(Root_QFQ)
qfq_peek_skb()qdisc_peek_dequeued(Child_QFQ) qfq_dequeue(Child_QFQ) /* Child qlen 2 -> 1 */ agg_dequeue() etf_dequeue_timesortedlist() timesortedlist_drop() qdisc_tree_reduce_backlog() /* Child qlen 1 -> 0 */ qfq_qlen_notify() /* deactivates Child's class */ /* Root qlen 2 -> 1 */ qdisc_qlen_inc() /* Child qlen 0 -> 1 */
Child_QFQstill holds the future packet. However, notify was computed from its temporarily lowered qlen, soRoot_QFQdeactivated the class anyway, andqfq_deactivate_agg()setq->in_serv_aggto NULL.Root_QFQis left with qlen == 1 and no active aggregate.Back in Root_QFQ's
qfq_dequeue(), len is 0 and the active list of the localin_serv_aggis empty. The "sch->q.qlen== 0" early return is skipped,qfq_choose_next_agg()returns NULL, andqfq_peek_skb()dereferences it. That is the panic the commit message describes, one level further up.The reverse happens when the drops empty
Child_QFQ. Its qlen wraps to0xFFFFFFFFduring the walk, so notify is false at the next level and the ancestor keeps an empty class active.The second problem is the local
in_serv_agginqfq_dequeue(). Take an intermediate qdisc that usesqdisc_peek_dequeued(), for example QFQ -> TBF -> ETF. There the drop happens during QFQ's ownqfq_peek_skb()instead of insideagg_dequeue().Suppose that drop drains TBF and the in-service aggregate agg1.
qfq_qlen_notify()then reachesqfq_deactivate_agg(), which already movesq->in_serv_aggto the next aggregate, agg2, throughqfq_choose_next_agg().qfq_dequeue()still has agg1 in its local variable. It sees len == 0, an empty active list and a nonzero qlen, so it callsqfq_choose_next_agg()a second time. agg2 has already been removed from the schedule. Without a third aggregate this call returns NULL, and the nextqfq_peek_skb()dereferences it.The same unprivileged user can build both topologies in its own namespaces, just like QFQ -> ETF. Should
qfq_dequeue()be changed to cope with drops reported from inside a child's dequeue or peek? For example, it could lower qlen only afteragg_dequeue()succeeds and reloadq->in_serv_aggafterqfq_peek_skb(). Or should ETF report these drops in a way that does not re-enter the parent while the parent is in the middle of its own dequeue?[Severity: Critical]
This call now runs from inside ETF's ->dequeue(). If the drops leave ETF empty, the parent'sqlen_notifyruns while the parent is still inside its own dequeue. Can this makehtb_dequeue_tree()innet/sched/sch_htb.cloop forever?Take two HTB leaf classes, A and B, in the same row (level 0, same prio,
HTB_CAN_SEND). Each has an ETF child. All of A's packets have expired (delta=0 guarantees this). B holds one packet with a txtime far in the future.hprio->ptrpoints at A.
htb_dequeue_tree()picks start once:start = cl = htb_lookup_leaf(hprio, prio);A's qlen is nonzero, so the "fix start if we just deleted it" branch is skipped. HTB then calls A's dequeue:
htb_dequeue_tree()
etf_dequeue_timesortedlist()
timesortedlist_drop()
qdisc_tree_reduce_backlog()/* ETF qlen is 0, notify = true */
htb_qlen_notify()
htb_deactivate()
htb_deactivate_prios()
htb_remove_class_from_row()/* A is erased from the row */ETF returns NULL. HTB advances ptr, and
htb_lookup_leaf()returns B. B's ETF also returns NULL because its packet is not yet eligible. ptr then reaches NULL, andhtb_lookup_leaf()goes back to the leftmost class, which is B again.A is no longer in the row, so this condition never becomes false:
} while (cl != start);The loop holds the root qdisc lock with BH disabled. It only ends when B's head packet becomes eligible, and
is_packet_valid()puts no upper limit on txtime.Before this patch, A stayed in the row during the walk. The loop went A -> B -> A == start and exited.
The commit message says an unprivileged user can put ETF under a classful parent inside its own namespaces. Doesn't that make this HTB lockup reachable in the same way as the QFQ NULL dereference being fixed?
In principle, other children that notify from dequeue (the codel family) can hit the same HTB pattern. Codel rarely empties its queue through drops, though, while ETF does so every time under these conditions.
[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch. Does the walk still miss the grandparent when QFQ is the intermediate qdisc, for example DRR -> QFQ -> ETF?
qfq_dequeue()temporarily lowers its own qlen around the child dequeue:qdisc_qlen_dec(sch); skb = agg_dequeue(in_serv_agg, cl, len); if (!skb) { qdisc_qlen_inc(sch); return NULL; }Suppose ETF's expired packets are all of QFQ's backlog (QFQ qlen == n).
qdisc_tree_reduce_backlog()then notifies QFQ correctly and sets QFQ's qlen to (n - 1) - n =0xFFFFFFFF. On the next hop it computes:notify = !sch->q.qlen;which is false. The grandparent's qlen and backlog are reduced, but it gets no
qlen_notify. Afterqfq_dequeue()puts QFQ's qlen back to 0, the grandparent still has the QFQ class on its active list.
drr_dequeue()peeks the first active class andqfq_dequeue()returns NULL, so the code takes the goto out path:skb = cl->qdisc->ops->peek(cl->qdisc); if (skb == NULL) { qdisc_warn_nonwc(__func__, cl->qdisc); goto out; }The other DRR classes with queued packets then starve until new traffic reaches the QFQ class. ETS non-strict bands and HFSC appear to stall on the stale class in the same way.
ETF did not notify the grandparent before this patch either, so the behaviour is no worse. Does the statement "so classful ancestors see the removal" still hold when QFQ is in the middle?
[Severity: Medium]
Does this new call reach taprio, which is the usual parent for software-mode ETF?
taprio_graft()always setsTCQ_F_NOPARENTon the child, including in software and txtime-assist mode:new->flags |= TCQ_F_ONETXQUEUE | TCQ_F_NOPARENT;In those modes,
taprio_enqueue_one()increments taprio's own qlen and backlog.taprio_dequeue_from_txq()decrements them only when the child returns an skb:skb = qdisc_dequeue_peeked(child); if (unlikely(!skb)) return NULL; qdisc_bstats_update(sch, skb); qdisc_qstats_backlog_dec(sch, skb); qdisc_qlen_dec(sch);When
timesortedlist_drop()runs under taprio, the new walk stops at once inqdisc_tree_reduce_backlog():if (sch->flags & TCQ_F_NOPARENT) break;ETF then returns NULL, so taprio's
sch->q.qlenand qstats.backlog grow with every expired packet. The visible result is wrong tc statistics, not a crash, because taprio does not use its qlen for scheduling.The commit message says a parent will no longer "keep accounting packets that no longer exist". Would taprio need a change too, such as not setting
TCQ_F_NOPARENTin software mode, or computing taprio's qlen from its children instead of keeping a separate count?--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261104135707.725-1-me%40riley.kitchen
Following up on my last mail: after working through the parent-side fix, the right change turns out to be in qfq_dequeue() itself - guarding the case where qfq_choose_next_agg() returns NULL before qfq_peek_skb() - not anything in ETF. Cong Wang has already posted exactly that patch ("net_sched: Check the return value of qfq_choose_next_agg()", Fixes: 462dbc9101ac, part of his netem duplicate series), so the crash I was addressing from the ETF side is already being handled in qfq where it belongs.
So please drop this ETF patch - I won't be resending it. The non-work-conserving behaviour the review noted is real, but ETF shouldn't paper over it by notifying parents from inside its dequeue; the qfq-side NULL check is the correct fix.
Thanks for the review.
pw-bot: reject
Quoted 311 lines · Copperfault Security
Thanks for the review. I checked all four points against net (
d8a4f4c59da5) and they hold up; I'll respin.- [Critical, HTB loop] Confirmed. Two sibling ETF leaves under HTB in the same row, one with only expired packets and one holding a single future-txtime packet: ETF's drop calls
qdisc_tree_reduce_backlog()->htb_qlen_notify()->htb_deactivate(), which removes the class from the row whilehtb_dequeue_tree()is walking it. The class is dequeued via the skb == NULL path, not the top "qlen == 0" branch, so the
"if (cl == start) start = next" fixup never runs; 'start' is left pointing at the removed class and "while (cl != start)" never terminates. The sibling never empties (its packet is not yet eligible) and never yields a packet, so the loop spins holding the root qdisc lock with BH disabled. That is worse than the NULL deref this patch is trying to fix.- [High, QFQ] Confirmed. In
Root_QFQ->Child_QFQ-> ETF, the notify fired from inside the child dequeue drives Child_QFQ's qlen to 0 (qfq_dequeue()has already doneqdisc_qlen_dec()around the child dequeue) and deactivates its class inRoot_QFQ, soqfq_deactivate_agg()nullsq->in_serv_aggwhile Root_QFQ'sqfq_dequeue()still holds the oldin_serv_aggin a local. Root is left with qlen == 1 and no in-service aggregate, skips the "qlen == 0" early return, andqfq_choose_next_agg()-> NULL ->qfq_peek_skb(NULL). The patch moves the exact panic it fixes up one level rather than removing the class.- [Medium, DRR/ETS/HFSC over QFQ] Confirmed.
qfq_dequeue()lowers its own qlen around the child dequeue, so reducing it by the full drop count underflows to ~0U transiently; notify at the grandparent hop is then false and the stale QFQ class is left on the grandparent's active list. The commit message's "classful ancestors see the removal" does not hold with QFQ in the middle.- [Medium, taprio] Confirmed.
taprio_graft()setsTCQ_F_NOPARENTon the child in software and txtime-assist mode, soqdisc_tree_reduce_backlog()breaks on the first hop and never reaches taprio. For the usual software-ETF parent the patch is a no-op, and taprio's qlen/backlog still grow with every expired packet.More broadly this is the same hazard that
52f1da34c9f4,097f6fc7b1and15cd0c93bf("net/sched: {codel,fq_codel,dualpi2}: Do not callqdisc_tree_reduce_backlogduring peek before restoring qlen", Jun 2026)
addressed: callingqdisc_tree_reduce_backlog()from a child's dequeue/peek can deactivate the parent's class underneath the parent's own dequeue. ETF hits it deterministically because it empties via drops and returns NULL. A codel-style "defer until the qlen is restored" is not enough here, since ETF returns NULL after dropping and the class is still deactivated mid-walk.So I don't think ETF can safely propagate these drops inline. The original
qfq_peek_skb()NULL deref looks like it wants a parent-side fix -qfq_dequeue()/qfq_peek_skb()toleratingin_serv_aggbecoming NULL during a child dequeue - andhtb_dequeue_tree()has the same latent exposure to a class self-deactivating mid-walk (the codel family can hit it too, just rarely). I'll rework in that direction. If you'd prefer the fix live in the parents (qfq/htb) or be handled a different way in etf, I'm happy to follow your steer.pw-bot: cr
Quoted 254 lines · On Sun, Nov 8, 2026 at 6:57 AM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 1 · High: 1 · Medium: 1 (1) · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Critical] This patch adds a call to
qdisc_tree_reduce_backlog()inside ETF's ->dequeue().
- [High] net/sched: etf:timesortedlist_drop()corrupts parentqfq_dequeue()state
- [Medium] The fix does not reach taprio, which is the usual parent for software-mode ETF, so taprio keeps counting packets that no longer…Pre-existing issues:
- [Medium] When QFQ sits between ETF and another classful qdisc (DRR, ETS or HFSC above QFQ), the grandparent is never told that QFQ became…--
net/sched: etf: propagate dequeue drops to parents
This patch makes
timesortedlist_drop()count the expired packets and bytes it drops on ETF's dequeue path. It then callsqdisc_tree_reduce_backlog()so that classful parents update their qlen and backlog. The goal is to fix a NULL dereference inqfq_peek_skb()when ETF sits below QFQ.Quoted 4 lines
net/sched/sch_etf.c +0
-0[ ... ]
net/sched/sch_etf.c static void timesortedlist_drop(struct Qdisc *sch, struct sk_buff *skb, · line 234
Quoted 6 lines
net/sched/sch_etf.c +1
-0@@ -227,6 +230,7 @@ static void timesortedlist_drop(struct Qdisc *sch, struct sk_buff *skb, }kfree_skb_list (to_free); +qdisc_tree_reduce_backlog (sch, dropped_pkts, dropped_bytes); }[Severity: High]
Does this fully close theqfq_peek_skb()NULL dereference, or does it only move it to other QFQ topologies? The new call runs from inside the parent's dequeue.qfq_dequeue()innet/sched/sch_qfq.cdoes not expect its own qlen and aggregate state to change underneath it.The first problem is that
qfq_dequeue()lowers its qlen around the child dequeue:qdisc_qlen_dec(sch); skb = agg_dequeue(in_serv_agg, cl, len); if (!skb) { qdisc_qlen_inc(sch); return NULL; }Take
Root_QFQ->Child_QFQ-> ETF. ETF holds one expired packet and one packet whose txtime is in the future, so both QFQ instances have qlen == 2.Root_QFQpeeksChild_QFQthroughqdisc_peek_dequeued(), which runsqfq_dequeue()onChild_QFQ.etf_peek_timesortedlist()returns the expired head without looking at its txtime, soChild_QFQsees len > 0 and continues:
qfq_dequeue(Root_QFQ)
qfq_peek_skb()qdisc_peek_dequeued(Child_QFQ) qfq_dequeue(Child_QFQ) /* Child qlen 2 -> 1 */ agg_dequeue() etf_dequeue_timesortedlist() timesortedlist_drop() qdisc_tree_reduce_backlog() /* Child qlen 1 -> 0 */ qfq_qlen_notify() /* deactivates Child's class */ /* Root qlen 2 -> 1 */ qdisc_qlen_inc() /* Child qlen 0 -> 1 */
Child_QFQstill holds the future packet. However, notify was computed from its temporarily lowered qlen, soRoot_QFQdeactivated the class anyway, andqfq_deactivate_agg()setq->in_serv_aggto NULL.Root_QFQis left with qlen == 1 and no active aggregate.Back in Root_QFQ's
qfq_dequeue(), len is 0 and the active list of the localin_serv_aggis empty. The "sch->q.qlen== 0" early return is skipped,qfq_choose_next_agg()returns NULL, andqfq_peek_skb()dereferences it. That is the panic the commit message describes, one level further up.The reverse happens when the drops empty
Child_QFQ. Its qlen wraps to0xFFFFFFFFduring the walk, so notify is false at the next level and the ancestor keeps an empty class active.The second problem is the local
in_serv_agginqfq_dequeue(). Take an intermediate qdisc that usesqdisc_peek_dequeued(), for example QFQ -> TBF -> ETF. There the drop happens during QFQ's ownqfq_peek_skb()instead of insideagg_dequeue().Suppose that drop drains TBF and the in-service aggregate agg1.
qfq_qlen_notify()then reachesqfq_deactivate_agg(), which already movesq->in_serv_aggto the next aggregate, agg2, throughqfq_choose_next_agg().qfq_dequeue()still has agg1 in its local variable. It sees len == 0, an empty active list and a nonzero qlen, so it callsqfq_choose_next_agg()a second time. agg2 has already been removed from the schedule. Without a third aggregate this call returns NULL, and the nextqfq_peek_skb()dereferences it.The same unprivileged user can build both topologies in its own namespaces, just like QFQ -> ETF. Should
qfq_dequeue()be changed to cope with drops reported from inside a child's dequeue or peek? For example, it could lower qlen only afteragg_dequeue()succeeds and reloadq->in_serv_aggafterqfq_peek_skb(). Or should ETF report these drops in a way that does not re-enter the parent while the parent is in the middle of its own dequeue?[Severity: Critical]
This call now runs from inside ETF's ->dequeue(). If the drops leave ETF empty, the parent'sqlen_notifyruns while the parent is still inside its own dequeue. Can this makehtb_dequeue_tree()innet/sched/sch_htb.cloop forever?Take two HTB leaf classes, A and B, in the same row (level 0, same prio,
HTB_CAN_SEND). Each has an ETF child. All of A's packets have expired (delta=0 guarantees this). B holds one packet with a txtime far in the future.hprio->ptrpoints at A.
htb_dequeue_tree()picks start once:start = cl = htb_lookup_leaf(hprio, prio);A's qlen is nonzero, so the "fix start if we just deleted it" branch is skipped. HTB then calls A's dequeue:
htb_dequeue_tree()
etf_dequeue_timesortedlist()
timesortedlist_drop()
qdisc_tree_reduce_backlog()/* ETF qlen is 0, notify = true */
htb_qlen_notify()
htb_deactivate()
htb_deactivate_prios()
htb_remove_class_from_row()/* A is erased from the row */ETF returns NULL. HTB advances ptr, and
htb_lookup_leaf()returns B. B's ETF also returns NULL because its packet is not yet eligible. ptr then reaches NULL, andhtb_lookup_leaf()goes back to the leftmost class, which is B again.A is no longer in the row, so this condition never becomes false:
} while (cl != start);The loop holds the root qdisc lock with BH disabled. It only ends when B's head packet becomes eligible, and
is_packet_valid()puts no upper limit on txtime.Before this patch, A stayed in the row during the walk. The loop went A -> B -> A == start and exited.
The commit message says an unprivileged user can put ETF under a classful parent inside its own namespaces. Doesn't that make this HTB lockup reachable in the same way as the QFQ NULL dereference being fixed?
In principle, other children that notify from dequeue (the codel family) can hit the same HTB pattern. Codel rarely empties its queue through drops, though, while ETF does so every time under these conditions.
[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch. Does the walk still miss the grandparent when QFQ is the intermediate qdisc, for example DRR -> QFQ -> ETF?
qfq_dequeue()temporarily lowers its own qlen around the child dequeue:qdisc_qlen_dec(sch); skb = agg_dequeue(in_serv_agg, cl, len); if (!skb) { qdisc_qlen_inc(sch); return NULL; }Suppose ETF's expired packets are all of QFQ's backlog (QFQ qlen == n).
qdisc_tree_reduce_backlog()then notifies QFQ correctly and sets QFQ's qlen to (n - 1) - n =0xFFFFFFFF. On the next hop it computes:notify = !sch->q.qlen;which is false. The grandparent's qlen and backlog are reduced, but it gets no
qlen_notify. Afterqfq_dequeue()puts QFQ's qlen back to 0, the grandparent still has the QFQ class on its active list.
drr_dequeue()peeks the first active class andqfq_dequeue()returns NULL, so the code takes the goto out path:skb = cl->qdisc->ops->peek(cl->qdisc); if (skb == NULL) { qdisc_warn_nonwc(__func__, cl->qdisc); goto out; }The other DRR classes with queued packets then starve until new traffic reaches the QFQ class. ETS non-strict bands and HFSC appear to stall on the stale class in the same way.
ETF did not notify the grandparent before this patch either, so the behaviour is no worse. Does the statement "so classful ancestors see the removal" still hold when QFQ is in the middle?
[Severity: Medium]
Does this new call reach taprio, which is the usual parent for software-mode ETF?
taprio_graft()always setsTCQ_F_NOPARENTon the child, including in software and txtime-assist mode:new->flags |= TCQ_F_ONETXQUEUE | TCQ_F_NOPARENT;In those modes,
taprio_enqueue_one()increments taprio's own qlen and backlog.taprio_dequeue_from_txq()decrements them only when the child returns an skb:skb = qdisc_dequeue_peeked(child); if (unlikely(!skb)) return NULL; qdisc_bstats_update(sch, skb); qdisc_qstats_backlog_dec(sch, skb); qdisc_qlen_dec(sch);When
timesortedlist_drop()runs under taprio, the new walk stops at once inqdisc_tree_reduce_backlog():if (sch->flags & TCQ_F_NOPARENT) break;ETF then returns NULL, so taprio's
sch->q.qlenand qstats.backlog grow with every expired packet. The visible result is wrong tc statistics, not a crash, because taprio does not use its qlen for scheduling.The commit message says a parent will no longer "keep accounting packets that no longer exist". Would taprio need a change too, such as not setting
TCQ_F_NOPARENTin software mode, or computing taprio's qlen from its children instead of keeping a separate count?--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261104135707.725-1-me%40riley.kitchen