From patchwork Wed Dec 8 00:10:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 12695188 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 4C2D5C433F5 for ; Wed, 8 Dec 2021 00:07:18 +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:MIME-Version:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=9zMHOT+/Rfp7Dg7SG9ouokyKUkg5Sfxkm2QidkCfUCU=; b=2lrpvfc6BdxDdz 3nRRetyJ1ARDr/c+L8U4pZj1HCiUuyhGt9hxF9cgxspW5/n/Hwbu1nxh2e1q9/sCXdYFUrHpEEtja zKzFQQ6gzZXzD+alOxUdBL3DPb8uc7EBXYsd895vSr5GZkpD5i4y48XS8BigQpKlDPHKZxzUu4GQF lt7S6gmqbbBGGLhOGrpCHVMEZStlYSGh2WUPyBSwBcdM9zxQipufUyhbxqx9JsSz+wgmnJnAEhXsA bCYUTgIb08sHFaBpKpURN4mw4ak/uBS5YnCGVNkPz4R2iq9JLsfRJKyF7vNOTjpjpZVzcXBdqQUa3 jGIzEVqvicyfkPSKECFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mukS4-00ANIp-EF; Wed, 08 Dec 2021 00:04:52 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mukS0-00ANHx-0h for linux-arm-kernel@lists.infradead.org; Wed, 08 Dec 2021 00:04:49 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CA7CCB81EBA; Wed, 8 Dec 2021 00:04:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 029FDC341C5; Wed, 8 Dec 2021 00:04:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638921883; bh=HVrBSNB36jTypNFFUkXDJkWXugeWW3Ecpo4AdjI1ygY=; h=Date:From:To:Cc:Subject:From; b=ZQQ6iAWGMymuF120zo9dKdNCNl6eiU0cit85AlJYyJtoyas5S2UxPHX3o0cwT+hbB 6yZQWUwsq76lATHtSVWBBzKLe5DlV3CIm0UHUJ2LgtEPbbWIxB4Hy3WLd4uxZP3G9n J7oyyuFhuBhr/ng8e8+XaCRwGymOuT6GAg4NYmVEBmfTtuysf7jhzYEQVLoVovcocd oRKJJesq8Jds5eAAeAdR+mwpQZN1YS+tDeLsogONg62v3noNXxvs/caRH2BHv6f2k1 7+T1bWmkbpJw/tnftpXDI2PiGYAYTHAbBoZd8NbUJGqi+8qTo7lvPEmX1CCg58kHgB 8BLzHqHVtZGeA== Date: Tue, 7 Dec 2021 18:10:13 -0600 From: "Gustavo A. R. Silva" To: Ludovic Desroches , Tudor Ambarus , Vinod Koul Cc: linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] dmaengine: at_xdmac: Use struct_size() in devm_kzalloc() Message-ID: <20211208001013.GA62330@embeddedor> MIME-Version: 1.0 Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211207_160448_253168_7FE289DD X-CRM114-Status: GOOD ( 11.68 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. Link: https://github.com/KSPP/linux/issues/160 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/dma/at_xdmac.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/dma/at_xdmac.c b/drivers/dma/at_xdmac.c index 275a76f188ae..e42dede5b243 100644 --- a/drivers/dma/at_xdmac.c +++ b/drivers/dma/at_xdmac.c @@ -2031,7 +2031,7 @@ static int __maybe_unused atmel_xdmac_resume(struct device *dev) static int at_xdmac_probe(struct platform_device *pdev) { struct at_xdmac *atxdmac; - int irq, size, nr_channels, i, ret; + int irq, nr_channels, i, ret; void __iomem *base; u32 reg; @@ -2056,9 +2056,9 @@ static int at_xdmac_probe(struct platform_device *pdev) return -EINVAL; } - size = sizeof(*atxdmac); - size += nr_channels * sizeof(struct at_xdmac_chan); - atxdmac = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); + atxdmac = devm_kzalloc(&pdev->dev, + struct_size(atxdmac, chan, nr_channels), + GFP_KERNEL); if (!atxdmac) { dev_err(&pdev->dev, "can't allocate at_xdmac structure\n"); return -ENOMEM;