From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 217D42517AB; Tue, 29 Apr 2025 17:23:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745947387; cv=none; b=kB5AflusUTU8sSJdUytOzbCDvh+YuJY0WRgg5IjYIz0WghxPPdECQl+qTgHIoJ4hanvlundIbVTPR0DQQ7mMykiwBKi/wi3StpAu28Wq5K8rJudK4q4j5DexZajwB/k70qVWizsbZ2MlwY/mv6/RGg+pI5BKp1GJGBpU49qnejU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745947387; c=relaxed/simple; bh=81YrJq52pF9dTCpoFjuGyUQXQyHMwjlfPx1uuySK6aE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ieva36RMiP4Jv2pFDwU6ZXQtEmNRNP6CSSK0I8TiylSORMsxhK6QEqf3CQLMFeJjaqUc7cdyRvKjidh54/3wrjtg94AyE1RjetNa+317QK+dnYljYfaQoLDIIAmljwANS3DbmrX8stsjdoLQ/yK1gf304UJdUChqwiHUVDw3T8s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=rUSE5oS9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="rUSE5oS9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8600AC4CEE3; Tue, 29 Apr 2025 17:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745947387; bh=81YrJq52pF9dTCpoFjuGyUQXQyHMwjlfPx1uuySK6aE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rUSE5oS9zbK1X2xx6VVFhEXBVT16qyER+abv7EX0eR7vu7X2lamHR5oAVf9V90n2K 2Rys4+Z+ZNwE6RguNCcHEmBV9ehlf8L52teEpAXh4hSOl+OhU7f3BQ8MK0peNPet1F BZTDOntHbxswJy3kvHsS/+T87icEfQnkWWkDb1no= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Gerrard Tai , Konstantin Khlebnikov , Cong Wang , Jamal Hadi Salim , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 234/286] net_sched: hfsc: Fix a UAF vulnerability in class handling Date: Tue, 29 Apr 2025 18:42:18 +0200 Message-ID: <20250429161117.556010063@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429161107.848008295@linuxfoundation.org> References: <20250429161107.848008295@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cong Wang [ Upstream commit 3df275ef0a6ae181e8428a6589ef5d5231e58b5c ] This patch fixes a Use-After-Free vulnerability in the HFSC qdisc class handling. The issue occurs due to a time-of-check/time-of-use condition in hfsc_change_class() when working with certain child qdiscs like netem or codel. The vulnerability works as follows: 1. hfsc_change_class() checks if a class has packets (q.qlen != 0) 2. It then calls qdisc_peek_len(), which for certain qdiscs (e.g., codel, netem) might drop packets and empty the queue 3. The code continues assuming the queue is still non-empty, adding the class to vttree 4. This breaks HFSC scheduler assumptions that only non-empty classes are in vttree 5. Later, when the class is destroyed, this can lead to a Use-After-Free The fix adds a second queue length check after qdisc_peek_len() to verify the queue wasn't emptied. Fixes: 21f4d5cc25ec ("net_sched/hfsc: fix curve activation in hfsc_change_class()") Reported-by: Gerrard Tai Reviewed-by: Konstantin Khlebnikov Signed-off-by: Cong Wang Reviewed-by: Jamal Hadi Salim Link: https://patch.msgid.link/20250417184732.943057-2-xiyou.wangcong@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/sched/sch_hfsc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/sched/sch_hfsc.c b/net/sched/sch_hfsc.c index adcf87d417ae4..ed8211c8d1f4c 100644 --- a/net/sched/sch_hfsc.c +++ b/net/sched/sch_hfsc.c @@ -959,6 +959,7 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid, if (cl != NULL) { int old_flags; + int len = 0; if (parentid) { if (cl->cl_parent && @@ -989,9 +990,13 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid, if (usc != NULL) hfsc_change_usc(cl, usc, cur_time); + if (cl->qdisc->q.qlen != 0) + len = qdisc_peek_len(cl->qdisc); + /* Check queue length again since some qdisc implementations + * (e.g., netem/codel) might empty the queue during the peek + * operation. + */ if (cl->qdisc->q.qlen != 0) { - int len = qdisc_peek_len(cl->qdisc); - if (cl->cl_flags & HFSC_RSC) { if (old_flags & HFSC_RSC) update_ed(cl, len); -- 2.39.5