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 81EEAC71133 for ; Fri, 18 Aug 2023 01:32:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354947AbjHRBb2 (ORCPT ); Thu, 17 Aug 2023 21:31:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357077AbjHRBa7 (ORCPT ); Thu, 17 Aug 2023 21:30:59 -0400 Received: from omta34.uswest2.a.cloudfilter.net (omta34.uswest2.a.cloudfilter.net [35.89.44.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F2242713 for ; Thu, 17 Aug 2023 18:30:57 -0700 (PDT) Received: from eig-obgw-5006a.ext.cloudfilter.net ([10.0.29.179]) by cmsmtp with ESMTP id WcMGqvqB1faVXWoEgqSN1H; Fri, 18 Aug 2023 01:25:10 +0000 Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with ESMTPS id WoEfq6oJDHSofWoEfq04mk; Fri, 18 Aug 2023 01:25:09 +0000 X-Authority-Analysis: v=2.4 cv=HbEH8wI8 c=1 sm=1 tr=0 ts=64dec875 a=1YbLdUo/zbTtOZ3uB5T3HA==:117 a=WzbPXH4gqzPVN0x6HrNMNA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=UttIx32zK-AA:10 a=wYkD_t78qR0A:10 a=NEAV23lmAAAA:8 a=VwQbUJbxAAAA:8 a=pGLkceISAAAA:8 a=8b9GpE9nAAAA:8 a=phlkwaE_AAAA:8 a=JfrnYn6hAAAA:8 a=cm27Pg_UAAAA:8 a=-bvcuBnrpKmIfEhu9ToA:9 a=QEXdDO2ut3YA:10 a=AjGcO6oz07-iQ99wixmX:22 a=T3LWEMljR5ZiDmsYVIUa:22 a=uKTQOUHymn4LaG7oTSIC:22 a=1CNFftbPRP8L7MoqJWF3:22 a=xmb-EsYY8bH0VWELuYED:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=f7nwE/qFZmVusLxJv+zoA/66vZW2NKiHaJWx4yhC0cI=; b=r/Wwa+KHDaHY8bcPNx4aFUQCFt RYaJEsoP3Pmk9Eb9/3iwlUGKrZ5FKHCX9QX11bl8DgIpseEh4WH6xGh4GW3UfezUe/v8VgjKGCz8e k06oSbj1xGoOgACMCmLcyLJHM+8AXI/z6otTqA661jPfjCiinzi4mFUgvLBzUxscCFS80GSgmEIW1 hmRCIMgr24h+WOJnLwPOG5feE4dHRc0pxMHTWUSBbDmkdFgTrpjYd9YD753SxvOALk8P8h2hIgtMt G4OrHF8nLaEx5rU54CFQdgcHXAjgkmQau/rjBjgv93vQF1RAUk0GaGgXQJ1C7Sm4FKVu0o5N28xh7 GaCSs5vw==; Received: from 187-162-21-192.static.axtel.net ([187.162.21.192]:52924 helo=[192.168.15.8]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1qWoEa-000Y5s-00; Thu, 17 Aug 2023 20:25:04 -0500 Message-ID: <1f6873bb-e6d3-fdff-5e20-72332469def2@embeddedor.com> Date: Thu, 17 Aug 2023 19:26:02 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH 14/21] dmaengine: stm32-mdma: Annotate struct stm32_mdma_device with __counted_by Content-Language: en-US To: Kees Cook , Vinod Koul Cc: Maxime Coquelin , Alexandre Torgue , dmaengine@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, Hector Martin , Sven Peter , Alyssa Rosenzweig , Ludovic Desroches , Tudor Ambarus , Lars-Peter Clausen , Zhou Wang , Jie Hai , Andy Gross , Bjorn Andersson , Konrad Dybcio , Green Wan , Orson Zhai , Baolin Wang , Chunyan Zhang , Patrice Chotard , Laxman Dewangan , Jon Hunter , Thierry Reding , Peter Ujfalusi , Kunihiko Hayashi , Masami Hiramatsu , Yu Kuai , Greg Kroah-Hartman , Jordy Zomer , Jernej Skrabec , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, asahi@lists.linux.dev, linux-arm-msm@vger.kernel.org, linux-tegra@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org References: <20230817235428.never.111-kees@kernel.org> <20230817235859.49846-14-keescook@chromium.org> From: "Gustavo A. R. Silva" In-Reply-To: <20230817235859.49846-14-keescook@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 187.162.21.192 X-Source-L: No X-Exim-ID: 1qWoEa-000Y5s-00 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 187-162-21-192.static.axtel.net ([192.168.15.8]) [187.162.21.192]:52924 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 465 X-Org: HG=hgshared;ORG=hostgator; X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfANj4pTR/E+qFWOHNTmEB43CQlp6HWJz0Ds8fnVdSjqRBfkSDqRIYQMTX8sNX3MVii1KmReHrjj8vemtY9rwwwG4TD4qRWJEVSRgfvmTVgipp3OnAx9N I87rJjysL1UjMvFyZQHQThZ1URlxFHNAaQFIPZ4R0yFh410FTBCOSRzIuQJD1i9c4bNDqSoFKTPlaJKzAlH/udR3N++NG40bub1RgyyHjD/x5x2SM5zCK+s2 Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org On 8/17/23 17:58, 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 stm32_mdma_device. > Additionally, since the element count member must be set before accessing > the annotated flexible array member, move its initialization earlier. > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci > > Cc: Vinod Koul > Cc: Maxime Coquelin > Cc: Alexandre Torgue > Cc: dmaengine@vger.kernel.org > Cc: linux-stm32@st-md-mailman.stormreply.com > Cc: linux-arm-kernel@lists.infradead.org > Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Thanks -- Gustavo > --- > drivers/dma/stm32-mdma.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c > index 926d6ecf1274..0c7d2295856e 100644 > --- a/drivers/dma/stm32-mdma.c > +++ b/drivers/dma/stm32-mdma.c > @@ -256,7 +256,7 @@ struct stm32_mdma_device { > u32 nr_ahb_addr_masks; > u32 chan_reserved; > struct stm32_mdma_chan chan[STM32_MDMA_MAX_CHANNELS]; > - u32 ahb_addr_masks[]; > + u32 ahb_addr_masks[] __counted_by(nr_ahb_addr_masks); > }; > > static struct stm32_mdma_device *stm32_mdma_get_dev( > @@ -1611,13 +1611,13 @@ static int stm32_mdma_probe(struct platform_device *pdev) > GFP_KERNEL); > if (!dmadev) > return -ENOMEM; > + dmadev->nr_ahb_addr_masks = count; > > dmadev->nr_channels = nr_channels; > dmadev->nr_requests = nr_requests; > device_property_read_u32_array(&pdev->dev, "st,ahb-addr-masks", > dmadev->ahb_addr_masks, > count); > - dmadev->nr_ahb_addr_masks = count; > > dmadev->base = devm_platform_ioremap_resource(pdev, 0); > if (IS_ERR(dmadev->base))