[PATCH] net/sched: sch_qfq: revalidate aggregate after peek
From: Jérémy Jean
Date: Fri Nov 06 2026 - 15:03:28 EST
qfq_dequeue() keeps in_serv_agg across qfq_peek_skb(), but a child peek
can re-enter QFQ and free it. KASAN reports a UAF:
BUG: KASAN: slab-use-after-free in qfq_dequeue+0x124/0xad0
Read of size 4 at addr ffff88800740423c by task swapper/0/0
After each child peek, restart qfq_dequeue() if either q->in_serv_agg
or cl->agg changed. Also use cl->agg after the child peek in qfq_enqueue().
Fixes: 462dbc9101ac ("pkt_sched: QFQ Plus: fair-queueing service at DRR cost")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Jérémy Jean <Jeremy.Jean@xxxxxxxxxxxxxxxxx>
---
net/sched/sch_qfq.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/net/sched/sch_qfq.c b/net/sched/sch_qfq.c
index 6f3b7273cb160..dc813822d3825 100644
--- a/net/sched/sch_qfq.c
+++ b/net/sched/sch_qfq.c
@@ -1100,17 +1100,24 @@ static void qfq_schedule_agg(struct qfq_sched *q, struct qfq_aggregate *agg);
static struct sk_buff *qfq_dequeue(struct Qdisc *sch)
{
struct qfq_sched *q = qdisc_priv(sch);
- struct qfq_aggregate *in_serv_agg = q->in_serv_agg;
+ struct qfq_aggregate *in_serv_agg;
struct qfq_class *cl;
struct sk_buff *skb = NULL;
/* next-packet len, 0 means no more active classes in in-service agg */
unsigned int len = 0;
+restart:
+ in_serv_agg = q->in_serv_agg;
+ skb = NULL;
+ len = 0;
if (in_serv_agg == NULL)
return NULL;
- if (!list_empty(&in_serv_agg->active))
+ if (!list_empty(&in_serv_agg->active)) {
skb = qfq_peek_skb(in_serv_agg, &cl, &len);
+ if (unlikely(in_serv_agg != q->in_serv_agg || cl->agg != in_serv_agg))
+ goto restart;
+ }
/*
* If there are no active classes in the in-service aggregate,
@@ -1148,6 +1155,8 @@ static struct sk_buff *qfq_dequeue(struct Qdisc *sch)
*/
in_serv_agg = q->in_serv_agg = qfq_choose_next_agg(q);
skb = qfq_peek_skb(in_serv_agg, &cl, &len);
+ if (unlikely(in_serv_agg != q->in_serv_agg || cl->agg != in_serv_agg))
+ goto restart;
}
if (!skb)
return NULL;
@@ -1271,9 +1280,10 @@ static int qfq_enqueue(struct sk_buff *skb, struct Qdisc *sch,
/* if the class is active, then done here */
if (cl_is_active(cl)) {
if (unlikely(skb == cl->qdisc->ops->peek(cl->qdisc)) &&
- list_first_entry(&agg->active, struct qfq_class, alist)
+ cl_is_active(cl) &&
+ list_first_entry(&cl->agg->active, struct qfq_class, alist)
== cl && cl->deficit < len)
- list_move_tail(&cl->alist, &agg->active);
+ list_move_tail(&cl->alist, &cl->agg->active);
return err;
}
--
2.47.3