Re: [PATCH v2 net] net/sched: sch_qfq: bound backward slot rotation

From: Paolo Abeni

Date: Tue Dec 01 2026 - 16:24:33 EST


On 12/1/26 10:28, Jamal Hadi Salim wrote:
On Tue, Dec 1, 2026 at 4:22 AM Lin Jiapeng <ljp1205831794@xxxxxxxxx> wrote:
On 2026-12-01 1:22 a.m., Paolo Abeni wrote:
On 11/24/26 05:01, Lin Jiapeng wrote:
From: Lin Jiapeng <jiapenglin@xxxxxxxxxxx>

QFQ+ keeps aggregates in timestamp-ordered slots and rotates the
occupied-slot bitmap when a group's start time decreases, avoiding the
need to move the aggregates themselves. Insertions are capped so that
occupied slots leave room for a later backward adjustment.

A stale aggregate can make the decrease larger than the slots can
represent. Rotation can then drop occupied bits or alias distinct logical
slots onto one physical hlist, and a later removal can clear bits in the
following slot-list pointers or leave stale bits. KASAN reports a
slab-use-after-free read of size 8 in qfq_choose_next_agg+0xd04/0xd90 by
task repro/92 after the corrupted group is selected, followed by a panic.

Limit backward rotation using the highest occupied bit so every occupied
offset remains below QFQ_MAX_SLOTS. If the decrease exceeds that limit,
move the activating aggregate's S/F and rounded start time forward by the
same slot-aligned delta before rotating. This preserves its service
interval and the logical-to-physical slot mapping, including repeated
rotations, while leaving representable rotations unchanged.

Fixes: 462dbc9101ac ("pkt_sched: QFQ Plus: fair-queueing service at
DRR cost")
Reported-by: TencentOS Corvus AI <corvus@xxxxxxxxxxx>
Link: https://lore.kernel.org/all/20261116121710.77403-1-
ljp1205831794@xxxxxxxxx/
Signed-off-by: Lin Jiapeng <jiapenglin@xxxxxxxxxxx>
@Jamal: could you please have a look?

It's totally unclear to me how the aggregates become state and if
the issue could/should be addressed flushing such stale entries
earlier.

/P

Sorry for the unclear description. By "stale" I meant old timestamps on
live objects, not dead aggregates that should have been removed.

The PoC works as follows:

1. Group D remains unserviced while q->V advances, so D->F stays old.
2. Aggregate A is reactivated in nonempty group g, and
qfq_update_start() assigns the old D->F to A->S.
3. This causes a large backward rotation of g's slot bitmap.
4. A subsequent class change removes aggregate B, whose rotated offset
is now beyond the 64-bit bitmap.

For example:

old D->F = 8, g->S = 55, B->S = 83

A->S = D->F
|
v
rotate g by 55 - 8 = 47 slots
|
v
remove B: offset = 83 - 8 = 75
|
v
__clear_bit(75, &g->full_slots)
|
+--> bit 75 is outside bits 0..63
and overwrites g->slots[].first

All involved aggregates and groups are still live. A still owns a class,
and D is a valid ER group, so flushing them earlier would remove valid
scheduling state rather than clean up stale entries.

The PoC uses only packet sends and class changes; no race is required.

I will let Paolo decide if he wants to take this as is - but you
should always describe how to reproduce in the commit.
Here's the order i use in the commits:
1) How the issue was found
2) What the issue is (include KASAN etc)
3) what the fix is
4) Conditions to recreate
Since it seams that the lack of clarity is not just for me, I suggest
reposting with a reworded commit. Please try to keep it concise and
include all the requested information.

Thanks,

Paolo