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 E5296C678DC for ; Fri, 18 Aug 2023 01:23:59 +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=d6GOrvTgEkeZciCs1ajhqrbtf0oBmDtcARr0wLplshE=; b=LKXVWDEql2Gwgx wYTWeK6TqS3Axl0mlkwocgo0qF2RlhVTgmf8W8d7kD2pdLLGhOPWn64GVcowwyfon3ZhMB8muRb+4 GMERwnRPBa6w8cF3fepw2cVlI5FSWcTyIeyn/0cSbWZX774jZsIEiUHIkrklYKCR8HcK0MkZVpUa0 i5fg4bT9rY9Ynf3Xe26Gq0DWITZCqMymLcAM1XEJTzYWQYDFmoDjJ5aF8u9ta50AyZzH/17kGp8WG oNV3vN+/YzpShZ5YwDTBTlQl7V8dDR7NceV1yN5P2WmYwdEXUDFVtGgypLhHLpYbMFq5cIr8xNdsv i/LvesHpVU23tMDtmeww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qWoD7-007T5k-2o; Fri, 18 Aug 2023 01:23:33 +0000 Received: from omta034.useast.a.cloudfilter.net ([44.202.169.33]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qWoD4-007Szd-0W for linux-arm-kernel@lists.infradead.org; Fri, 18 Aug 2023 01:23:31 +0000 Received: from eig-obgw-5006a.ext.cloudfilter.net ([10.0.29.179]) by cmsmtp with ESMTP id WmuKqo7iLez0CWoCpqAs6W; Fri, 18 Aug 2023 01:23:15 +0000 Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with ESMTPS id WoD3q6laRHSofWoD3q026s; Fri, 18 Aug 2023 01:23:29 +0000 X-Authority-Analysis: v=2.4 cv=HbEH8wI8 c=1 sm=1 tr=0 ts=64dec811 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=cm27Pg_UAAAA:8 a=qjWHau5h7Oqj65Zv8QkA:9 a=QEXdDO2ut3YA:10 a=AjGcO6oz07-iQ99wixmX: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=4O/pnsMN2mbUZXxNy5kzNXFmPO21hV2JJ/xiQe1qSMo=; b=KMrBMGMXN+OPsPe1WYDiAsg4Xz fV0vGm09SDOP8V0o8AD/WiWjeZ/ttYw5oZvtIfro0fjdAoYqSt106U1OpqEYNdrMLk5HVpBqQnGj2 cjH8H8ft36qOdQ7+UmgvX+ENKt3RKIioeb//n15aDS3YsiAJz8uapZk1MHSacBm1fjkp8vJsqvpq3 kvKmjG6ryksjNTn6SCDesKpS2dj7hqYPy9VzkMdfDINL0Ky+8d1Xm4treWBRAMr8Ybv7MtUQb1mrr CjmD0WecnaY6N0lIo6CRY/NzYGIy9ulPKd3uMI9wOQ5kf6r45IrtuIMz+6dtnhBIUXiHeMrb6y/EC q5SlftHg==; Received: from 187-162-21-192.static.axtel.net ([187.162.21.192]:48268 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 1qWoCx-000VYw-1s; Thu, 17 Aug 2023 20:23:23 -0500 Message-ID: Date: Thu, 17 Aug 2023 19:24:22 -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 08/21] dmaengine: sa11x0: Annotate struct sa11x0_dma_desc with __counted_by Content-Language: en-US To: Kees Cook , Vinod Koul Cc: dmaengine@vger.kernel.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 , Maxime Coquelin , Alexandre Torgue , 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-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-tegra@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org References: <20230817235428.never.111-kees@kernel.org> <20230817235859.49846-8-keescook@chromium.org> From: "Gustavo A. R. Silva" In-Reply-To: <20230817235859.49846-8-keescook@chromium.org> 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: 187.162.21.192 X-Source-L: No X-Exim-ID: 1qWoCx-000VYw-1s 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]:48268 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 216 X-Org: HG=hgshared;ORG=hostgator; X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfNBQ/W7ZiLWXLver4zYFA6atfbtVYCfnrxJ4fhp+axp9hyksmPWEwlrhIs9RYpTH8u3dRpM8jLpJSlSH5r6ly/43XfEea6xY5MZgtw+rtKXJfaB4konB 6zqEGiMUBtFzOLRGDaE7JRNVQenoOY58qRPIYgUJQeKJxHxwDmSC1YsLrdKWzDTG32dchSi33d3F5mAdnCLGReh23rKeQJQWZE425s7N+dRcCrmbf3Riqy1O X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230817_182330_264433_59950AAF X-CRM114-Status: GOOD ( 14.88 ) 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 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 sa11x0_dma_desc. > 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: dmaengine@vger.kernel.org > Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Thanks -- Gustavo > --- > drivers/dma/sa11x0-dma.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/dma/sa11x0-dma.c b/drivers/dma/sa11x0-dma.c > index a29c13cae716..e5849622f198 100644 > --- a/drivers/dma/sa11x0-dma.c > +++ b/drivers/dma/sa11x0-dma.c > @@ -78,7 +78,7 @@ struct sa11x0_dma_desc { > bool cyclic; > > unsigned sglen; > - struct sa11x0_dma_sg sg[]; > + struct sa11x0_dma_sg sg[] __counted_by(sglen); > }; > > struct sa11x0_dma_phy; > @@ -558,6 +558,7 @@ static struct dma_async_tx_descriptor *sa11x0_dma_prep_slave_sg( > dev_dbg(chan->device->dev, "vchan %p: kzalloc failed\n", &c->vc); > return NULL; > } > + txd->sglen = j; > > j = 0; > for_each_sg(sg, sgent, sglen, i) { > @@ -593,7 +594,6 @@ static struct dma_async_tx_descriptor *sa11x0_dma_prep_slave_sg( > > txd->ddar = c->ddar; > txd->size = size; > - txd->sglen = j; > > dev_dbg(chan->device->dev, "vchan %p: txd %p: size %zu nr %u\n", > &c->vc, &txd->vd, txd->size, txd->sglen); > @@ -628,6 +628,7 @@ static struct dma_async_tx_descriptor *sa11x0_dma_prep_dma_cyclic( > dev_dbg(chan->device->dev, "vchan %p: kzalloc failed\n", &c->vc); > return NULL; > } > + txd->sglen = sglen; > > for (i = k = 0; i < size / period; i++) { > size_t tlen, len = period; > @@ -653,7 +654,6 @@ static struct dma_async_tx_descriptor *sa11x0_dma_prep_dma_cyclic( > > txd->ddar = c->ddar; > txd->size = size; > - txd->sglen = sglen; > txd->cyclic = 1; > txd->period = sgperiod; > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel