Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp974188pxb; Sun, 19 Sep 2021 02:05:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygxTny8Lw4IVMX4c+L6XeLX2a8sszRVuHF7IniWgmXFLbFAYMijqWQyFeyH/W8QE5bEds0 X-Received: by 2002:a92:cb43:: with SMTP id f3mr14311358ilq.261.1632042327580; Sun, 19 Sep 2021 02:05:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632042327; cv=none; d=google.com; s=arc-20160816; b=mleMDHIj5rhE569lSQ2760HIuYjyslhN5dKTtpGe1NFKA6rrcKM244X2xWA3nFvU/G cbxCdOcQTFsCElE+rIMhk4hTGhMZQAS8UPUvj73dAzGi6AbCs0nyxWwx4xLuAggD9TQR kpKVSlicweEaiTesbaJQwDNI4XBPXx27agiUPu3uPS4i8UOU0tU6rraNR2B3bT0NawGr trScPJPJiKkS4+ZShTKEM3Cz+uKXee7kSPaIo+2ILfoZn2AwmU/9/sOxDqQgIR0zAF4k qI5Jlx3pAMJ0/ObbatKm5+5oOVrfxPOVuKYyeKKVJoHa1FBmjviyJDtcMHdb350cF9+d Npvw== 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=MFGKZmvyMLK99CP+tZ3bziV7HLwyE2GP88ufd1BXTgw=; b=AWggYNFqN7xGAfn3rbn5WmdpOJbRozUKzqqi6NViIVbQRyB+3JOmeprPGSIXCvLstp 7C2DqB9vpQHNGKJv6T8cgvWnKXmmUBTifjZZfJuXLWkDlbMpaiPy801OZ+oV2kkYaC6v jK5EFqN/FLCuY0APUPtn/D/t8mcK9WnzA+C/dY0FniNeFFe+BECHyizVDcFuvZ7KEX50 Cl0y9hh0iUDBDNyMxTtiGRilqCmy3ulY6NW5h2xM4V16pkEPRFamO+Tc2CdBsJXRY5TQ 6QOhtqvJ8tuhUXyv1BVibYFVcuz915ko18i49iJZ+UpzdyYYH7dbEYrdslYvl3G7FTFs +Pzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=VB7DZQsS; 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 v19si11296224jat.80.2021.09.19.02.04.11; Sun, 19 Sep 2021 02:05:27 -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=VB7DZQsS; 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 S238252AbhIRRNp (ORCPT + 99 others); Sat, 18 Sep 2021 13:13:45 -0400 Received: from mout.gmx.net ([212.227.15.19]:44729 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233210AbhIRRNo (ORCPT ); Sat, 18 Sep 2021 13:13:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1631985125; bh=HaaOH1N5B34fUsGwuYxHkOP8Bmo2FI+Nxh0L4luHKr8=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=VB7DZQsSQo3NdthY+tY5Lzk2zptqyURBOMmdUSo5Agucie2GLm8aROBoioKi0lKvD Ld0DnLhHissWEqrg7drrzOVbytBJyYGOyLxJ3qg2tzLEjpw/pEc89piEVlG0qFH81L TTNjPM3g0mTe/KElMKvOXjWbqSwUF9dVX+7en8AU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from titan ([79.150.72.99]) by mail.gmx.net (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1M8hV5-1mWIaL2lUX-004l1v; Sat, 18 Sep 2021 19:12:04 +0200 Date: Sat, 18 Sep 2021 19:11:47 +0200 From: Len Baker To: Kees Cook Cc: Len Baker , "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?= , 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: <20210918152604.GB15999@titan> References: <20210911102818.3804-1-len.baker@gmx.com> <20210918132010.GA15999@titan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Provags-ID: V03:K1:/jOFZgiazp1Mu4q1yJZMZHCqZguWrTCVgOiUcRwDstkREyaTGYs UBQwp8eIVfvNPaQRfAJFF6LevZRZFI3xZ7MwzMmBLXd1W+g/m5XnL7waXh0U0kTdndpmAi0 ep8beAtJmIfSZXxkf5ZwEUPtSYRTGnVO38vTd3E9Hlc/eloGCAHpZj4eeqnyIixDxUm7vwb h6tbGt6bwtugEagOhPyqw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:4M+R8W0zYpQ=:FygVzFs7OR1agH0Yq+kqbo 4yXp3xJ45NY4137+M42bmwT+MbhbJ0gdkcvFzqOqph1/eLu8KfjQNG6U4FE9XtJiC1sSCxdNW EaufVRWhjFaqnoorFfuL9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-kernel@vger.kernel.org Hi Kees, On Sat, Sep 18, 2021 at 06:51:51AM -0700, Kees Cook wrote: > > > On September 18, 2021 6:20:10 AM PDT, Len Baker wrot= e: > >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 simil= ar) > >> function arguments due to the risk of them overflowing. This could le= ad > >> to values wrapping around and a smaller allocation being made than th= e > >> 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#ope= n-coded-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/drive= rs/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_chann= el_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 thi= s > >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 arithmeti= c > > - http://patchwork.linuxtv.org/project/linux-media/patch/202109111= 02818.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 = comment > >and a "Reviewed-by:" tag from Haiyang Zhang. So, what is the reason for= the > >"Not Applicable" state?. > > That is the "Media" subsystem patch tracker. The patch appears to be for= networking, so the Media tracker has marked it as "not applicable [to the= media subsystem]". > > The CC list for this patch seems rather wide (media, dri). I would have = expected only netdev. Were you using scripts/get_maintainer.pl for getting= addresses? Yes, my workflow is scripts/checkpatch.pl and then scripts/get_maintainer.= pl before sending any patch :) Regards, Len > > -Kees