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 869C6CE7A88 for ; Sat, 23 Sep 2023 09:03:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231304AbjIWJDg (ORCPT ); Sat, 23 Sep 2023 05:03:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231293AbjIWJDV (ORCPT ); Sat, 23 Sep 2023 05:03:21 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5072010E4 for ; Sat, 23 Sep 2023 02:02:33 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13FF1C433C9; Sat, 23 Sep 2023 09:02:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695459752; bh=wLwMXei8xd94rYvt7YUim5VACHPexOivfcfPG9ycbrU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LoyfEevdTufTER9i9/vR0DfAxebgy1i7TrhkUjNg7Uhj7jBCVslA2eZQyQ/5oSLZz e8f6FEnawP5K5+2t8+8Bq8SUdyUdqnBG6cqrtXyySTjB6CR/e3j1XExEmYP9N+H7Wj mYKHXOvkuUGhhHdwGgVxj5cg5/D3cvh1bNlvW33HEKYUUhSbV5GSma1//ssmSCoTa+ b8o78Hdmhtf0gWxK9rQqj0NKCq7Exs5gfpiz6UztwVPDjOUtLCQAyEn9mhmTyFd29w 867MxfZNdFmTNL0FOkQt3qi6S+wVDuMM+H9r+ob4JIQV6QPJMP1xpeb1rMG3PuWgfs amKtglvvbUdpQ== Date: Sat, 23 Sep 2023 11:03:28 -0600 From: "Gustavo A. R. Silva" To: Kees Cook Cc: Liam Girdwood , Mark Brown , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Subject: Re: [PATCH] regulator: mc13xxx: Annotate struct mc13xxx_regulator_priv with __counted_by Message-ID: References: <20230922175402.work.819-kees@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230922175402.work.819-kees@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 22, 2023 at 10:54:02AM -0700, Kees Cook wrote: > Prepare for the coming implementation by GCC and Clang of the __counted_by > attribute. Flexible array members annotated with __counted_by can have > their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS > (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family > functions). > > As found with Coccinelle[1], add __counted_by for struct mc13xxx_regulator_priv. > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci > > Cc: Liam Girdwood > Cc: Mark Brown > Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Thanks -- Gustavo > --- > drivers/regulator/mc13xxx.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/regulator/mc13xxx.h b/drivers/regulator/mc13xxx.h > index e03279dc43f4..057aaef6f086 100644 > --- a/drivers/regulator/mc13xxx.h > +++ b/drivers/regulator/mc13xxx.h > @@ -24,7 +24,7 @@ struct mc13xxx_regulator_priv { > u32 powermisc_pwgt_state; > struct mc13xxx_regulator *mc13xxx_regulators; > int num_regulators; > - struct regulator_dev *regulators[]; > + struct regulator_dev *regulators[] __counted_by(num_regulators); > }; > > extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, > -- > 2.34.1 > >