From: Lin Jiapeng <ljp1205831794@gmail.com>
To: jhs@mojatatu.com, jiri@resnulli.us, davem@davemloft.net,
edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, paolo.valente@unimore.it,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Lin Jiapeng <jiapenglin@tencent.com>,
TencentOS Corvus AI <corvus@tencent.com>
Subject: [PATCH net] net/sched: sch_qfq: bound backward slot rotation
Date: Mon, 16 Nov 2026 20:17:07 +0800 [thread overview]
Message-ID: <20261116121710.77403-1-ljp1205831794@gmail.com> (raw)
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 start-time decrease larger than the bitmap
can represent. Rotating then pushes existing members beyond full_slots,
and a later qfq_slot_remove() clears a bit in the following slot-list
pointers. KASAN reports the resulting corruption when the group is
selected:
BUG: KASAN: slab-use-after-free in qfq_choose_next_agg+0xd04/0xd90
Read of size 8 at addr ff11000102f73010 by task repro/92
CPU: 0 UID: 1000 PID: 92 Comm: repro
Call Trace:
kasan_report+0xe4/0x1a0
qfq_choose_next_agg+0xd04/0xd90
qfq_dequeue+0x365/0x14b0
qdisc_peek_dequeued+0x91/0x280
tbf_dequeue+0x91/0xcd0
Allocated by task 91:
qfq_change_class+0xca5/0x1c50
tc_ctl_tclass+0x4ee/0x1400
Freed by task 37:
kfree+0x1b3/0x550
qfq_rm_from_agg+0x228/0x300
qfq_destroy_qdisc+0x118/0x1e0
The buggy address belongs to the object at ff11000102f73000,
which belongs to the cache kmalloc-128 of size 128.
The buggy address is located 16 bytes inside of
freed 128-byte region [ff11000102f73000, ff11000102f73080)
The report is followed by a kernel panic.
Limit the backward adjustment according to BITS_PER_LONG and the
largest insertion slot. If it 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 the timestamp and physical-slot
mapping, keeps every removal offset inside full_slots, and leaves
representable rotations unchanged.
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>
---
net/sched/sch_qfq.c | 13 +++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/net/sched/sch_qfq.c b/net/sched/sch_qfq.c
index e900890e9c54..e83105ce9015 100644
--- a/net/sched/sch_qfq.c
+++ b/net/sched/sch_qfq.c
@@ -1300,7 +1300,7 @@ 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;
int s;
roundedS = qfq_round_down(agg->S, grp->slot_shift);
@@ -1318,6 +1318,17 @@ static int qfq_enqueue(struct sk_buff *skb, struct Qdisc *sch,
if (!qfq_gt(grp->S, agg->S))
goto skip_update;
+ slot = (grp->S - roundedS) >> grp->slot_shift;
+ if (unlikely(slot > BITS_PER_LONG - QFQ_MAX_SLOTS + 1)) {
+ u64 deltaS = grp->S - roundedS -
+ ((u64)(BITS_PER_LONG - QFQ_MAX_SLOTS + 1) <<
+ 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 */
--
2.55.0
reply other threads:[~2026-11-16 12:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261116121710.77403-1-ljp1205831794@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®