From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796203147; b=v3skCtrCbwGwd9cvY4hkalcl/u8iep02J4cQJeRI3esWiTbiFwPb4m4hZ0vbOwF4RCYs tinXB9c9L3SiGkpmPIoQ/p3VyqRe1/XbAjGmhnZc8/S2+nc3uFz+lTB1aWB8/y12a3qIN +/YeNou9oTR+yxsGU4RH8xJxrzE/KCU2bzi6YRnYlPKoRGVmqUvLjYKHr7mPdCxMGWZ88 R6ckbc26e1VH3aAn7+5dmAQ+AxvTzWWLu9OFNtkTtJrWW7/Nx6qkYw4ptWQAP77blquo5 uLHttQ+ZESt1CBkyLM0mU+SxE1+N1nBcr2OumZbQLmt8c+pg/1o8SH4azLcCnOugA8A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796203147; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=TXL1CV6i6FBIxTHV05R+/UiWlxQIqELWZjk92riLUuw=; b=sTDozfykXobIPBn7deovKfFaceID40bqQlOYZHY2E6zkKgrh3i7I04hi60Nhwa4Zr1F1 XWYEKbOtl1a2hrLjy7AOdBsEktCw+VnvULDaqHXnc+qs0+kX5bPsIRmsAgz1O03hVBFcC Y8caLopM3vp1r99R95bMHragCwzQnQcJb0SAVAgWrQQC4f3xyJNjdxkIXrOAUljNozONi Zkea7dY7qbP/WqeEhM778pslGgoEL4Xa3igQEfY9jlPIe7z6400ogpIsfp9Ut/KePLDeh BMxJKMuVxthynjLLoMcueyYTUV59EiMOTMYgClsGORbMgWJZ9bMdbsc89kE2GBMSA4A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yVCmAc7G; arc=none smtp.remote-ip=209.85.215.180 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6E4F606A31A for ; Wed, 2 Dec 2026 09:19:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C6E4F606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yVCmAc7G Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-cdb9f760337so6876613a12.0 for ; Wed, 02 Dec 2026 01:19:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796203146; x=1796807946; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=TXL1CV6i6FBIxTHV05R+/UiWlxQIqELWZjk92riLUuw=; b=yVCmAc7GegnJfUdoGeup6zAXGcEH9tLURW50SirMT2UyWdxCS/XG/XT7RVKdHGaCs8 gk9rEoG27v9B4W+zahpDsy+/xQULOMSya6P3FO04lI9V5WopS7oyFtHpz4PgT8mZlOZi VMPG4TFGpdRnrMIjYanDzRH4ZguHTBmIdLKYsWWIFOTY/CyxVu2m3FexrOeJP3dwQ9d1 YpVbyUbt4GYHeUJyjbFQq2ChqJMRE2GSuBlPf7QsCyfZBLY1o08yoj4+ryPXKQJPMkZI tIqOrER+PkWLF2adMWGw+D+fEB3ur1TsjivPpkS2wKQ9h1VgwvTy5/l2VJm6Fd5JeNOd W4TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796203146; x=1796807946; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=TXL1CV6i6FBIxTHV05R+/UiWlxQIqELWZjk92riLUuw=; b=03MK2ezum6kZVKIZlj4Y8ORqT2FnNGekMP30RkUs9Jbx4+ZBRBGsF5KywrDtiZws7s dOK+CgPfpOE7d2O4+3bxDsliIK4KkPaBy1ltD0mpbTXYhC5pF3rOquTZgkaqosJJmmf6 MjFHwwG1G9egrTbpTEnKU7jV27rbqbGsb8v2XJfWhifutfTxj/foO+Va2k+uPLInC3qq DbJ6oY6FwkSiv/CHaP0LL1Kaz2Ii1svqElfijzh09a7QxhJLwRDFccEauuazuZdlt0hg ubJIH+y8VG6THWOgg65RRUArZSLQcZdXDGMo8sG56RiLlz4CiiTBNJvTRnaZns9vPsxv l4iQ== X-Forwarded-Encrypted: i=1; AL+hErEM+fEQSU+qaenpIdiFaCx23n0lbistll4ObwiPSkgD3yQSpTU+PKQnKC7cXMSLSAQST/pCZDU=@vger.kernel.org X-Gm-Message-State: APuU4Z8ZrBPfAvvuQqzPsTjbLj5JWo+5zdlHBRjFjrzNR6jGAaRktWOV GlH1XAggmA7qdutQCJ9HwvjdJbMDXgXemklBie6Bt1JcbXqdrom9yxME X-Gm-Gg: AZFdTZfacMntFEhDWdRI9w8rgT4JUlW0U11GCV7YFwCzofHl3atGb6veKTsOhty8OSC 0vVO67pcJ8vuFIsS4NkxyZfiKJ/8Vx8cvGaKYRd8tEuz4mzhfhUrr71U02XXp+2cDlkwOlZ71P7 TnnL7uUtx6m+417ge+vCfx97cZyKEFd/S+mMEKJaHnbv9uzyguOD0gbsgMsA0B4GDJ5Fne7PPd1 OE++BVxJMGho8yaCT/l07fh3Fh0D4WFGCbPd9DguTihDFefQLlkmHcGbxh14XyCrDXObOQjWbDc wr56grB6xfCrFWZn/2ZdBR1aWWQhbMxdtOBCI5dhj9lUUTgOQAhd8kcmopKxcXDjoNgvL7Ciuhg Nr4VoA8vjcf9RJnFTE3jGw5OKG/ZTWDr8vjCO31hcSKnYCfO6OomHBibT0gUwuRP+6n2e8gknf1 hyL78hXwJAFtixSvZ20cJV3FOkWAtn5c13MUszkIOlwYCZu9rwKbQ7YgGabdmfBnySxszppWkRA 6wMnFUi7AlhdCts5goczTZsg5zXkTmX3iZziq4bFyziCZIGm0Gv3hE75Y99wLnF89bW2uJ/93vA txnjheu1Sk4L24oC6GMNfI3gdIXAMfNjDQdl0f1t16kZQH4P8+XsKAw5dr0Jfrn/0DwqsA3Zug= = X-Received: by 2002:a17:90b:1cc7:b0:3b5:8f72:e476 with SMTP id 98e67ed59e1d1-3b58f72ef79mr5423429a91.15.1796203145791; Wed, 02 Dec 2026 01:19:05 -0800 (PST) Received: from JIAPENGLIN-MC0.tencent.com ([43.132.141.25]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5b59f520bsm2555777a91.15.2026.12.02.01.19.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 02 Dec 2026 01:19:05 -0800 (PST) From: Lin Jiapeng To: jhs@mojatatu.com, jiri@resnulli.us, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, horms@kernel.org, paolo.valente@unimore.it, netdev@vger.kernel.org Cc: Lin Jiapeng , TencentOS Corvus AI Subject: [PATCH v3 net] net/sched: sch_qfq: bound backward slot rotation Date: Wed, 2 Dec 2026 17:18:43 +0800 Message-ID: <20261202091853.78490-1-ljp1205831794@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261124040208.13282-1-ljp1205831794@gmail.com> References: <20261124040208.13282-1-ljp1205831794@gmail.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Lin Jiapeng 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 Signed-off-by: Lin Jiapeng --- 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