Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp814105pxb; Sat, 18 Sep 2021 19:52:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4W/CQvYtmgEaa5owP1/ELYL2tyb1tWLpu8Ydid9g+pDt76CK44xqRWUdAC+BQvI//SMnq X-Received: by 2002:a05:6e02:148e:: with SMTP id n14mr10481472ilk.319.1632019934551; Sat, 18 Sep 2021 19:52:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632019934; cv=none; d=google.com; s=arc-20160816; b=Np2wxdgZZw7aHwQZuZxT5jCcJKdEyQNAY+kxspRshJMaVDRAXUMmsrFhazNLF94sCx xfCICidifmBHY3yCNOUKFDLkpEL0V6BMVDAIWyv/r+mr5P7g93L2uIp+iHUgJe9Mad7q AMDJDhxu6CRF9k0bluX7qlnjeJEtDj7oQjn1d+S3modcaq17WwLVBMZ43hcNDzU5aNok Jhdg52kefokL19vWuEEUiYB5ZIa1q5pVE0qexnt5lZeKY23lWhj6BEGC/0QY2n4QOhga ukk7fPVTdYyhpRPmpcT9UF3rFKs64kZ2CL0iLYS61Syq2OuVPP+v+BQbJjU8h85rGlWB WB6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=KLn0Pn68FVmeBqmjmy3hNQRHUcGwOvRsk5nAtBJQzjE=; b=AvsO39zSWqx5ViOOpEU8Z1NwvYZl7Enyr/G1zu3hHLOSc4NxfW7j5wvCYJaYRqVeuS hYyxBFvsa6V+Yzfojbad1QtewcggDW3Hj+z+GApQpl3UbPIUJznPm1WRay2EQmkrv/H0 Sn1n3kCcPsnAk73lir2BvmePa1+AiPT4xug1zKvfwMNnIge6Veu9npPBoYDkFA7ASKRA rZMmCb3axp0rHTn43Lo7Gx3cMZzt9QA8Ayr0YQs0qR38zEiPsi9MkAL+hr2+/WzJh68M 4O7B0FEAVjtzKJmh116WE87JepL3zzKhBYCwBWer1Y7A/bgQpt6xaT2PJxx54C7LBzyj LmWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=LWTfMYcA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si3934747jam.54.2021.09.18.19.51.38; Sat, 18 Sep 2021 19:52:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=LWTfMYcA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236978AbhIRNWN (ORCPT + 99 others); Sat, 18 Sep 2021 09:22:13 -0400 Received: from mout.gmx.net ([212.227.17.20]:47769 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbhIRNWI (ORCPT ); Sat, 18 Sep 2021 09:22:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1631971222; bh=utd0q4hqIMtuJEsThLosqrfrDQjZp+7lfixpFX7XqnI=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=LWTfMYcASFTf67QItbBWAZMgfjABOCJnq4qSUTWVkOAtVhBwNq0hgqMVJFGO0reQV 1OBScoMwlAruAkx1+LnLyWnUG6F6mthX3pbBDxBChCBtPm0B2giHjopoBJR5qik4og rHuMrAeT599Y25tj4UQbiNY3NSjUBCCyqyswkthg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from titan ([79.150.72.99]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MNKhm-1mH5ci08wk-00OmPk; Sat, 18 Sep 2021 15:20:22 +0200 Date: Sat, 18 Sep 2021 15:20:10 +0200 From: Len Baker To: "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , "David S. Miller" , Jakub Kicinski , Sumit Semwal , Christian =?iso-8859-1?Q?K=F6nig?= , Kees Cook Cc: Len Baker , Colin Ian King , linux-hardening@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Subject: Re: [PATCH] net: mana: Prefer struct_size over open coded arithmetic Message-ID: <20210918132010.GA15999@titan> References: <20210911102818.3804-1-len.baker@gmx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210911102818.3804-1-len.baker@gmx.com> X-Provags-ID: V03:K1:BPsfjmvLWKWmUtY2rfEeoDvxY6Wuum+kDmKPnYfRtNYpw8qgDAD RhTDWgmsIEN+bzwDQEpc3L/j6yAPdII+XK7ekbbFRT+WCGCF+/aq+yq2YmAPesXrZu3fRfx wW7jNo6iQ7H5V5LYlTFcYwbOe4bNIRmOLUTAIiWaGRfv2n3S9hvz/U7QU1NsODbw6onb6aM LL0BxR0LXzP/M0XqAQB0g== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:qStfD7wYGCw=:CcrsvfQSdNHEuPuePCcNlz IO+6yJb1Wzy05aUq3UsQCasVn8xv1ZUVRo6mHXjGimDZR4Did1bGuQyqPt+XUG1jlB05UqUJ0 nWgRzgDrI1CHIz5yOaIEMUilrjTv/tXfj4iWBp/wcdvTqycEWi2GeWER1sCrx5m01Vc0gA8as uve1NAj8KXEdS8aPmN4KTN5acD0gl75Z98tR9G8pEJfcYjb8YHzSO6JgkXKvJwVwdXHkbKs3i RxcNn1X7TnutYQShodSla+6tgDLTiZQQMwpJ2yH6Njx7FkubrnJdiwL54PO9mcQbTy6snpaMY 5xtq1LtIyYUghT5r3+nPkI9AOX7fTLY2DxioCYD0CTZfvbFlAKBY8NYq2TghQDzNHD2t18w7N xmmOnWY9cQ31BmrpEQSwPsDlp3Wn9wUK1RZC9tPJ8Qac7X7qry31ZjiQTjHf3Dh6rfZxogl+H lwi7zwkbJx6YysMfJaWcDR2JtUjIi3SXCoWF5+qI2tNCwJcjyQXcxJuKcXkDrm4tamdeLfNAH OnOogVvQ3bz2Y2lxjadQn7BaA/OMwM3boxeoHeWgowB2OiJAfnWTeieKs+WreKsZfZ3SN02PK muAQRPzfq004pN3SeI0zhzo0TPv3jzasctsi3/9NsGnnBnbcaN3yWu9brDUVxYQ7u4N6Ry7lY aE/f4oqeplwQASCnvDVWBW+M6vSyREznTSVBFi7zYxPoJ6KEolM5NgS4zvjYiE1kL0Yosoami mLe4VLryD/hSLshKzRqi6HGK7pWpGygCdX1XeGol4LhPoEyogqJoDeZFIuCWosuOvp7aB+RRv CrdE0Y2dbmIC9zbUA/etHs6BsBKe876fVfiUWARtpd13vusxAgNMlbOC7+WMv3ObKb15g795X tLuzE2X5o6emAtu47HgKo668A8WeIvtw9rM/NXc23EPhjK2jlLxPHKWgzqUNGXq394CArijMk z/+md7oA7PQVxaXk7GCAIdke1ektjaz+8eadbTr1h898jGZUljVJzOIEFA22xNnMFXitgDuK6 ninxUQ4qfEUX0wYviLSceiJ0FVn98lk7BQ7qtWOplhQCIlzH8Fi0luyTAbzFUSSo7F5wv8zaK THujcWZZ3EUjUQ= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Sat, Sep 11, 2021 at 12:28:18PM +0200, Len Baker wrote: > 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. > > So, use the struct_size() helper to do the arithmetic instead of the > argument "size + count * size" in the kzalloc() function. > > [1] https://www.kernel.org/doc/html/v5.14/process/deprecated.html#open-c= oded-arithmetic-in-allocator-arguments > > Signed-off-by: Len Baker > --- > drivers/net/ethernet/microsoft/mana/hw_channel.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/= net/ethernet/microsoft/mana/hw_channel.c > index 1a923fd99990..0efdc6c3c32a 100644 > --- a/drivers/net/ethernet/microsoft/mana/hw_channel.c > +++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c > @@ -398,9 +398,7 @@ static int mana_hwc_alloc_dma_buf(struct hw_channel_= context *hwc, u16 q_depth, > int err; > u16 i; > > - dma_buf =3D kzalloc(sizeof(*dma_buf) + > - q_depth * sizeof(struct hwc_work_request), > - GFP_KERNEL); > + dma_buf =3D kzalloc(struct_size(dma_buf, reqs, q_depth), GFP_KERNEL); > if (!dma_buf) > return -ENOMEM; > > -- > 2.25.1 > I have received a email from the linux-media subsystem telling that this patch is not applicable. The email is the following: Hello, The following patch (submitted by you) has been updated in Patchwork: * linux-media: net: mana: Prefer struct_size over open coded arithmetic - http://patchwork.linuxtv.org/project/linux-media/patch/202109111028= 18.3804-1-len.baker@gmx.com/ - for: Linux Media kernel patches was: New now: Not Applicable This email is a notification only - you do not need to respond. The question is: Why it is not applicable?. I have no received any bad com= ment and a "Reviewed-by:" tag from Haiyang Zhang. So, what is the reason for th= e "Not Applicable" state?. Regards, Len