mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lin Jiapeng <ljp1205831794@gmail.com>
To: Paolo Abeni <pabeni@redhat.com>,
	jhs@mojatatu.com, jiri@resnulli.us, netdev@vger.kernel.org
Cc: Lin Jiapeng <jiapenglin@tencent.com>,
	TencentOS Corvus AI <corvus@tencent.com>,
	kuba@kernel.org, davem@davemloft.net, edumazet@kernel.org,
	paolo.valente@unimore.it, linux-kernel@vger.kernel.org,
	horms@kernel.org
Subject: Re: [PATCH v2 net] net/sched: sch_qfq: bound backward slot rotation
Date: Tue, 1 Dec 2026 17:22:32 +0800	[thread overview]
Message-ID: <143b8cc0-44c4-4a93-b936-a66677c1a0bd@gmail.com> (raw)
In-Reply-To: <7ecbb59e-d985-4b75-9240-ce83bcd87175@redhat.com>



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.


  parent reply	other threads:[~2026-12-01  9:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  4:01 Lin Jiapeng
2026-11-30 17:22 ` Paolo Abeni
2026-12-01  9:19   ` Jamal Hadi Salim
2026-12-01  9:22   ` Lin Jiapeng [this message]
2026-12-01  9:28     ` Jamal Hadi Salim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=143b8cc0-44c4-4a93-b936-a66677c1a0bd@gmail.com \
    --to=ljp1205831794@gmail.com \
    --cc=corvus@tencent.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jhs@mojatatu.com \
    --cc=jiapenglin@tencent.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=paolo.valente@unimore.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®