Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1258375rdb; Mon, 19 Feb 2024 09:03:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVy2eARQeoq0U8Dgd+YGpA1p7XKusHbpzBjtEHprb4HQ0CoHG7JaSZA5FhcCCYVaaDjf+RG1HOg29jAdjA4kN/6y6kCDq2F5b6jrjlDjw== X-Google-Smtp-Source: AGHT+IHH+dDn/s4saE3jyNAc6Ihe2bn3vpLFOp3jOGFxeugaAOohKpDTfzbxtKGGioRyqkAjcfO0 X-Received: by 2002:a50:fc02:0:b0:564:5973:56f2 with SMTP id i2-20020a50fc02000000b00564597356f2mr2789345edr.7.1708362190332; Mon, 19 Feb 2024 09:03:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708362190; cv=pass; d=google.com; s=arc-20160816; b=GFNRQJzU8NpOkujrkqRqpi1a6hU/JgfPAmLFp9xkVPeajVEBq/FakCC+vIxY8uMyJy YXQB+tPs/56MtYH85hq91XzhUUcGIzeWU5A8oN2QySgWLSL7055r2rh5bis68K/O/Pv3 o+2Xhb1EDsYKPJIbv3ydsyGX6CnvYVkUoIrQAd1Nob4FvKiAW7lDif9gopwhQ6vsogSW in+8lucnV6ltSQYohM9WuGoaFMSuvoVp5TpTCk81DvftU3q7NjOrpVLbhcnP/EJs2EVJ q0Eb9pHedQ4BNXki6AaJ2Z+39TXpZsSz0IiAZphB4xvmM1x+9pN8HsSdg4VNPNLva2Ud +QOg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=tV5Dx1RkSZGsrXJ5YM089Hvw2rJlLS2jlUFxilnLmJg=; fh=WxqRNWYcdVanQXxcbG325XIyhRRuetlUFCQrXKdu8jo=; b=Jx8ePHoRkx76Up+XUkHKrWvGWAp0oU21/X/c9oATndelT/12UkStJFN1PkFxU60PnP RPrVsiOm+gINugqzdHoXFcAAwmNaTxMbpKIRWx1pUtVEfKEi1/TN9qbOE8Z7TDHgk2A+ /F7vyLOxnCbVQVoBwY7yc2/pw6iKwjmXQw69na9JyEQd1Ed6LnIRHW2dPTFoEkGNtWyl ygbIXipsKfqz0WvuzffLZ5pK3JvRA466E0+xykbEjyaFE52tmgbnTHXzKaZE8C6De4Od XLNhzTe+yiLytYHDEj1akhXK3y80+nYeOmZmAMMPyM5MQvyqiH8eGgQBmh8InghE6km3 TXHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-71724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71724-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z63-20020a509e45000000b005645c7dc5c9si1447988ede.364.2024.02.19.09.03.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 09:03:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-71724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71724-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1B78C1F253A7 for ; Mon, 19 Feb 2024 17:03:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A2618446A0; Mon, 19 Feb 2024 17:03:02 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 836483A1CF; Mon, 19 Feb 2024 17:03:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708362182; cv=none; b=ds9m2qBiQwK3QfyHhSFHQc3dWu2MtfkudnmmxIQUBAXq3z6aiLD5cJgO8cxBWHC2DkpezcuMgHbukHe6FGTmuzrU9Zj6ZUdZ4vZbdtD4r0U7snYWCJWu75f6P2RBPx6oia9Fqx4lef4pyChF3sVEuXz8jr5aSXM4qeQLkMHyhaw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708362182; c=relaxed/simple; bh=FDHavmdGhoIJckd4BTDH4LTUQrUq5xigNG4PkIe8dTM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EW4qgtkk6W2S2U8lM2N2P2m+36FBk/uwskRiR9WKD7FTFiq3wMQsfVyq7VeKyd8TzmJYYAhnbqWpvmwaWN9idhFGkJd2E7+t7ILAvKYfBEkw11o4KB/TyQmxqrbomxw6Ni3clGbVLuoDoojCW37eu1eiMnero+SONT649kXY8aI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6C281DA7; Mon, 19 Feb 2024 09:03:39 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.67.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 370C13F762; Mon, 19 Feb 2024 09:02:58 -0800 (PST) Date: Mon, 19 Feb 2024 17:02:55 +0000 From: Mark Rutland To: Kees Cook Cc: Andy Shevchenko , "Gustavo A . R . Silva" , linux-hardening@vger.kernel.org, Rasmus Villemoes , Marco Elver , Eric Biggers , Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 1/3] overflow: Adjust check_*_overflow() kern-doc to reflect results Message-ID: References: <20240214194432.makes.837-kees@kernel.org> <20240214194605.602505-1-keescook@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240214194605.602505-1-keescook@chromium.org> On Wed, Feb 14, 2024 at 11:46:01AM -0800, Kees Cook wrote: > The check_*_overflow() helpers will return results with potentially > wrapped-around values. These values have always been checked by the > selftests, so avoid the confusing language in the kern-doc. The idea of > "safe for use" was relative to the expectation of whether or not the > caller wants a wrapped value -- the calculation itself will always follow > arithmetic wrapping rules. > > Reviewed-by: Gustavo A. R. Silva > Signed-off-by: Kees Cook > --- > Cc: Mark Rutland > Cc: linux-hardening@vger.kernel.org Acked-by: Mark Rutland Mark. > --- > include/linux/overflow.h | 21 +++++++++------------ > 1 file changed, 9 insertions(+), 12 deletions(-) > > diff --git a/include/linux/overflow.h b/include/linux/overflow.h > index 7b5cf4a5cd19..ad64d810c8aa 100644 > --- a/include/linux/overflow.h > +++ b/include/linux/overflow.h > @@ -57,11 +57,10 @@ static inline bool __must_check __must_check_overflow(bool overflow) > * @b: second addend > * @d: pointer to store sum > * > - * Returns 0 on success. > + * Returns true on wrap-around, false otherwise. > * > - * *@d holds the results of the attempted addition, but is not considered > - * "safe for use" on a non-zero return value, which indicates that the > - * sum has overflowed or been truncated. > + * *@d holds the results of the attempted addition, regardless of whether > + * wrap-around occurred. > */ > #define check_add_overflow(a, b, d) \ > __must_check_overflow(__builtin_add_overflow(a, b, d)) > @@ -72,11 +71,10 @@ static inline bool __must_check __must_check_overflow(bool overflow) > * @b: subtrahend; value to subtract from @a > * @d: pointer to store difference > * > - * Returns 0 on success. > + * Returns true on wrap-around, false otherwise. > * > - * *@d holds the results of the attempted subtraction, but is not considered > - * "safe for use" on a non-zero return value, which indicates that the > - * difference has underflowed or been truncated. > + * *@d holds the results of the attempted subtraction, regardless of whether > + * wrap-around occurred. > */ > #define check_sub_overflow(a, b, d) \ > __must_check_overflow(__builtin_sub_overflow(a, b, d)) > @@ -87,11 +85,10 @@ static inline bool __must_check __must_check_overflow(bool overflow) > * @b: second factor > * @d: pointer to store product > * > - * Returns 0 on success. > + * Returns true on wrap-around, false otherwise. > * > - * *@d holds the results of the attempted multiplication, but is not > - * considered "safe for use" on a non-zero return value, which indicates > - * that the product has overflowed or been truncated. > + * *@d holds the results of the attempted multiplication, regardless of whether > + * wrap-around occurred. > */ > #define check_mul_overflow(a, b, d) \ > __must_check_overflow(__builtin_mul_overflow(a, b, d)) > -- > 2.34.1 >