* [PATCH v2 net] net/sched: sch_qfq: bound backward slot rotation
@ 2026-11-24 4:01 Lin Jiapeng
2026-11-30 17:22 ` Paolo Abeni
2026-12-02 9:18 ` [PATCH v3 " Lin Jiapeng
0 siblings, 2 replies; 7+ messages in thread
From: Lin Jiapeng @ 2026-11-24 4:01 UTC (permalink / raw)
To: jhs, jiri, davem, edumazet, kuba, pabeni, horms, paolo.valente,
netdev, linux-kernel
Cc: Lin Jiapeng, TencentOS Corvus AI
From: Lin Jiapeng <jiapenglin@tencent.com>
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@tencent.com>
Link: https://lore.kernel.org/all/20261116121710.77403-1-ljp1205831794@gmail.com/
Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
---
v2:
- Derive the backward rotation limit from the highest occupied slot.
- Keep occupied offsets below QFQ_MAX_SLOTS to prevent hlist aliasing.
- Update the insertion and rotation comments.
v1: https://lore.kernel.org/all/20261116121710.77403-1-ljp1205831794@gmail.com/
net/sched/sch_qfq.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/net/sched/sch_qfq.c b/net/sched/sch_qfq.c
index e900890e9c54..3e2b40bea668 100644
--- a/net/sched/sch_qfq.c
+++ b/net/sched/sch_qfq.c
@@ -843,9 +843,9 @@ static void qfq_make_eligible(struct qfq_sched *q)
* The index of the slot in which the input aggregate agg is to be
* inserted must not be higher than QFQ_MAX_SLOTS-2. There is a '-2'
* and not a '-1' because the start time of the group may be moved
- * backward by one slot after the aggregate has been inserted, and
- * this would cause non-empty slots to be right-shifted by one
- * position.
+ * backward after the aggregate has been inserted, and this would cause
+ * non-empty slots to be right-shifted. Backward rotation is separately
+ * bounded so that every occupied slot stays below QFQ_MAX_SLOTS.
*
* QFQ+ fully satisfies this bound to the slot index if the parameters
* of the classes are not changed dynamically, and if QFQ+ never
@@ -965,7 +965,8 @@ static struct qfq_aggregate *qfq_slot_scan(struct qfq_group *grp)
* because we use ffs() to find the first non-empty slot.
* This covers decreases in the group's start time, but what about
* increases of the start time ?
- * Here too we should make sure that i is less than 32
+ * The caller keeps every occupied slot below QFQ_MAX_SLOTS after the
+ * shift, preserving the one-to-one mapping between bits and bucket lists.
*/
static void qfq_slot_rotate(struct qfq_group *grp, u64 roundedS)
{
@@ -1300,7 +1301,8 @@ static int qfq_enqueue(struct sk_buff *skb, struct Qdisc *sch,
static void qfq_schedule_agg(struct qfq_sched *q, struct qfq_aggregate *agg)
{
struct qfq_group *grp = agg->grp;
- u64 roundedS;
+ u64 roundedS, slot;
+ unsigned int max_back;
int s;
roundedS = qfq_round_down(agg->S, grp->slot_shift);
@@ -1318,6 +1320,17 @@ static void qfq_schedule_agg(struct qfq_sched *q, struct qfq_aggregate *agg)
if (!qfq_gt(grp->S, agg->S))
goto skip_update;
+ slot = (grp->S - roundedS) >> grp->slot_shift;
+ max_back = QFQ_MAX_SLOTS - 1 - __fls(grp->full_slots);
+ if (unlikely(slot > max_back)) {
+ u64 deltaS = grp->S - roundedS -
+ ((u64)max_back << grp->slot_shift);
+
+ agg->S += deltaS;
+ agg->F += deltaS;
+ roundedS += deltaS;
+ }
+
/* create a slot for this agg->S */
qfq_slot_rotate(grp, roundedS);
/* group was surely ineligible, remove */
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 net] net/sched: sch_qfq: bound backward slot rotation
2026-11-24 4:01 [PATCH v2 net] net/sched: sch_qfq: bound backward slot rotation Lin Jiapeng
@ 2026-11-30 17:22 ` Paolo Abeni
2026-12-01 9:19 ` Jamal Hadi Salim
2026-12-01 9:22 ` Lin Jiapeng
2026-12-02 9:18 ` [PATCH v3 " Lin Jiapeng
1 sibling, 2 replies; 7+ messages in thread
From: Paolo Abeni @ 2026-11-30 17:22 UTC (permalink / raw)
To: jhs, jiri, netdev, Lin Jiapeng
Cc: Lin Jiapeng, TencentOS Corvus AI, kuba, davem, edumazet,
paolo.valente, linux-kernel, horms
On 11/24/26 05:01, Lin Jiapeng wrote:
> From: Lin Jiapeng <jiapenglin@tencent.com>
>
> 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@tencent.com>
> Link: https://lore.kernel.org/all/20261116121710.77403-1-ljp1205831794@gmail.com/
> Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
@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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 net] net/sched: sch_qfq: bound backward slot rotation
2026-11-30 17:22 ` Paolo Abeni
@ 2026-12-01 9:19 ` Jamal Hadi Salim
2026-12-01 9:22 ` Lin Jiapeng
1 sibling, 0 replies; 7+ messages in thread
From: Jamal Hadi Salim @ 2026-12-01 9:19 UTC (permalink / raw)
To: Paolo Abeni
Cc: jiri, netdev, Lin Jiapeng, Lin Jiapeng, TencentOS Corvus AI, kuba,
davem, edumazet, paolo.valente, linux-kernel, horms
On Mon, Nov 30, 2026 at 12:22 PM Paolo Abeni <pabeni@redhat.com> wrote:
>
> On 11/24/26 05:01, Lin Jiapeng wrote:
> > From: Lin Jiapeng <jiapenglin@tencent.com>
> >
> > 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@tencent.com>
> > Link: https://lore.kernel.org/all/20261116121710.77403-1-ljp1205831794@gmail.com/
> > Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
> @Jamal: could you please have a look?
>
Unfortunately the OP doesnt include how they actually created the
issue; otherwise, our test environment could have vetted it.
The code changes look sane. The sashikos are complaining about
commit/code doc (not code) which should only be fixed if there's a
respin and the only reason i can see it needing a respin is to
essentially answer how it was reproduced (which also answer your
question below).
> It's totally unclear to me how the aggregates become state and if
> the issue could/should be addressed flushing such stale entries
> earlier.
cheers,
jamal
> /P
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 net] net/sched: sch_qfq: bound backward slot rotation
2026-11-30 17:22 ` Paolo Abeni
2026-12-01 9:19 ` Jamal Hadi Salim
@ 2026-12-01 9:22 ` Lin Jiapeng
2026-12-01 9:28 ` Jamal Hadi Salim
1 sibling, 1 reply; 7+ messages in thread
From: Lin Jiapeng @ 2026-12-01 9:22 UTC (permalink / raw)
To: Paolo Abeni, jhs, jiri, netdev
Cc: Lin Jiapeng, TencentOS Corvus AI, kuba, davem, edumazet,
paolo.valente, linux-kernel, horms
On 2026-12-01 1:22 a.m., Paolo Abeni wrote:
> On 11/24/26 05:01, Lin Jiapeng wrote:
>> From: Lin Jiapeng <jiapenglin@tencent.com>
>>
>> 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@tencent.com>
>> Link: https://lore.kernel.org/all/20261116121710.77403-1-
>> ljp1205831794@gmail.com/
>> Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
> @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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 net] net/sched: sch_qfq: bound backward slot rotation
2026-12-01 9:22 ` Lin Jiapeng
@ 2026-12-01 9:28 ` Jamal Hadi Salim
2026-12-01 21:24 ` Paolo Abeni
0 siblings, 1 reply; 7+ messages in thread
From: Jamal Hadi Salim @ 2026-12-01 9:28 UTC (permalink / raw)
To: Lin Jiapeng
Cc: Paolo Abeni, jiri, netdev, Lin Jiapeng, TencentOS Corvus AI, kuba,
davem, edumazet, paolo.valente, linux-kernel, horms
On Tue, Dec 1, 2026 at 4:22 AM Lin Jiapeng <ljp1205831794@gmail.com> 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@tencent.com>
> >>
> >> 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@tencent.com>
> >> Link: https://lore.kernel.org/all/20261116121710.77403-1-
> >> ljp1205831794@gmail.com/
> >> Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
> > @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
cheers,
jamal
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 net] net/sched: sch_qfq: bound backward slot rotation
2026-12-01 9:28 ` Jamal Hadi Salim
@ 2026-12-01 21:24 ` Paolo Abeni
0 siblings, 0 replies; 7+ messages in thread
From: Paolo Abeni @ 2026-12-01 21:24 UTC (permalink / raw)
To: Jamal Hadi Salim, Lin Jiapeng
Cc: jiri, netdev, Lin Jiapeng, TencentOS Corvus AI, kuba, davem,
edumazet, paolo.valente, linux-kernel, horms
On 12/1/26 10:28, Jamal Hadi Salim wrote:
> On Tue, Dec 1, 2026 at 4:22 AM Lin Jiapeng <ljp1205831794@gmail.com> 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@tencent.com>
>>>>
>>>> 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@tencent.com>
>>>> Link: https://lore.kernel.org/all/20261116121710.77403-1-
>>>> ljp1205831794@gmail.com/
>>>> Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
>>> @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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 net] net/sched: sch_qfq: bound backward slot rotation
2026-11-24 4:01 [PATCH v2 net] net/sched: sch_qfq: bound backward slot rotation Lin Jiapeng
2026-11-30 17:22 ` Paolo Abeni
@ 2026-12-02 9:18 ` Lin Jiapeng
1 sibling, 0 replies; 7+ messages in thread
From: Lin Jiapeng @ 2026-12-02 9:18 UTC (permalink / raw)
To: jhs, jiri, davem, edumazet, kuba, pabeni, willemb, horms,
paolo.valente, netdev
Cc: Lin Jiapeng, TencentOS Corvus AI
From: Lin Jiapeng <jiapenglin@tencent.com>
QFQ+ rotates a group's occupied-slot bitmap when an older aggregate start
time requires a backward adjustment. TencentOS Corvus AI found that a
crafted QFQ configuration and packet sequence can corrupt this state and
crash the kernel.
An unserviced group can retain an old finish time while q->V advances.
qfq_update_start() may copy that timestamp to an aggregate reactivated in
a nonempty group. The resulting rotation does not account for the highest
occupied slot, so it can move offsets beyond QFQ_MAX_SLOTS, lose bitmap
bits, or alias distinct logical offsets onto one hlist. These are old
timestamps on live aggregates, so flushing them would discard valid
scheduling state. A later class change removes such an aggregate and
clears bits beyond full_slots, leading to this report:
[ 33.849150] BUG: KASAN: slab-out-of-bounds in qfq_choose_next_agg+0xd04/0xd90
[ 33.849700] Read of size 8 at addr ff11000103386010 by task repro/72
[ 33.850270] CPU: 0 UID: 1000 PID: 72 Comm: repro Not tainted 7.4.0-rc4 #1 PREEMPT(lazy)
[ 33.850622] Call Trace:
[ 33.851402] qfq_choose_next_agg+0xd04/0xd90
[ 33.851494] qfq_dequeue+0x365/0x14b0
[ 33.851647] qdisc_peek_dequeued+0x91/0x280
[ 33.851725] tbf_dequeue+0x91/0xcd0
[ 33.851813] __qdisc_run+0x184/0x1830
[ 33.851908] __dev_queue_xmit+0x27f7/0x3a50
[ 33.852797] packet_sendmsg+0x2270/0x4dd0
[ 33.853363] __sys_sendto+0x430/0x480
[ 33.853674] __x64_sys_sendto+0xe0/0x1c0
[ 33.854150] do_syscall_64+0x108/0x600
[ 33.854412] entry_SYSCALL_64_after_hwframe+0x77/0x7f
[ 33.858951] Kernel panic - not syncing: KASAN: panic_on_warn set ...
Bound backward rotation using the highest occupied bit. If the decrease
exceeds the available headroom, advance the activating aggregate's S, F,
and rounded start time by the same slot-aligned delta before rotating.
This keeps occupied offsets within the bitmap and slot array, preserves
F-S and the logical-to-physical mapping, and leaves representable
rotations unchanged.
With CONFIG_NET_SCH_QFQ, CONFIG_NET_SCH_TBF, CONFIG_VETH, and KASAN
enabled, an unprivileged user that can create user and network namespaces
can reproduce this in a single-vCPU guest. The reproducer creates veth
with TBF above QFQ, uses packet sends and class changes to force the
rotation and remove displaced aggregates, then sends more packets to
select the corrupted group. No race or heap grooming is required. The
recorded unfixed KASAN kernel panicked in qfq_choose_next_agg(); the
fixed kernel completed the same sequence.
Fixes: 462dbc9101ac ("pkt_sched: QFQ Plus: fair-queueing service at DRR cost")
Reported-by: TencentOS Corvus AI <corvus@tencent.com>
Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
---
v3:
- Clarify that old timestamps belong to live aggregates and explain the
complete trigger path.
- Add concise reproduction conditions and KASAN evidence; code is unchanged.
v2: https://lore.kernel.org/netdev/20261124040208.13282-1-ljp1205831794@gmail.com/
v1: https://lore.kernel.org/all/20261116121710.77403-1-ljp1205831794@gmail.com/
net/sched/sch_qfq.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/net/sched/sch_qfq.c b/net/sched/sch_qfq.c
index e900890e9c54..3e2b40bea668 100644
--- a/net/sched/sch_qfq.c
+++ b/net/sched/sch_qfq.c
@@ -843,9 +843,9 @@ static void qfq_make_eligible(struct qfq_sched *q)
* The index of the slot in which the input aggregate agg is to be
* inserted must not be higher than QFQ_MAX_SLOTS-2. There is a '-2'
* and not a '-1' because the start time of the group may be moved
- * backward by one slot after the aggregate has been inserted, and
- * this would cause non-empty slots to be right-shifted by one
- * position.
+ * backward after the aggregate has been inserted, and this would cause
+ * non-empty slots to be right-shifted. Backward rotation is separately
+ * bounded so that every occupied slot stays below QFQ_MAX_SLOTS.
*
* QFQ+ fully satisfies this bound to the slot index if the parameters
* of the classes are not changed dynamically, and if QFQ+ never
@@ -965,7 +965,8 @@ static struct qfq_aggregate *qfq_slot_scan(struct qfq_group *grp)
* because we use ffs() to find the first non-empty slot.
* This covers decreases in the group's start time, but what about
* increases of the start time ?
- * Here too we should make sure that i is less than 32
+ * The caller keeps every occupied slot below QFQ_MAX_SLOTS after the
+ * shift, preserving the one-to-one mapping between bits and bucket lists.
*/
static void qfq_slot_rotate(struct qfq_group *grp, u64 roundedS)
{
@@ -1300,7 +1301,8 @@ static int qfq_enqueue(struct sk_buff *skb, struct Qdisc *sch,
static void qfq_schedule_agg(struct qfq_sched *q, struct qfq_aggregate *agg)
{
struct qfq_group *grp = agg->grp;
- u64 roundedS;
+ u64 roundedS, slot;
+ unsigned int max_back;
int s;
roundedS = qfq_round_down(agg->S, grp->slot_shift);
@@ -1318,6 +1320,17 @@ static void qfq_schedule_agg(struct qfq_sched *q, struct qfq_aggregate *agg)
if (!qfq_gt(grp->S, agg->S))
goto skip_update;
+ slot = (grp->S - roundedS) >> grp->slot_shift;
+ max_back = QFQ_MAX_SLOTS - 1 - __fls(grp->full_slots);
+ if (unlikely(slot > max_back)) {
+ u64 deltaS = grp->S - roundedS -
+ ((u64)max_back << grp->slot_shift);
+
+ agg->S += deltaS;
+ agg->F += deltaS;
+ roundedS += deltaS;
+ }
+
/* create a slot for this agg->S */
qfq_slot_rotate(grp, roundedS);
/* group was surely ineligible, remove */
base-commit: 0d39bf81267861742b80d5f1c52e8a63e9ca0ca1
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-02 9:19 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 4:01 [PATCH v2 net] net/sched: sch_qfq: bound backward slot rotation Lin Jiapeng
2026-11-30 17:22 ` Paolo Abeni
2026-12-01 9:19 ` Jamal Hadi Salim
2026-12-01 9:22 ` Lin Jiapeng
2026-12-01 9:28 ` Jamal Hadi Salim
2026-12-01 21:24 ` Paolo Abeni
2026-12-02 9:18 ` [PATCH v3 " Lin Jiapeng
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.