Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1014763pxb; Tue, 14 Sep 2021 14:08:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxa0GT1am4fV0+bBJoRdbzmaF4gqs8qc3S3/Y6wHjxmdqr3LtUfdgkawEoRa16faWa+Ue2N X-Received: by 2002:a02:3f47:: with SMTP id c7mr6501431jaf.110.1631653698002; Tue, 14 Sep 2021 14:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631653697; cv=none; d=google.com; s=arc-20160816; b=rIB6Q9FpE55muG9Xu9x5wBc8V8Bvo4gChJFgp3F/WobLMVz12OnWn8B3SVxbmGyFKO 6xWlD/Yj6PN/ryAHLa6YFjmRs1/BZvT6fEqZ3ZB+aCULodgfKTAX+g+6JA5nZxaDID5p Uo6IbxGj5lPd2RU6xn/MJkyOHZwB3Xnf2GwgK0XNEXICGyjeRibz3ctDTI7LCOZ6lG8h u5kuR62IYhNqji+WrGsRKbdVtEOymuRflUACnFDztk6ilAC4Bob9V+vidOzRC0+mYlB7 nsj8SpUJQK4UQNIgDT0hChUxrW7pOP0bRwX0sWnJhYmBgqP+SREy8pXBq4HjDQ53YtIJ 9K5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature:dkim-filter; bh=aRIuKcelosoK7HSq+GC2ST2aT0MMYO+BBP+OHR42Tnk=; b=iRc5fhOKXNbrRDlY4z+KtgsRHcYYbtNnV3UZ3+pVD8omYDE14ieFtf+h0+yRSQ8IYY xaSgz44fLDIU+PV22tKDiXIvDZgyL1GhaRwJEfWULC0xVfgmgVT0Jdiif5IWsr369pQK Cg2yMYq03g5g8dSgm6Kd77MwjEDCCFPz/5FROGUeVVbC00BiRfY8ZqwP5nFECrh8CuNL ksYjJgHUqNwYg6Ff1EJO503LYWj6ZhUkD9liryGbQC7Do19PC55So6+f7EcovUSZpO0p jOX8gKUf/ZO+V1/QSBZ0PRbIPVRjGvkFmD7mKFyd1ShZNu0PA01yty4Z5Z+C2fJmNrfP 4atg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lwn.net header.s=20201203 header.b=DF5eyEPC; 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 t24si10091358iog.114.2021.09.14.14.08.05; Tue, 14 Sep 2021 14:08: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=pass header.i=@lwn.net header.s=20201203 header.b=DF5eyEPC; 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 S234245AbhINVIT (ORCPT + 99 others); Tue, 14 Sep 2021 17:08:19 -0400 Received: from ms.lwn.net ([45.79.88.28]:41268 "EHLO ms.lwn.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234059AbhINVIT (ORCPT ); Tue, 14 Sep 2021 17:08:19 -0400 Received: from localhost (unknown [IPv6:2601:281:8300:104d::5f6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ms.lwn.net (Postfix) with ESMTPSA id 49BE92CA; Tue, 14 Sep 2021 21:07:01 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 ms.lwn.net 49BE92CA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lwn.net; s=20201203; t=1631653621; bh=aRIuKcelosoK7HSq+GC2ST2aT0MMYO+BBP+OHR42Tnk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=DF5eyEPCSfnJMLuEitlrBN1ofw/Bm9eNbLjJM8hQ3CmUUW2YVzeW2shBm9HLfu/5p Ob6ojTKZEIP2RLq+DBTXEG1CHIc2Atym7cUat3XVjFfTbpBdCewoXlMjUKLHolV+kN SZI8LixJab3flQHeGvMOxYiWlgTNtIbvABZGhQZCOR9lNxyuygNjGn07Cyiz8QK1Aq gE7v+nb/TU3LATeSEfi1vjbwGIjBpyO0tV/xvajH5iFnIpIwlFZ0YLFm4vz4QQh7rt 8iDwky8DJB4GwbGY0mVnX3zVRkXOF0hZY5OnhcQAwQfZYHRXNc4hPngv2JcScbOfS3 uB5rT4GTT+VOw== From: Jonathan Corbet To: Len Baker , Kees Cook Cc: Len Baker , "Gustavo A. R. Silva" , Joe Perches , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2] docs: deprecated.rst: Clarify open-coded arithmetic with literals In-Reply-To: <20210829144716.2931-1-len.baker@gmx.com> References: <20210829144716.2931-1-len.baker@gmx.com> Date: Tue, 14 Sep 2021 15:07:00 -0600 Message-ID: <87r1dqdfyj.fsf@meer.lwn.net> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Len Baker writes: > Although using literals for size calculation in allocator arguments may > be harmless due to compiler warnings in case of overflows, it is better > to refactor the code to avoid the use of open-coded math idiom. > > So, clarify the preferred way in these cases. > > Suggested-by: Kees Cook > Signed-off-by: Len Baker > --- > Changelog v1 -> v2 > - Clarify the sentence by changing "keep out" with "avoid " > (Joe Perches). > > Documentation/process/deprecated.rst | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/Documentation/process/deprecated.rst b/Documentation/process/deprecated.rst > index 9d83b8db8874..b5a8be914178 100644 > --- a/Documentation/process/deprecated.rst > +++ b/Documentation/process/deprecated.rst > @@ -60,7 +60,8 @@ smaller allocation being made than the caller was expecting. Using those > allocations could lead to linear overflows of heap memory and other > misbehaviors. (One exception to this is literal values where the compiler > can warn if they might overflow. Though using literals for arguments as > -suggested below is also harmless.) > +suggested below is also harmless. So, the preferred way in these cases is > +to refactor the code to avoid the open-coded math idiom.) Sorry for being so slow to get to this... honestly, though, I've been staring at it for a bit and cannot figure out what you are trying to communicate. What does "math idiom" mean here? If you are trying to say that using literals is *not* harmless, then perhaps the first part of the parenthetical should be taken out? Confused... jon