Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp55784pxb; Wed, 20 Oct 2021 16:24:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEWvloUcPHCsv9HAOJhNJZYB6KTbuaCfyISapzR7ORpROfi9RZOrpymaPLGsX5Fm3gatrv X-Received: by 2002:a05:6a00:1a8e:b0:44c:5f27:e971 with SMTP id e14-20020a056a001a8e00b0044c5f27e971mr1856383pfv.72.1634772240903; Wed, 20 Oct 2021 16:24:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634772240; cv=none; d=google.com; s=arc-20160816; b=buDXfP2/fA+fMyMTr3w/QsJaa0guFTQiYoEIvGfSR7UDHxINcLZRmComISch37QOHL tZfa6wMF0m8lZCYX3pgfgQMf2/XWTLRvfN9kFGDZFNuugT/Hi+vPSIeDRzG5y1aTKymk tO7qJIgKJrYxjHCHZvYouCCpZDpsz0rpc6pDMY46U8Dx8UURmWpQ7i08wewpdd1Uonfr fu4iXpMEk8tVVS2qnrntFA9ds4oIhXMdHUeP6169El2/sLDlbRAR3VvM0d1jD5Dj8nen S1mADT7Rlkzwso7Z8r9RSYmfggvnt3jbcuccYZtSb0beIPiBnuNzYhamwFuI+y8TILov G6JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=2271XYV/mmrG00ppDLG98OtjVhXNYziWayEsLY/2I4A=; b=xI1ok28l9m5EKXHtLKnEQW8ReqlGxmgRRICv6kxnWD89aXXjcvNv2l9z4UIiAkRKM/ l74zmidY9FTF5R4AOz/yY9U4Y30JV3J6Z8IApcnKr416UiMyQc5aS5QgrS5pCp2yf4j6 AKWLZXLeXpI8IVgPM0ev/ErcuHQjNlI/xwrDBwO0uRYQYq0bi5o4/IfHqr45ducECfIj R102ofaWqz+FqrLYiHE+v0VNstjW/7+Lx7NpxX6nbncBKDn7fAuEWpKwFXL/5sk/7Kxy TjqWuOIUc86cuQ2x12XSst57vb3mtSnErGy2dx8WrqGoN+aNXo8arJ08yufRPFRcYrVX nEYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Czf1Iwhw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o11si5988932pfu.316.2021.10.20.16.23.45; Wed, 20 Oct 2021 16:24:00 -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=@kernel.org header.s=k20201202 header.b=Czf1Iwhw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231214AbhJTXX4 (ORCPT + 99 others); Wed, 20 Oct 2021 19:23:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:55950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229998AbhJTXX4 (ORCPT ); Wed, 20 Oct 2021 19:23:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5C7F760EFE; Wed, 20 Oct 2021 23:21:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634772101; bh=/xqLQmjienSp554eHZIl64dYoKQyTBAnqNBmKwd5TVo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Czf1IwhwdwBivekNEoZ4zSrEU1bcDZnOAyKxHoNMQAdb7pEc5KqzVht+3ZUK4DHya zDkXroTJADOkSVoKEtaT0JkWPtFk65msl20ICX8S8zMBnd0HOx9Y5Ft13QEz6EJZWw be+Q4DqzRd/kuTpH8FOLIMueaY3KpIiVnJU2nH1sCUsglO2Cc2aIj1K9nfM8M1Z4+o aMQD+DvhDOdKGJKny8dJL14MxlQR5tmulKbxCC1ZG3Hs/5AYzNmbWcsU96nD47/Mom x2GDv9nboHIv5vCY+3Q4MfhFP4+8sdmJ2NpEmnQAvvQSJz0BU0mfpxTvHqUZJ2zTHW niWiU5lGZKs1g== Date: Wed, 20 Oct 2021 18:26:20 -0500 From: "Gustavo A. R. Silva" To: "Gustavo A. R. Silva" Cc: Len Baker , David Howells , Marc Dionne , Kees Cook , linux-afs@lists.infradead.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] afs: Prefer struct_size over open coded arithmetic Message-ID: <20211020232620.GA1314964@embeddedor> References: <20210919094432.30510-1-len.baker@gmx.com> <8664159c-b986-64b0-13d1-b2739deb159d@embeddedor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8664159c-b986-64b0-13d1-b2739deb159d@embeddedor.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 20, 2021 at 07:09:38PM -0500, Gustavo A. R. Silva wrote: > > > 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 I'm taking this in my -next tree. Thanks, Len. -- Gustavo