From: Dickson Wu <dick…@certik.com>
A leaf qdisc can drop its last queued packet from its dequeue callback.
The resulting backlog notification deactivates the HTB class while
htb_dequeue_tree() still holds it as the start of its scan. If another
class in the row is not ready, the scan cannot return to the removed
start and spins with the root qdisc lock held. An unprivileged user can
trigger this in a user and network namespace; a KVM guest stalls in the
transmit softirq.
When the child returns NULL after deactivating the class, look up the
next active leaf and update the scan start if the removed class was the
start. Continue scanning so a ready sibling can still be served.
A reproducer is available on request.
Fixes: 256d61b87b2c ("[NET_SCHED]: Fix endless loops (part 4): HTB")
Signed-off-by: Dickson Wu <dick…@certik.com>
---
Tested on net e9d78fc6741a in KVM (x86_64), as an unprivileged user in
a user namespace, sender pinned to CPU 0:
- base: two trigger runs stall the guest for 19.7 and 19.8 seconds.
- patched: both trigger runs and both controls finish in 2.0 seconds.
- tdc HTB and netem tests: 29/29 pass on both kernels.
- W=1 build of sch_htb.o (x86_64 and allmodconfig), no warnings.
This was found and the fix prepared with AI coding tools (OpenAI Codex
agents, with review by Claude). I went over the analysis and the patch
before signing off.
net/sched/sch_htb.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
index 1ba67b121..63403112d 100644
--- a/net/sched/sch_htb.c
+++ b/net/sched/sch_htb.c
@@ -917,6 +917,15 @@ static struct sk_buff *htb_dequeue_tree(struct htb_sched *q, const int prio,
if (likely(skb != NULL))
break;
+ if (unlikely(!cl->prio_activity)) {
+ struct htb_class *next = htb_lookup_leaf(hprio, prio);
+
+ if (cl == start)
+ start = next;
+ cl = next;
+ goto next;
+ }
+
qdisc_warn_nonwc("htb", cl->leaf.q);
htb_next_rb_node(level ? &cl->parent->inner.clprio[prio].ptr:
&q->hlevel[0].hprio[prio].ptr);
--
2.43.0