From patchwork Sun Sep 5 06:50:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Len Baker X-Patchwork-Id: 1524799 X-Patchwork-Delegate: anthony.l.nguyen@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=NwV3+hdV; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H2nfV3QHnz9sW4 for ; Mon, 6 Sep 2021 09:24:02 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 9923E80B9A; Sun, 5 Sep 2021 23:23:59 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VWfcSTE9Kd-4; Sun, 5 Sep 2021 23:23:57 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp1.osuosl.org (Postfix) with ESMTP id 38FC380B49; Sun, 5 Sep 2021 23:23:57 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 5645C1BF2B8 for ; Sun, 5 Sep 2021 06:51:09 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 43B94401C8 for ; Sun, 5 Sep 2021 06:51:09 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=gmx.net Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ob8HmxPyubi1 for ; Sun, 5 Sep 2021 06:51:07 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by smtp2.osuosl.org (Postfix) with ESMTPS id 520BE40015 for ; Sun, 5 Sep 2021 06:51:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1630824651; bh=6y4lA42xc7tbqPJz5XFWFgyW1+53pCMMuYhyZwSm6Ro=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=NwV3+hdVBu6FFKg/gaTjSLrOPfLGDyyRXwKwz7rMO8LzfxKN6wwC8gU1vvrd0QrY+ JU5pi9afRmoVHXSABFDYCOwT4868KsuhCH05H1YwbIBaFXfzfGjGANRMKjrwUDoR1V OT2ohUu0IoSylgB5xfxsLoxps6BBv5fWuhDY4xsw= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([79.150.72.99]) by mail.gmx.net (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1N2mFi-1n5tpf1DNk-0136Ew; Sun, 05 Sep 2021 08:50:51 +0200 From: Len Baker To: Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Jakub Kicinski Date: Sun, 5 Sep 2021 08:50:20 +0200 Message-Id: <20210905065020.8402-1-len.baker@gmx.com> X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NnVbdslNuY6uyqjO3scf3l6q2n/ybkFJ1gAaKrIx2bXZ42Og/kH8fWC HanbF+rCOpiYUwKnkWtpiVRT8NoM8ACMkVdvcedOSpKCH9n7z6je9tCeu2goT7pB6FkZpSx5G Pfpz/RKzOOwvkk5f4S/cgZsYxD8CDJiuwYNj03DiQyZxVAU+0K0akDuQwGVgeoAaVS1oTyDHW bSoWUtDzcXlq7lcLC5JokjqJCwUH/MpbmDx8Cv/XJQWd8jHRN5wKPQcTnUwWRX4kkwzQtbh6L zPxB2yjkz9cSkeLJyCdcYYvMfN71emAz0QDIbNPo36x7iykLEkJGJTA8YD9hzMmuPKxtRN91Z CiwTZbqMU0PZGaEf1bTIkTKfovUOOcKkFA/RhZ7CvBe6cTvZfocst8hDw== X-Mailman-Approved-At: Sun, 05 Sep 2021 23:23:52 +0000 Subject: [Intel-wired-lan] [PATCH] ice: Prefer kcalloc over open coded arithmetic X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kees Cook , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, linux-hardening@vger.kernel.org, Len Baker Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" As noted in the "Deprecated Interfaces, Language Features, Attributes, and Conventions" documentation [1], size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors. In this case this is not actually dynamic sizes: both sides of the multiplication are constant values. However it is best to refactor this anyway, just to keep the open-coded math idiom out of code. So, use the purpose specific kcalloc() function instead of the argument size * count in the kzalloc() function. [1] https://www.kernel.org/doc/html/v5.14/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments Signed-off-by: Len Baker Reviewed-by: Gustavo A. R. Silva --- drivers/net/ethernet/intel/ice/ice_arfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.25.1 diff --git a/drivers/net/ethernet/intel/ice/ice_arfs.c b/drivers/net/ethernet/intel/ice/ice_arfs.c index 88d98c9e5f91..3071b8e79499 100644 --- a/drivers/net/ethernet/intel/ice/ice_arfs.c +++ b/drivers/net/ethernet/intel/ice/ice_arfs.c @@ -513,7 +513,7 @@ void ice_init_arfs(struct ice_vsi *vsi) if (!vsi || vsi->type != ICE_VSI_PF) return; - arfs_fltr_list = kzalloc(sizeof(*arfs_fltr_list) * ICE_MAX_ARFS_LIST, + arfs_fltr_list = kcalloc(ICE_MAX_ARFS_LIST, sizeof(*arfs_fltr_list), GFP_KERNEL); if (!arfs_fltr_list) return;