From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5282CC636D4 for ; Thu, 9 Feb 2023 11:23:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230416AbjBILW7 (ORCPT ); Thu, 9 Feb 2023 06:22:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231189AbjBILWH (ORCPT ); Thu, 9 Feb 2023 06:22:07 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B4A766FB9; Thu, 9 Feb 2023 03:18:24 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E2718B82076; Thu, 9 Feb 2023 11:18:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5359DC4339C; Thu, 9 Feb 2023 11:18:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675941501; bh=R7kTku5brZXv/qMfyPkboEF/c6xphWbY4jAq2WK5a2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FUEvZszQyNtFTfDPkGv1bYFkGn3ihixUt09/k1ngLb31oK/r2XsrtNdV5n4uGMX8n uz8X8RHTbn0FwymFqMfvIC8fg5jnHAI5kvbTtK4PSxX0IzI/sV3n29eORKP2tpqd6P YBdM3G/QdHpgAA0piLnePQnyk9Rqq57nd3VhUPvmlh6JREH3fc0zZdpDH+06mbnXA4 WhS/7MnltBy6yH34HsMTM4AOV7KLnaeimR90j+acgQilcnFkKcrHWJianbYAWjTfzK UDppuAeaJPIawYpsuZWkz+td7RqclG3DgNxqwyNv8tKpp5DD+U8f8FmmpIVsZ4fTXO RoHekp6EaFXAQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kees Cook , Jamal Hadi Salim , Cong Wang , Jiri Pirko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, Simon Horman , Cong Wang , Sasha Levin Subject: [PATCH AUTOSEL 5.15 13/17] net: sched: sch: Bounds check priority Date: Thu, 9 Feb 2023 06:17:25 -0500 Message-Id: <20230209111731.1892569-13-sashal@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230209111731.1892569-1-sashal@kernel.org> References: <20230209111731.1892569-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Kees Cook [ Upstream commit de5ca4c3852f896cacac2bf259597aab5e17d9e3 ] Nothing was explicitly bounds checking the priority index used to access clpriop[]. WARN and bail out early if it's pathological. Seen with GCC 13: ../net/sched/sch_htb.c: In function 'htb_activate_prios': ../net/sched/sch_htb.c:437:44: warning: array subscript [0, 31] is outside array bounds of 'struct htb_prio[8]' [-Warray-bounds=] 437 | if (p->inner.clprio[prio].feed.rb_node) | ~~~~~~~~~~~~~~~^~~~~~ ../net/sched/sch_htb.c:131:41: note: while referencing 'clprio' 131 | struct htb_prio clprio[TC_HTB_NUMPRIO]; | ^~~~~~ Cc: Jamal Hadi Salim Cc: Cong Wang Cc: Jiri Pirko Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: netdev@vger.kernel.org Signed-off-by: Kees Cook Reviewed-by: Simon Horman Reviewed-by: Cong Wang Link: https://lore.kernel.org/r/20230127224036.never.561-kees@kernel.org Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- net/sched/sch_htb.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c index 45b92e40082ef..7ea8c73ddeff0 100644 --- a/net/sched/sch_htb.c +++ b/net/sched/sch_htb.c @@ -427,7 +427,10 @@ static void htb_activate_prios(struct htb_sched *q, struct htb_class *cl) while (cl->cmode == HTB_MAY_BORROW && p && mask) { m = mask; while (m) { - int prio = ffz(~m); + unsigned int prio = ffz(~m); + + if (WARN_ON_ONCE(prio > ARRAY_SIZE(p->inner.clprio))) + break; m &= ~(1 << prio); if (p->inner.clprio[prio].feed.rb_node) -- 2.39.0