Skip to content

Commit 3f98113

Browse files
congwangPaolo Abeni
authored andcommitted
sch_hfsc: Fix qlen accounting bug when using peek in hfsc_enqueue()
When enqueuing the first packet to an HFSC class, hfsc_enqueue() calls the child qdisc's peek() operation before incrementing sch->q.qlen and sch->qstats.backlog. If the child qdisc uses qdisc_peek_dequeued(), this may trigger an immediate dequeue and potential packet drop. In such cases, qdisc_tree_reduce_backlog() is called, but the HFSC qdisc's qlen and backlog have not yet been updated, leading to inconsistent queue accounting. This can leave an empty HFSC class in the active list, causing further consequences like use-after-free. This patch fixes the bug by moving the increment of sch->q.qlen and sch->qstats.backlog before the call to the child qdisc's peek() operation. This ensures that queue length and backlog are always accurate when packet drops or dequeues are triggered during the peek. Fixes: 12d0ad3 ("net/sched/sch_hfsc.c: handle corner cases where head may change invalidating calculated deadline") Reported-by: Mingi Cho <[email protected]> Signed-off-by: Cong Wang <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Reviewed-by: Jamal Hadi Salim <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 407e0ef commit 3f98113

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

net/sched/sch_hfsc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,9 @@ hfsc_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free)
15691569
return err;
15701570
}
15711571

1572+
sch->qstats.backlog += len;
1573+
sch->q.qlen++;
1574+
15721575
if (first && !cl->cl_nactive) {
15731576
if (cl->cl_flags & HFSC_RSC)
15741577
init_ed(cl, len);
@@ -1584,9 +1587,6 @@ hfsc_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free)
15841587

15851588
}
15861589

1587-
sch->qstats.backlog += len;
1588-
sch->q.qlen++;
1589-
15901590
return NET_XMIT_SUCCESS;
15911591
}
15921592

0 commit comments

Comments
 (0)