From patchwork Thu Apr 25 16:55:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 13643566 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 971E9C10F15 for ; Thu, 25 Apr 2024 16:56:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KmsWQGyeEp9mFwRKXvWy3gd1v8Bs+YWLUpPWnTYWoZ4=; b=U76+iLKUzeRMpT KlSAXizRuIQKdI9CmSj3rYEwS82c/jgZb8zJvjQt5zVDlFvpkW7wiwLeuzAFds+L3X4pSUFbgaTRf 3j4AXVx2EMo2uxvo1F1/FbW3pJOMOxUJglDIijTTVD9Zn8+pxmRz5tgJAb7ySUu78CXJOh1Fa6N4c XyDD0TzsVrGS5lmUDpQ6+Kj/hWcfjMHJRJ5xWMNm3r+dM+EOUA5u0iXJ+0wiVcKUfjqqgM9lf7A1S LyG0bNRFN0XnspeJh8GzjGyjetMgtAvt8GUbcSJaVle6aEs7dcWsIHpzGTg5KVnUhfeuTlCKQCLGL WmPLWGq/v7T/0SXzUwkA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s02Ol-00000009TEn-2lyc; Thu, 25 Apr 2024 16:56:39 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s02OY-00000009T6J-1wM6; Thu, 25 Apr 2024 16:56:28 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id A80FACE14A3; Thu, 25 Apr 2024 16:56:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86EC4C4AF0D; Thu, 25 Apr 2024 16:56:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714064184; bh=xOZM1ewaEE8webcrxae6fRZ3lapbeFGOs6WCFr8o9mU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=aBmRapsv6IaKBvdiQYhwCmEf62JM5xoaIdiZiuzQMg+cDdNZ5fUPBS0dvn02e3av9 zI2nOSy20qcJz3Vvu6so2xEacDjHl5ORFeYDK8ApeaQwQJkHbbQ8Bf4QDslxjjJv+Y oLDNM5DU10WXbvFj1NVqBfIxdsS7RjR25TBTrRN5h7Avx0QCbfSFuzbilZlZ3xr82q y13aputd6YFD4hjuFFtnmMn9BNWvTaMgZ6K+Y/I/ZlpdYlOhKVjAewRdxcu/yBXU+9 O2Ga2ovz2u7oU/CviciWQV/ZmGoZ6mwAqQnM6aHY3q94S0XD0Gwv4eKiMzUYVsLSgB c1kRGKIZXJn/Q== From: Nathan Chancellor Date: Thu, 25 Apr 2024 09:55:52 -0700 Subject: [PATCH 2/2] clk: bcm: rpi: Assign ->num before accessing ->hws MIME-Version: 1.0 Message-Id: <20240425-cbl-bcm-assign-counted-by-val-before-access-v1-2-e2db3b82d5ef@kernel.org> References: <20240425-cbl-bcm-assign-counted-by-val-before-access-v1-0-e2db3b82d5ef@kernel.org> In-Reply-To: <20240425-cbl-bcm-assign-counted-by-val-before-access-v1-0-e2db3b82d5ef@kernel.org> To: Michael Turquette , Stephen Boyd , Florian Fainelli Cc: Kees Cook , "Gustavo A. R. Silva" , bcm-kernel-feedback-list@broadcom.com, linux-clk@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-hardening@vger.kernel.org, patches@lists.linux.dev, llvm@lists.linux.dev, stable@vger.kernel.org, Nathan Chancellor X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1678; i=nathan@kernel.org; h=from:subject:message-id; bh=xOZM1ewaEE8webcrxae6fRZ3lapbeFGOs6WCFr8o9mU=; b=owGbwMvMwCUmm602sfCA1DTG02pJDGla3abTn9y8tqDHMf/Qn/N85dnXVnov523rf7SlcaFbR 2b1jttqHaUsDGJcDLJiiizVj1WPGxrOOct449QkmDmsTCBDGLg4BWAiPKUM/1MLZtRPneq48r76 vu2NLyLVtxv1zLwQaPcvwZZv+ulgOV1GhgXn/XQKJgfuK7uWwHxp29VlqtZzb4XqTdmabG4lH3B DkwMA X-Developer-Key: i=nathan@kernel.org; a=openpgp; fpr=2437CB76E544CB6AB3D9DFD399739260CB6CB716 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240425_095627_104770_C333AB17 X-CRM114-Status: GOOD ( 12.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' with __counted_by, which informs the bounds sanitizer about the number of elements in hws, so that it can warn when hws is accessed out of bounds. As noted in that change, the __counted_by member must be initialized with the number of elements before the first array access happens, otherwise there will be a warning from each access prior to the initialization because the number of elements is zero. This occurs in raspberrypi_discover_clocks() due to ->num being assigned after ->hws has been accessed: UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-raspberrypi.c:374:4 index 3 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') Move the ->num initialization to before the first access of ->hws, which clears up the warning. Cc: stable@vger.kernel.org Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") Signed-off-by: Nathan Chancellor Reviewed-by: Kees Cook Reviewed-by: Florian Fainelli --- drivers/clk/bcm/clk-raspberrypi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c index 829406dc44a2..4d411408e4af 100644 --- a/drivers/clk/bcm/clk-raspberrypi.c +++ b/drivers/clk/bcm/clk-raspberrypi.c @@ -371,8 +371,8 @@ static int raspberrypi_discover_clocks(struct raspberrypi_clk *rpi, if (IS_ERR(hw)) return PTR_ERR(hw); - data->hws[clks->id] = hw; data->num = clks->id + 1; + data->hws[clks->id] = hw; } clks++;