* [PATCH net v3] net/sched: sch_qfq: revalidate aggregate after peek
@ 2026-11-12 16:49 Jérémy Jean
2026-11-12 16:58 ` netdev-bot+sinfo
2026-11-16 17:07 ` netdev-bot+sashiko
0 siblings, 2 replies; 3+ messages in thread
From: Jérémy Jean @ 2026-11-12 16:49 UTC (permalink / raw)
To: Jamal Hadi Salim, Jiri Pirko
Cc: netdev, linux-kernel, Jérémy Jean, stable
A QFQ child callback can re-enter qfq_enqueue() during a peek or
dequeue. qfq_enqueue() can then move the class and free its
aggregate. This can cause a UAF or corrupt the active lists and
service accounting.
Restart qfq_dequeue() after a selection change. Defer recursive root
enqueues through agg_dequeue() and replay them after service
accounting. Keep replay drops on the same root. Correct ancestor
counts after failures. Recheck activity and use the current aggregate
in qfq_enqueue(). Keep declarations before the retry label.
Fixes: 462dbc9101ac ("pkt_sched: QFQ Plus: fair-queueing service at DRR cost")
Cc: stable@vger.kernel.org
Signed-off-by: Jérémy Jean <Jeremy.Jean@oss.cyber.gouv.fr>
---
Changes in v3 after review from Sashiko:
- Keep native child peeks. Defer recursive enqueues until agg_dequeue() returns.
- Keep replay drops on the stable root. Repair ancestor accounting on failure.
- Keep retry declarations before the label.
Changes in v2 after review from Sashiko:
- Cover the post-dequeue peek.
- Clarify the trigger.
v1: https://lore.kernel.org/all/20261106200236.716641-2-Jeremy.Jean@oss.cyber.gouv.fr/
v2: https://lore.kernel.org/all/20261110222946.2147440-2-Jeremy.Jean@oss.cyber.gouv.fr/
net/sched/sch_qfq.c | 40 +++++++++++++++++++++++++++++++++-------
1 file changed, 33 insertions(+), 7 deletions(-)
diff --git a/net/sched/sch_qfq.c b/net/sched/sch_qfq.c
index e900890..d867d3b 100644
--- a/net/sched/sch_qfq.c
+++ b/net/sched/sch_qfq.c
@@ -182,6 +182,7 @@ struct qfq_sched {
u64 oldV, V; /* Precise virtual times. */
struct qfq_aggregate *in_serv_agg; /* Aggregate being served. */
+ struct sk_buff_head *deferred_enqueues;
u32 wsum; /* weight sum */
u32 iwsum; /* inverse weight sum */
@@ -1103,17 +1104,25 @@ 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;
+ struct sk_buff_head deferred_enqueues;
+ struct sk_buff *skb, *next;
/* next-packet len, 0 means no more active classes in in-service agg */
- unsigned int len = 0;
+ unsigned int len;
+
+restart:
+ in_serv_agg = q->in_serv_agg;
+ 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,
@@ -1151,17 +1160,23 @@ 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;
qdisc_qlen_dec(sch);
+ qdisc_root_sleeping(sch)->flags |= TCQ_F_DEQUEUE_DROPS;
+ __skb_queue_head_init(&deferred_enqueues);
+ q->deferred_enqueues = &deferred_enqueues;
skb = agg_dequeue(in_serv_agg, cl, len);
+ q->deferred_enqueues = NULL;
if (!skb) {
qdisc_qlen_inc(sch);
- return NULL;
+ goto replay_deferred;
}
qdisc_qstats_backlog_dec(sch, skb);
@@ -1181,6 +1196,11 @@ static struct sk_buff *qfq_dequeue(struct Qdisc *sch)
len, (unsigned long long) in_serv_agg->F,
(unsigned long long) q->V);
+replay_deferred:
+ while ((next = __skb_dequeue(&deferred_enqueues)) != NULL)
+ if (qdisc_enqueue(next, sch, &qdisc_root_sleeping(sch)->to_free))
+ qdisc_tree_reduce_backlog(sch, 1, qdisc_pkt_len(next));
+
return skb;
}
@@ -1236,6 +1256,11 @@ static int qfq_enqueue(struct sk_buff *skb, struct Qdisc *sch,
struct qfq_aggregate *agg;
int err = 0;
+ if (unlikely(q->deferred_enqueues)) {
+ __skb_queue_tail(q->deferred_enqueues, skb);
+ return NET_XMIT_SUCCESS;
+ }
+
cl = qfq_classify(skb, sch, &err);
if (cl == NULL) {
if (err & __NET_XMIT_BYPASS)
@@ -1274,9 +1299,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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net v3] net/sched: sch_qfq: revalidate aggregate after peek
2026-11-12 16:49 [PATCH net v3] net/sched: sch_qfq: revalidate aggregate after peek Jérémy Jean
@ 2026-11-12 16:58 ` netdev-bot+sinfo
2026-11-16 17:07 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-12 16:58 UTC (permalink / raw)
To: Jérémy Jean
Cc: Jamal Hadi Salim, Jiri Pirko, netdev, linux-kernel, stable
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account. If the series needs another revision for
other reasons, please include the information in the commit messages
then.
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v3] net/sched: sch_qfq: revalidate aggregate after peek
2026-11-12 16:49 [PATCH net v3] net/sched: sch_qfq: revalidate aggregate after peek Jérémy Jean
2026-11-12 16:58 ` netdev-bot+sinfo
@ 2026-11-16 17:07 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 17:07 UTC (permalink / raw)
To: Jeremy.Jean; +Cc: jhs, jiri, netdev, linux-kernel, stable, kuba
Thank you for your contribution! Sashiko AI review found 7 potential
issue(s) to consider.
Critical: 0 · High: 3 · Medium: 3 · Low: 1
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).
- [High] In qfq_dequeue() (net/sched/sch_qfq.c), `q->deferred_enqueues`
is one pointer per qdisc.
- [High] The new replay loop in qfq_dequeue()
(net/sched/sch_qfq.c:1200-1202) calls `qdisc_enqueue(next, sch, ...)`.
- [High] net/sched: sch_qfq: premature qdisc_qlen_dec() triggers false
qlen_notify
- [Medium] qfq_dequeue() calls qdisc_root_sleeping(sch) twice without
holding rcu_read_lock(): once at line 1171 to set TCQ_F_DEQUEUE_DROPS,…
- [Medium] qfq_dequeue() now does a plain read-modify-write of the root
qdisc's flags word on every dequeue: `qdisc_root_sleeping(sch)->flags…
- [Medium] On every packet it dequeues, qfq_dequeue() sets
TCQ_F_DEQUEUE_DROPS on the root qdisc, which may be a different qdisc…
- [Low] The commit message says only "A QFQ child callback can re-enter
qfq_enqueue() during a peek or dequeue".
--
net/sched: sch_qfq: revalidate aggregate after peek
This patch makes qfq_dequeue() restart when the in-service aggregate
changes during a child peek. It also defers enqueues that re-enter
qfq_enqueue() while agg_dequeue() runs, and replays them after service
accounting. Finally, qfq_enqueue() now rechecks class activity and uses
cl->agg after peeking the child.
> A QFQ child callback can re-enter qfq_enqueue() during a peek or
> dequeue.
[Severity: Low]
This isn't a bug, but could the commit message name the trigger?
As far as I can tell, the path is:
netem_dequeue()
qdisc_enqueue(skb, q->qdisc, &to_free)
netem_enqueue() <- duplicating child netem
rootq->enqueue(skb2, rootq, to_free)
qfq_enqueue()
qfq_change_agg() -> ... -> qfq_destroy_agg()
The goto tfifo_dequeue loop in netem_dequeue() can also cause several
nested enqueues from a single peek.
The v2 changelog says "Clarify the trigger". The body still doesn't name
a qdisc or a configuration.
> diff --git a/net/sched/sch_qfq.c b/net/sched/sch_qfq.c
> index e900890e9c544..d867d3b918def 100644
> --- a/net/sched/sch_qfq.c
> +++ b/net/sched/sch_qfq.c
[ ... ]
> @@ -1151,17 +1160,23 @@ 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;
>
> qdisc_qlen_dec(sch);
>
> + qdisc_root_sleeping(sch)->flags |= TCQ_F_DEQUEUE_DROPS;
[Severity: Medium]
Is it safe to call qdisc_root_sleeping() here without rcu_read_lock()?
qdisc_root_sleeping() is:
return rcu_dereference_rtnl(qdisc->dev_queue->qdisc_sleeping);
On the transmit path only rcu_read_lock_bh() is held, and RTNL is not:
__dev_queue_xmit()
__dev_xmit_skb()
qdisc_run()
dequeue_skb()
qfq_dequeue()
With CONFIG_PROVE_RCU, can this trigger a "suspicious
rcu_dereference_check() usage" splat on every dequeue? The
qdisc_root_sleeping() call in the replay loop below has the same
problem.
qdisc_dequeue_drop() uses the same root->to_free mechanism, and it
wraps the call:
rcu_read_lock();
root = qdisc_root_sleeping(q);
[Severity: Medium]
Can this plain read-modify-write of the root qdisc's flags race with
qdisc_offload_dump_helper()?
This line runs under the root qdisc lock. qdisc_offload_dump_helper()
changes the same word while holding only RTNL:
sch->flags &= ~TCQ_F_OFFLOADED;
...
if (!err)
sch->flags |= TCQ_F_OFFLOADED;
It runs on every tc qdisc show, through tc_fill_qdisc() -> tbf_dump()
-> tbf_offload_dump(). prio, red, ets, gred, fifo and mq reach it the
same way.
Take a tree like TBF -> QFQ, where tbf_dequeue() peeks the child and
runs qfq_dequeue(). A stale write-back from the dump can clear
TCQ_F_DEQUEUE_DROPS, and then qdisc_run_end() does not collect
root->to_free:
if (qdisc->flags & TCQ_F_DEQUEUE_DROPS) {
to_free = qdisc->to_free;
...
Would the replay drops then stay on root->to_free, and leak if the root
is destroyed first?
The race can go the other way too. The QFQ write can undo a
TCQ_F_OFFLOADED update, so TCA_HW_OFFLOAD would be reported wrongly in
dumps.
Before this patch, the data path did not write another qdisc's flags.
[Severity: Medium]
This sets TCQ_F_DEQUEUE_DROPS on the root qdisc on every dequeued
packet, and nothing clears it. The root may be a different qdisc type.
Until now, a qdisc set this flag on itself at init (codel, fq_codel,
cake and dualpi2). That matches the flag's description, "->dequeue()
can drop packets in q->to_free".
Say QFQ sets the flag on an HTB root. Every codel, fq_codel, cake or
dualpi2 under that root then switches qdisc_dequeue_drop() from
kfree_skb_reason() to deferring drops onto root->to_free. qdisc_run_end()
also starts returning root->to_free. Both stay that way after the QFQ
qdisc is deleted.
The unconditional |= also writes to the root qdisc's first cache line on
every packet, and other CPUs read that line in __dev_xmit_skb().
The commit message only says "Keep replay drops on the same root".
Should it describe this cross-qdisc change? Should it also mention the
dependency on the TCQ_F_DEQUEUE_DROPS and qdisc_run_end() to_free code,
given the requested stable backport?
> + __skb_queue_head_init(&deferred_enqueues);
> + q->deferred_enqueues = &deferred_enqueues;
> skb = agg_dequeue(in_serv_agg, cl, len);
> + q->deferred_enqueues = NULL;
[Severity: High]
Can a nested qfq_dequeue() on the same qdisc clear this pointer while
the outer call is still inside agg_dequeue()?
q->deferred_enqueues is a single pointer per qdisc. It is set, then
cleared to NULL, with no save and restore. Consider a tree where QFQ Q
is a child of another QFQ R:
R (qfq) -> class X -> Q (qfq) -> class Y -> netem A -> netem B (duplicate)
The sequence could be:
qfq_dequeue(R) peeks X
qdisc_peek_dequeued(Q)
qfq_dequeue(Q) <- D1, sets Q->deferred_enqueues
agg_dequeue()
qdisc_peek_len(A)
netem_dequeue(A)
netem_enqueue(B)
rootq->enqueue(skb2, rootq, to_free)
qfq_enqueue(R)
qdisc_enqueue(skb2, Q) <- deferred, NET_XMIT_SUCCESS
cl->qdisc->ops->peek(Q) <- X is still active
qdisc_peek_dequeued(Q)
qfq_dequeue(Q) <- D2
Q->gso_skb is still empty because D1 has not returned, so the peek runs
a full qfq_dequeue(Q). On its way out, D2 sets Q->deferred_enqueues to
NULL. It then replays its own list through the normal qfq_enqueue()
path, while D1 is still inside agg_dequeue().
>From then on, re-entrant enqueues during D1's agg_dequeue() are no
longer deferred. That covers D2's replay and later passes of the
tfifo_dequeue loop in netem_dequeue(A). On that path, this chain can
free the in_serv_agg that D1 still holds:
qfq_enqueue()
qfq_change_agg()
qfq_deact_rm_from_agg()
qfq_destroy_agg()
kfree(agg)
agg_dequeue() then continues with:
else if (cl->deficit < qdisc_peek_len(cl->qdisc)) {
cl->deficit += agg->lmax;
list_move_tail(&cl->alist, &agg->active);
}
After that, qfq_dequeue() updates in_serv_agg->budget and reads
in_serv_agg->F.
Doesn't this leave reachable the same use-after-free and active list
corruption that the commit is meant to fix? Is a save and restore of
the previous pointer needed here? Another option would be to avoid
peeking a child that is in the middle of its own dequeue.
>
> if (!skb) {
> qdisc_qlen_inc(sch);
> - return NULL;
> + goto replay_deferred;
> }
[ ... ]
> @@ -1181,6 +1196,11 @@ static struct sk_buff *qfq_dequeue(struct Qdisc *sch)
> len, (unsigned long long) in_serv_agg->F,
> (unsigned long long) q->V);
>
> +replay_deferred:
> + while ((next = __skb_dequeue(&deferred_enqueues)) != NULL)
> + if (qdisc_enqueue(next, sch, &qdisc_root_sleeping(sch)->to_free))
> + qdisc_tree_reduce_backlog(sch, 1, qdisc_pkt_len(next));
[Severity: High]
Can the replay loop send a false qlen_notify to the parent qdisc?
qdisc_qlen_dec(sch) runs before agg_dequeue(). The deferral in
qfq_enqueue() returns NET_XMIT_SUCCESS without touching sch->q.qlen.
The ancestors above sch have already counted each deferred skb, but
sch has not. So while the replay loop runs, sch->q.qlen counts neither
the skb about to be returned nor the deferred skbs still on the list.
When a parent peeks a QFQ child, qdisc_peek_dequeued() calls
qfq_dequeue(). It stores the result in sch->gso_skb and calls
qdisc_qlen_inc() only after qfq_dequeue() returns. DRR, ETS, HFSC and
QFQ all peek their children this way.
Say sch holds one packet and a deferred skb fails to enqueue during
the replay. qdisc_tree_reduce_backlog() then computes
notify = !sch->q.qlen, which is true, and calls cops->qlen_notify() on
the parent. The parent deactivates sch's class. Yet qfq_dequeue() still
returns an skb, which ends up in sch->gso_skb with q.qlen == 1.
The same happens with two deferred skbs where the first fails and the
second succeeds. This case applies even when the parent dequeues sch
directly, as HTB does. The parent is told sch is empty, and then the
second replay puts a packet in sch without reactivating the class.
In both cases the parent's class stays inactive while sch holds a
packet. It is not served until a later enqueue reactivates it.
With an outer QFQ, the first case runs inside the outer agg_dequeue(),
through qdisc_peek_len(cl->qdisc):
else if (cl->deficit < qdisc_peek_len(cl->qdisc)) {
cl->deficit += agg->lmax;
list_move_tail(&cl->alist, &agg->active);
}
By this point qfq_qlen_notify() has already taken cl off agg->active.
If cl was the only active class, qfq_deactivate_agg() has also run.
Since agg is the outer in-service aggregate, it picked a new one.
list_move_tail() then puts cl back on agg->active, but agg is now
neither in service nor in any slot. Wouldn't later enqueues to that
aggregate see a non-empty active list and skip qfq_activate_agg()?
That would stall the aggregate for good. The outer qfq_dequeue() also
goes on to charge len to its stale in_serv_agg.
The early qdisc_qlen_dec() is not new. But this patch adds a new
caller of qdisc_tree_reduce_backlog() in that window, along with skbs
that sch has not counted yet. Could the deferred skbs be counted in
sch->q.qlen when they are queued? Or could the decrement move after
the replay? Or is there another way to keep sch->q.qlen in step with
its ancestors whenever the tree is walked?
[Severity: High]
Can qdisc_pkt_len(next) read next after it has been freed?
qfq_enqueue() passes the child's error back unchanged. Not every child
puts a dropped skb on to_free. Take a TBF child and a GSO skb larger
than max_size:
qfq_dequeue() <- replay loop
qfq_enqueue()
qdisc_enqueue(skb, cl->qdisc, to_free)
tbf_enqueue()
tbf_segment()
If no segment could be enqueued, tbf_segment() ends with:
kfree_skb(skb);
return NET_XMIT_DROP;
The deferred skb here is a netem duplicate made with skb_clone(), so it
can be a GSO skb.
In that case qdisc_pkt_len(next) reads the cb of a freed skb. The
resulting garbage length is subtracted from every ancestor's
qstats.backlog.
Would it be safer to save qdisc_pkt_len(next) before calling
qdisc_enqueue(), the way netem_dequeue() does?
>
> return skb;
> }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112164954.2786444-2-Jeremy.Jean%40oss.cyber.gouv.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-16 17:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 16:49 [PATCH net v3] net/sched: sch_qfq: revalidate aggregate after peek Jérémy Jean
2026-11-12 16:58 ` netdev-bot+sinfo
2026-11-16 17:07 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox