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 10027E748ED for ; Sun, 1 Oct 2023 07:50:09 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=V59htut9ZSW5Bm02uCUrBzPsRKa0nLNrr3odn+brysY=; b=F1DLvCogEus7Zg rKoPY75CK2OvkJzZBOIRA4yOaQKBqAirfOOay0nJUEbQaD5nEUzCOZqr8MgEBkQKiIldqdZaipAMF 3esg5hq2UHeMDUszWFoBjj3lZZq3EpTrjWjMn9JXOm2wxoBaNHvnNLp3Dv+/YVdDKortr05hFG2iz eE9revt59wKIWTSdM/CCTogAMSNYD5RR2yZUY7bTD2qeS6P6J02NfWi4ZNkckzgnI5Yp7hLZ1YMti BOZCsykOU7K5JOClgwQQuu/jnCO/tWhU8uVe5T3AXnRAP+C2lNXaAYN037aQitnUaEUEpL1ne0VQT uS2cfouirj3Do9UZsz5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmrCu-00AiVc-34; Sun, 01 Oct 2023 07:49:40 +0000 Received: from omta36.uswest2.a.cloudfilter.net ([35.89.44.35]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qmrCs-00AiU6-05 for linux-arm-kernel@lists.infradead.org; Sun, 01 Oct 2023 07:49:39 +0000 Received: from eig-obgw-5006a.ext.cloudfilter.net ([10.0.29.179]) by cmsmtp with ESMTP id mdmCqH56aMZBkmrCeq6e1d; Sun, 01 Oct 2023 07:49:25 +0000 Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with ESMTPS id mrCdqMh9hgo39mrCeqvDeL; Sun, 01 Oct 2023 07:49:24 +0000 X-Authority-Analysis: v=2.4 cv=D4dUl9dj c=1 sm=1 tr=0 ts=65192484 a=1YbLdUo/zbTtOZ3uB5T3HA==:117 a=P7XfKmiOJ4/qXqHZrN7ymg==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=bhdUkHdE2iEA:10 a=wYkD_t78qR0A:10 a=VwQbUJbxAAAA:8 a=NEAV23lmAAAA:8 a=cLZyiMI5l2q1nrJyhZUA:9 a=QEXdDO2ut3YA:10 a=AjGcO6oz07-iQ99wixmX: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=ctbPsvlFsKyDYeo7FjRggIA8ffQtTboXoPN4rM9I5Ak=; b=U+nXmy3Z6LSZdtXmnO3XiLegSK kdboceARJMpolXbgZGHt1Q1rWpezLjLdiErLTqBd2mzmn3CC3IbiBpOMxWiqAp8bsn6hZ20xwEYBI 3nwEETsTZoe9O9rniIN+IWKzHpl3uvm4f6T0BV3wfu+YALy2zdzRmSwi5nc+7o4GMS0g/FPpTwSUb IYlNt64qP9L7Gn0FIRsijCjALoZmQyXHc1aaYEqI6njCWnSOl6psjMYnltkCeJTa/zQbEvJom0JQc 1LC6bqtPcC1cw6RW9r3MiztBpSwz4HVLA+8hCMQfbgLgTlPca2HgkSyZTzIgfyiyO7aVtZg3b38T+ otR7PGDQ==; Received: from [94.239.20.48] (port=43776 helo=[192.168.1.98]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1qmrCb-002Jj3-1w; Sun, 01 Oct 2023 02:49:21 -0500 Message-ID: <1bcde585-f740-8959-6e2e-19793795b60e@embeddedor.com> Date: Sun, 1 Oct 2023 09:49:16 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH] mtd: rawnand: rockchip: Use struct_size() Content-Language: en-US To: Christophe JAILLET , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Heiko Stuebner , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Tom Rix Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev References: <481721c2c7fe570b4027dbe231d523961c953d5a.1696146232.git.christophe.jaillet@wanadoo.fr> From: "Gustavo A. R. Silva" In-Reply-To: <481721c2c7fe570b4027dbe231d523961c953d5a.1696146232.git.christophe.jaillet@wanadoo.fr> 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 - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 94.239.20.48 X-Source-L: No X-Exim-ID: 1qmrCb-002Jj3-1w X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([192.168.1.98]) [94.239.20.48]:43776 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 17 X-Org: HG=hgshared;ORG=hostgator; X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfH+JPhomF8xZu0RjZg7ICYhscIQMhZQLCt7tZH+okCHjL3w2A2JJCL8GIu2HylZrrm7FqVzDLdHnl8+xGR36A6MG0pxtkXf/d7c4D74nzi+axnXvUIYp AlolcDmxR2ZKH6rQ71Wj10M8PsGkLMDHAAeN6UoeK53yAo0w4RIFoAhyvzm0Ppqlsa3vULiYgW2Y/rLWWbO3ok9jWyQ6wXHBE1WsP1d+pWyMWteHzaisrTSs X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231001_004938_109811_255020D5 X-CRM114-Status: GOOD ( 19.64 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 10/1/23 09:44, Christophe JAILLET wrote: > Use struct_size() instead of hand writing it. > This is less verbose and more robust. > > While at it, 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). Again, I'd prefer this as two separate patches. > > Also remove a useless comment about the position of a flex-array in a > structure. > > Signed-off-by: Christophe JAILLET In any case: Reviewed-by: Gustavo A. R. Silva Thanks -- Gustavo > --- > This patch is part of a work done in parallel of what is currently worked > on by Kees Cook. > > My patches are only related to corner cases that do NOT match the > semantic of his Coccinelle script[1]. > > In this case, struct_size() was not used to compute the size needed for the > structure and its flex array. > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci > --- > drivers/mtd/nand/raw/rockchip-nand-controller.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/mtd/nand/raw/rockchip-nand-controller.c b/drivers/mtd/nand/raw/rockchip-nand-controller.c > index 5bc90ffa721f..596cf9a78274 100644 > --- a/drivers/mtd/nand/raw/rockchip-nand-controller.c > +++ b/drivers/mtd/nand/raw/rockchip-nand-controller.c > @@ -158,8 +158,7 @@ struct rk_nfc_nand_chip { > u32 timing; > > u8 nsels; > - u8 sels[]; > - /* Nothing after this field. */ > + u8 sels[] __counted_by(nsels); > }; > > struct rk_nfc { > @@ -1119,7 +1118,7 @@ static int rk_nfc_nand_chip_init(struct device *dev, struct rk_nfc *nfc, > return -EINVAL; > } > > - rknand = devm_kzalloc(dev, sizeof(*rknand) + nsels * sizeof(u8), > + rknand = devm_kzalloc(dev, struct_size(rknand, sels, nsels), > GFP_KERNEL); > if (!rknand) > return -ENOMEM; _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel