From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1E914119EA for ; Fri, 31 Jul 2026 14:05:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785506737; cv=none; b=mG86vlyZ0psr2buhYcWgtmu7pcQ+XI0ZqCTFlwV4RM+DAwKqIXlDiFAVtYj5H+3NsLFmh0q93fq3z64nnJxNIo51I35ODOEFUiUIJmPq7oP1HFu6sn9g4AwAV2kjhihaHfDSDvP4Pu0U2LVgX2JX3PW6fDn6C3RkWkazbJfaA0I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785506737; c=relaxed/simple; bh=WFThtS01zuWi9Z/ZY42l8xKEAvRkhPojWTIq0tlSJtU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=oxygFjYSxKMGWRcIB9XnbPTsO3O+CDS7CbitUzh03W22rlkdyxw5jopfOoK9OofJlROkMHxvIVr/O4npFvtqZiegunqcP1hpCJD5LNdWKll8XOVIoxeEBl91tIFkkT3UiyTcUT260yW5q1TSalzwKguDPX0SpKC4Jj9Q1uhwctg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b=TX6n7CEZ; arc=none smtp.client-ip=209.85.222.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b="TX6n7CEZ" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-92e85499ffbso80412885a.0 for ; Fri, 31 Jul 2026 07:05:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1785506735; x=1786111535; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=76hei+yKv+rozwlkxCZSaL8AFRKjftE/3gkCFmdDrGk=; b=TX6n7CEZy+PioxHxRxOtkeX4I9pT8UOtYDTX9DP2ReV4WPwWtqQmvvDuSycbvKfS8o 2JvRvbrpmiz+Go83gdSQEZ58TsV5t1QL9k5eY2YJkBFiNaomvesgOh/as5MXiv0UxeSv ZCJSMCo9zVsUOKV5oJVVoGtSIWk6QV5/n17/kOd9oqkltupK50T0ND8AO3GoFVQjQtLb MtAHP0DpU6yRuax9+lUx01xrPIIDf0GhQjZojXz79gqr576PmUx445FqXlV5EVWRFYJA C0lwb5+Kb4mnqMn4W15c9OyKoHAc+h+5Zl7ibcXidm671K16TzxgJB23PtJIYLI2sLhh xOSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785506735; x=1786111535; h=content-transfer-encoding:mime-version: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=76hei+yKv+rozwlkxCZSaL8AFRKjftE/3gkCFmdDrGk=; b=hneTIoW0JJJ0psaOaA5z3mPVf/xybTfcb1QIyNOvaXeHMSfp1GHK5SqOp/Pllg/AGs TmA3R7ks483PGzVfX0hjnGmYgQFrJc/jIcigteKX4EorRxVEVNaUkI6a5HdDPAjn883g ShPKBHylBRegQEsfO/UBKY5qCETKP5jmY0VsHrTsQQ1Juv2n/CZ90hu8gYCIwpRuMBx5 6VupQcxakYqIdyMuJeoewXIyviZNov6G8YsM+9OkgUEXv9xGR891FGrmu4Hoxw1MoC+/ X6h8uTGbDJXxUFTOuW7SotZYC7FeDZuaCrJNf5SgyK00e3P72rpeaNDhgwSLnLnB2h/1 9GlA== X-Forwarded-Encrypted: i=1; AHgh+RrHCmYOu8VrNhud7kmpVrk9q2SNZqx/UUqcDmCs2z1j4OPbZMX+a8hIV+PNTwDhkzDs+5hFt9i2dgH2Lyg=@vger.kernel.org X-Gm-Message-State: AOJu0YxYtI9TsLOvFo8trYuwmsxEoMUN1K/rVD3wI2WrOpq1piLUSiW/ gAyjqxShZ+cQnFzPP6IjhbsUeHDvULYlwqCweqA6PD/7UzNvM2atPR2Tiju/LV6o9YY= X-Gm-Gg: AR+sD10h/Wo5TcYCf05jvOrxkhhLyDFjlz6d1DC/ZP8Yu4x7TsitRCkOx/CpY49zMQt eakuJrVzrD8Wr0JyJMqz9ucXBCY0aMTLgFCMcgju8Q46a/7MoCbPony33Jnt/Z9YHFNwfQ23T4j HC9EW8xyxKrCg4nzZGrbZ45Lx+p1DtTG/ewgnn8tpiIW+2Tnt2DyMfh6xjW/uUruZu5l284fFED e8zDbk6cHXkk/cgRu9+DZNbmuao2piC1ulbSFGuaQm6BxLqh1bvWjzLDK09BQ4lHiWTYYhFUx88 1LdDnvCgLakX/0AOk5ivKVsrkGMb8b5vTp0v71/FiTU4JaVRLT5ByNWjmV49aDcrMWcnSMXJ34Z BgDm5Ckdnk0bIHMhyZnqb+nSTf9sVfdwYA9wgniNAjiwuNJIy3r/c6M2BfhZFXeqlpoDZ2MgEPy yAnGu3rIpH4oyZQne09t1UJrk8zk5D8JIJacTCJI2Ey0lJtsJNJ8EPIwJIOOln+it2OA== X-Received: by 2002:a05:620a:4154:b0:92b:641f:ea5e with SMTP id af79cd13be357-934a0581ac2mr21594885a.0.1785506734705; Fri, 31 Jul 2026 07:05:34 -0700 (PDT) Received: from localhost ([146.190.222.192]) by smtp.gmail.com with UTF8SMTPSA id af79cd13be357-9349bc2653asm62043085a.4.2026.07.31.07.05.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 31 Jul 2026 07:05:34 -0700 (PDT) From: David Lee To: jhs@mojatatu.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: David Lee , Kyle Zeng , Dominik 'Disconnect3d' Czarnota , horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] net/sched: sch_qfq: prevent aggregate self-replacement Date: Fri, 31 Jul 2026 14:05:32 +0000 Message-ID: <20260731140533.566493-1-david.lee@trailofbits.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit qfq_change_class() snapshots the current aggregate settings while holding the qdisc tree lock, but drops the lock before selecting the destination aggregate. During that gap, qfq_enqueue() can move the class to an aggregate matching the requested settings. When qfq_change_class() resumes, qfq_find_agg() then returns cl->agg. If it is a singleton, qfq_deact_rm_from_agg() frees the aggregate before qfq_add_to_agg() immediately accesses the same pointer, causing a use-after-free. While holding the tree lock, skip the replacement when the destination is already the current aggregate. Any estimator replacement has already completed, so the class change can finish normally. Fixes: 462dbc9101ac ("pkt_sched: QFQ Plus: fair-queueing service at DRR cost") Bug found and triaged by OpenAI Security Research and validated by Trail of Bits. Assisted-by: Codex:gpt-5.6-sol gpt-5.5-cyber Signed-off-by: Kyle Zeng --- Trail of Bits has a reproducer for this bug that triggers a KASAN use-after-free and can share if needed. net/sched/sch_qfq.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/sched/sch_qfq.c b/net/sched/sch_qfq.c index 6f3b7273c..e900890e9 100644 --- a/net/sched/sch_qfq.c +++ b/net/sched/sch_qfq.c @@ -517,11 +517,14 @@ static int qfq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, sch_tree_lock(sch); qfq_init_agg(q, new_agg, lmax, weight); } + if (existing && new_agg == cl->agg) + goto unlock; if (existing) qfq_deact_rm_from_agg(q, cl); else qdisc_class_hash_insert(&q->clhash, &cl->common); qfq_add_to_agg(q, new_agg, cl); +unlock: sch_tree_unlock(sch); qdisc_class_hash_grow(sch, &q->clhash); -- 2.53.0