Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2382429pxb; Mon, 20 Sep 2021 20:53:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwxv6pu0hjwB44Goz4KA+KProNIv0Frp9hc6AtEcThJCROHHfQIouvdCR9hirsi28aCgVC X-Received: by 2002:a50:f197:: with SMTP id x23mr33137492edl.222.1632196397765; Mon, 20 Sep 2021 20:53:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632196397; cv=none; d=google.com; s=arc-20160816; b=BRLArTGMvS3sWzNhVJOSd48JZlF+0zdyfUnCjfRqLMl80CyyCaPTGBVkvvgCbBVska dLbIoHmzgXaCmcbVpcLz1HlvucxnS2razJt+mqY9z/F1faGtE1XXp5H2NcjVeGP+XVzi 8bmvjF5/1JRGkFLBoleAU6aSwHtNUVtRnFJ3PjJaAYDoIj1xYSJxl9Z3OU0y/aFQ1oYh qR2nDh3J6+EYXecQ79WRCRiD4NNq9oNhrS6wKA3CtJG2J2o3X/nDYp19TQTbPFMSOv14 unN87vpUV6Cl5bHNEiTjIkg2wXtkEHT32EpiEbDb6WfcGHP2qjwwzLyGfyGbTeOmPAHT KEaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=dIZWTLeUsAcg6awfj+mJ/VeStP2PiXGKlLzxmy7BCEg=; b=umhWj90yNYskX0L4eWjnGr0py7uHTfygrkreYEN0ox85iMJCf8O6VlJPGSE/wgMY2/ 4z9jttYLS2wUPAGRr/kFcyXG+JCV5FytigP/b7CCE87gLoXHrfxxovNUHu1BRZb/sG8+ wZkkSA/xWIk0LY5ARdqex4jLu7Gc5gYRQsazJiD4IneSGvTbTt9e0DiGIL9nA+kBoJ5K FF28smLBH1BVHWLVM6kqXux5dlYJTGzxEQVlx2cWkzXZ7MAVPJZSZdA9M/XxJ/+0xS/j +TzpXAeZBrJNKFV6BK7cQYaU5LkowzLvs7UTz9rfr19bEnIv2L8rizTeBIzUYFPKu9SM ZyFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=qpP925gQ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s18si21392641eji.59.2021.09.20.20.52.54; Mon, 20 Sep 2021 20:53:17 -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=fail header.i=@embeddedor.com header.s=default header.b=qpP925gQ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233392AbhIUAbv (ORCPT + 99 others); Mon, 20 Sep 2021 20:31:51 -0400 Received: from gateway33.websitewelcome.com ([192.185.146.130]:44930 "EHLO gateway33.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230376AbhIUA3u (ORCPT ); Mon, 20 Sep 2021 20:29:50 -0400 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 3A86611F6D for ; Mon, 20 Sep 2021 19:05:51 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id STIFmLGJBjSwzSTIFmoR9U; Mon, 20 Sep 2021 19:05:51 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=dIZWTLeUsAcg6awfj+mJ/VeStP2PiXGKlLzxmy7BCEg=; b=qpP925gQr2CunCsqGZ8nBoNddT hr+cP5UbxRC/JdtHMH18vJFzQPaDHnc1j6KxxAZx9VdRj/JJSUjAt+qkohtGh5+zvKZXqkYvERaB+ sTI/RQMyUXv2x2Lc5X6WdXMggxnU7QXGzBdXHuhztlY2lkYiMr3pN0oFJ3HgruRuSkxpjreftedGn yx93FeU7vWW6WhBGiaHGPCsj1m/ehyiyVZIaCJItH8dPpvc6cQjhQEquiXCnxJunJ1deZ4/I+/UH2 gXwrqPuWtIUz3JKZJHkMievNK4+NcezwXqsiLZmYj/GfA2KrJhzCY+T1rDUpOwRlukQ7z3HaL/t4S KdGsoAqg==; Received: from 187-162-31-110.static.axtel.net ([187.162.31.110]:33874 helo=[192.168.15.9]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1mSTIE-000eHV-PB; Mon, 20 Sep 2021 19:05:50 -0500 Subject: Re: [PATCH] afs: Prefer struct_size over open coded arithmetic To: Len Baker , David Howells , Marc Dionne Cc: "Gustavo A. R. Silva" , Kees Cook , linux-afs@lists.infradead.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210919094432.30510-1-len.baker@gmx.com> From: "Gustavo A. R. Silva" Message-ID: <8664159c-b986-64b0-13d1-b2739deb159d@embeddedor.com> Date: Mon, 20 Sep 2021 19:09:38 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210919094432.30510-1-len.baker@gmx.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 187.162.31.110 X-Source-L: No X-Exim-ID: 1mSTIE-000eHV-PB X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 187-162-31-110.static.axtel.net ([192.168.15.9]) [187.162.31.110]:33874 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 18 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/19/21 04:44, 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 + size * count" in the kzalloc() function. > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments > > Signed-off-by: Len Baker Reviewed-by: Gustavo A. R. Silva Thanks -- Gustavo > --- > fs/afs/security.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/fs/afs/security.c b/fs/afs/security.c > index 3c7a8fc4f93f..7c6a63a30394 100644 > --- a/fs/afs/security.c > +++ b/fs/afs/security.c > @@ -219,8 +219,7 @@ void afs_cache_permit(struct afs_vnode *vnode, struct key *key, > * yet. > */ > size++; > - new = kzalloc(sizeof(struct afs_permits) + > - sizeof(struct afs_permit) * size, GFP_NOFS); > + new = kzalloc(struct_size(new, permits, size), GFP_NOFS); > if (!new) > goto out_put; > > -- > 2.25.1 >