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: 12662935 X-Patchwork-Delegate: gustavo@embeddedor.com 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 88F50C433F5 for ; Wed, 8 Dec 2021 00:04:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242701AbhLHAIS (ORCPT ); Tue, 7 Dec 2021 19:08:18 -0500 Received: from sin.source.kernel.org ([145.40.73.55]:46270 "EHLO sin.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242690AbhLHAIR (ORCPT ); Tue, 7 Dec 2021 19:08:17 -0500 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 sin.source.kernel.org (Postfix) with ESMTPS id 57E19CE1ECA; Wed, 8 Dec 2021 00:04:45 +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 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.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;