Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4027696pxb; Tue, 2 Nov 2021 02:47:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5IiewDzSJ720qPK74TkNuMk3Jqgsq72QiFutIfZD/X9UTPL1maWH0obl81pdidWTNzKxP X-Received: by 2002:a17:906:6582:: with SMTP id x2mr44177136ejn.38.1635846472165; Tue, 02 Nov 2021 02:47:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635846472; cv=none; d=google.com; s=arc-20160816; b=uEXyndwRGOf8y6T/kJjwPh0CNngQmuTsd7Ar5/r4SVRTVC0OzpPVbfFoBnC7yNWS4l 7edLtA+90CP6H6yFhjZuHGRxMYaUk0aB2O2OWSkQUEz4Dbt3RE4Bz17f7eH2DM5myqmf fEx6LK4QJxzAn+pAAmue3RLrmCLrnvDk1O2u1c/rjchS3ixsGiZjOjyvCVznO8RE/+kW 7n+Wlc6feCtEKCjlQO/w67yZWBl3IoPxISDv6qt0Yu0gzPk+XEDUXmaQ9B6RVy66bg7a 8l6C2Egak/Hy56uidOWqEhI2Mgy9jbiK8f5Ua550z3d6PzJcIZD5Kh2lvgOnPWYJSSVm bkQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-transfer-encoding :content-id:mime-version:subject:cc:to:references:in-reply-to:from :organization:dkim-signature; bh=nYxvqfKyKtI4tu/9sa2DOgaLzeCCe5kytXHcdT7EDvU=; b=j30juPQgG89edng1gPW9D0Ii0WBIeTwsH+Z6rgz8f2y9w7IIPyUz3b5utJLWb+ToPe S1LppcR/Y876MazaGSEjocPwP+Rgzm3wsF4SyFJ0mYh9Ue/uckN98aq3w+pNw2FehQU9 SQJA+5SF+BaQ+wvYregWCZl22+8vaACamQkAzjF3WzHcl7I1mKODXwDrYD9lJZQ2LBym Qj4Kj2qsv8A3IAIRyF7MRcirzU0NP4TDwx7rAPmGAlkmmWQ90nfgmQVkjq4n6AZBS1O0 1FOJA/veVO/0RGzbUS5Xqm9RYFtEtRgPDeXfG9uWlVLYyNBFsEjSaLTEgiHO+w2KlS/h fLBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CPCWVN6f; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c67si17784632edf.314.2021.11.02.02.47.27; Tue, 02 Nov 2021 02:47:52 -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=@redhat.com header.s=mimecast20190719 header.b=CPCWVN6f; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbhKBJsL (ORCPT + 99 others); Tue, 2 Nov 2021 05:48:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56675 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbhKBJsH (ORCPT ); Tue, 2 Nov 2021 05:48:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635846332; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nYxvqfKyKtI4tu/9sa2DOgaLzeCCe5kytXHcdT7EDvU=; b=CPCWVN6fACV1mC3xIu4Uy1VVC7xrOCWoKUYxcVI7XBxY7XpjYlcA2guxLdUIvR0ti0Kjkj nJjtcqpNMSSxGMCVVtUCGw2gKKZhzx/E+uWkt2IaBtYAdg8X8oSN/EMBV31X4Wny2XO2BM kvVllde/20hF6DUXdRGTQpwgCayZgw8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-424-4x6F5WCcPPyxkNENe6Mihg-1; Tue, 02 Nov 2021 05:45:27 -0400 X-MC-Unique: 4x6F5WCcPPyxkNENe6Mihg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 40EBE1006AA2; Tue, 2 Nov 2021 09:45:26 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id A3F4A60D30; Tue, 2 Nov 2021 09:45:24 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <20210919094432.30510-1-len.baker@gmx.com> References: <20210919094432.30510-1-len.baker@gmx.com> To: Len Baker Cc: dhowells@redhat.com, Marc Dionne , "Gustavo A. R. Silva" , 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 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4028804.1635846297.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Tue, 02 Nov 2021 09:44:57 +0000 Message-ID: <4028805.1635846297@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: David Howells