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 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 03672C00A8F for ; Tue, 24 Oct 2023 02:41:39 +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:Date:To:Cc:From:Subject:References: In-Reply-To:MIME-Version:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5JU2B1iSNrVCFEP/eJ4QS+Obq/KKG0SOql0Lc70c61k=; b=KH3TK2ycBAzFWk 9vePCCi6X8JMkyNbgsYOxlsUyJpEaQ2i8qpVgonWnCBGE1203AnpmEQ5UVp1AFYz2y6xB8mVNMPeg SV1IrhXiLtwNm0FcOGmeKeEMbaHqWBrR+NM6VQ1/Ety6fzg9yST0nuquZI7WvcPntrAsDXdFG0msf j+4IatcTktn1LdQVObTZKc/6F0mc6brJnBl2m5JsqHpHY1xIZX77cCecLms7+++fyyIf9PmolYtEH W6DZ5HxFvx1At6x+ByyQlkb6odBBsMLvIFNsxvQiec4g4unIOR0DIMm8zDY/7jkfHwJ5lSaw+wg78 ia4qGKuJQ5RydOlxk9ag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qv7Lw-008fLd-20; Tue, 24 Oct 2023 02:41:08 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qv7Lp-008fLA-1v for linux-arm-kernel@lists.infradead.org; Tue, 24 Oct 2023 02:41:07 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 195B46292E; Tue, 24 Oct 2023 02:41:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAFB1C433C8; Tue, 24 Oct 2023 02:41:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698115260; bh=FWOFfug8FXGUj/9FvMiIQxHfXn4ZtTpUZJQqYJHKQ9I=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=Es6/Ztw5L3SOejtLMVVkw7+xqev3YoY70imuHxVvk+s/lcWmqBnFJDIrMayfWvalN SqlnoIxvFHrenuCeTGkgcTwlvj/J2TFQEM3EXtjFJag6zbC0pbd/VYd8yT5+t0bQgp ufSZDBt6BY9/Tx3q5m0v5gtIE7n4xd7CQrY5ePrl8NX8unQWHkNJ8UlFLvf7qc/Wws dquKF3gfEN6y/di9HpJkmCpH1du938WTHbk8lL9oDNufPBClf81yx66R0oRwcVixBV aex5NffKqf7/W7HJXe8m27M0HXadNqAZrsJtCPI2gSWHT/Cgpt/mmMMXV7Ev8dBiTh IudoaiMda+8oA== Message-ID: MIME-Version: 1.0 In-Reply-To: References: Subject: Re: [PATCH v2 2/2][next] clk: visconti: Add bounds-checking coverage for struct visconti_pll_provider From: Stephen Boyd Cc: Kees Cook , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Gustavo A. R. Silva , linux-hardening@vger.kernel.org To: Gustavo A. R. Silva , Michael Turquette , Nobuhiro Iwamatsu Date: Mon, 23 Oct 2023 19:40:58 -0700 User-Agent: alot/0.10 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231023_194101_678750_7994EC9C X-CRM114-Status: GOOD ( 14.66 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Quoting Gustavo A. R. Silva (2023-10-16 15:06:16) > In order to gain the bounds-checking coverage that __counted_by provides > to flexible-array members at run-time via CONFIG_UBSAN_BOUNDS (for array > indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions), > we must make sure that the counter member, in this particular case `num`, > is updated before the first access to the flex-array member, in this > particular case array `hws`. See below: > > commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") introduced `__counted_by` for `struct clk_hw_onecell_data` > together with changes to relocate some of assignments of counter `num` > before `hws` is accessed: > > include/linux/clk-provider.h: > 1380 struct clk_hw_onecell_data { > 1381 unsigned int num; > 1382 struct clk_hw *hws[] __counted_by(num); > 1383 }; > > However, this structure is used as a member in other structs, in this > case in `struct visconti_pll_provider`: > > drivers/clk/visconti/pll.h: > 16 struct visconti_pll_provider { > 17 void __iomem *reg_base; > 18 struct device_node *node; > 19 > 20 /* Must be last */ > 21 struct clk_hw_onecell_data clk_data; > 22 }; > > Hence, we need to move the assignments to `ctx->clk_data.num` after > allocation for `struct visconti_pll_provider` and before accessing the > flexible array `ctx->clk_data.hws`. And, as assignments for all members > in `struct visconti_pll_provider` are originally adjacent to each other, > relocate all assignments together, so we don't split up > `ctx->clk_data.hws = nr_plls` from the rest. :) > > Reviewed-by: Kees Cook > Acked-by: Nobuhiro Iwamatsu > Signed-off-by: Gustavo A. R. Silva > --- Applied to clk-next _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel