From patchwork Thu May 13 22:49:14 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: 12256807 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85CFCC433B4 for ; Thu, 13 May 2021 22:48:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 441D2613CD for ; Thu, 13 May 2021 22:48:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230327AbhEMWtt (ORCPT ); Thu, 13 May 2021 18:49:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:47260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230168AbhEMWts (ORCPT ); Thu, 13 May 2021 18:49:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 38FD9613CD; Thu, 13 May 2021 22:48:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620946118; bh=zjDn79+oCEcXN7/ywRSvtSC+DVZKzNYOS/1XNPve5xk=; h=Date:From:To:Cc:Subject:From; b=UlNmGjy+Sr9KgC8Jul/5pxK7lQ0Ewhr04wTCFE0VpWtnTelzSfXWoUgoSVRCCmtf+ FjcJtomzJWOJbRL22GadqACRdFcahUhlPtcKwiCNkkwACllCMz9xEf30u8ErqooM+q 21Pl8jDgT1Bk2cOt9uN65TeS/rT9b3jFdRDUDDMBkLSnuXC7szI4G4/KOcnNANi4cj f4fPvbmR6/DvXLj1Bkl3lHknyRh3lmABpt8/Dmbzx4OUPXNB8XNkGL+hiRuWTbHTnR R4FTbTtGyhyfw9bw5aC8yxC+xgItBG81ASwRWWdHMDO8o0sTICpllveNuKPTaj33YU MSK2RiJYBFMLg== Date: Thu, 13 May 2021 17:49:14 -0500 From: "Gustavo A. R. Silva" To: "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , "David S. Miller" , Jakub Kicinski Cc: linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] net: mana: Use struct_size() in kzalloc() Message-ID: <20210513224914.GA216478@embeddedor> MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@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. This code was detected with the help of Coccinelle and, audited and fixed manually. Signed-off-by: Gustavo A. R. Silva --- drivers/net/ethernet/microsoft/mana/mana_en.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c index 04d067243457..46aee2c49f1b 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -1387,8 +1387,7 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc, gc = gd->gdma_context; - rxq = kzalloc(sizeof(*rxq) + - RX_BUFFERS_PER_QUEUE * sizeof(struct mana_recv_buf_oob), + rxq = kzalloc(struct_size(rxq, rx_oobs, RX_BUFFERS_PER_QUEUE), GFP_KERNEL); if (!rxq) return NULL;