Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp407440rdh; Wed, 7 Feb 2024 08:08:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IF0DJSiEczKxidizUHqCDRqTf+IazFbaeg6vzdCCSyHz8xtKgx1f4Kwb4D9FwzOGFOouoX/ X-Received: by 2002:a17:90b:3ece:b0:295:fd18:6ebf with SMTP id rm14-20020a17090b3ece00b00295fd186ebfmr3164557pjb.47.1707322105922; Wed, 07 Feb 2024 08:08:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707322105; cv=pass; d=google.com; s=arc-20160816; b=vlCxY9juKgp633sDUmMaBNWJ+ZPrQWMc3EUcFbpLHtgQDrcdbhelUATnYreZWS0Nmo HuFQItscUZFrDDAHDYaeqjKzVFatfbKHPVjXmtTNYJYG3XebGVKszNAiBZmpIcKk0x2t fV3ngJQtdn7CL1yNYh3k5U4NwumuAwX5iV/usuZJQF2/XBEUdsB0nZjFHTcfT/114Ln8 fcxkAiSLvQildvK8aI9YMHzAqAcgA0uneE81bTxc8Vu5ebNPg6Fk5QqGmqjLdFGFwhZB L8+MkfR0RPLOMYNdqMDGXz7PrSLR3e+hzXdsVoHYjRRE778oBMVduokqUe9wVhqTkkBf HqIA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=TPcc1Z5tbUu/YfL1Zy2MeFweBmwTVf9DFXiNZ7Rr3v0=; fh=5hhQ97D5ObiWxYUjuRRU3SlW9fvDMau4EZTla0wc2K8=; b=RJWNCbn55sKpjBGPg2rYXRN/RVUp393ocfgZoOsF8FIXcnjkTtnSDG7aOApQ/4NfFO QBigfjGBraFtRUqZEGF2DZC/HfHL8MeylD/PYdsNMrzp6yqTkUGOPAIn/z8de45kjUnw txWRENbOJ+XeP3pcqrJh+DBSZtONNWlw0iocbEQ4FvU5vFLNrHevxzo5QSEbCaVCzJFA SA2j1+Fs1G3rLzYTSI7CmbCGEAD3GBWiRiOsB1Js+PiUfC82RwW/qqYzDhgLm/Ce4/yk owRr/nf0V801u0fGly+sBDHiAg9pT1pjMjh4DcG27SnghyQuaJgL64iibRv4qfZpQT/9 hbng==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=oCObCT43; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-56751-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56751-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=2; AJvYcCVok/Fi7Fh8gdFSUkyKsVzeNlt/qP1PWOiFut7qtZhkGmMeE7/QqyRp+t5az7hFNC/OQ/Hmt+d4rJ3S8YOuxE49V8J3XaqCKV4QMUyK+A== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ml14-20020a17090b360e00b0029689f75831si3557692pjb.40.2024.02.07.08.08.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 08:08:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56751-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=oCObCT43; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-56751-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56751-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 923CA28BE14 for ; Wed, 7 Feb 2024 16:08:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 980A080625; Wed, 7 Feb 2024 16:08:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="oCObCT43" Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 671827E596 for ; Wed, 7 Feb 2024 16:08:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707322098; cv=none; b=bbRjPd5oNRJ4dRqjGMUsv/7ZjB2yhD2v4L0XEYmNthDwdlB9rnqVa/UJ646v/MLBop+YDqABo38FtZmCxQLrUN9pXabp8v3EudJlQ3dnR5oAuuNZN37u4Xt382S7fg9NKG6DM9LoUwLc3YKxtjP9/UgvZYyAv88livWdr54dVLU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707322098; c=relaxed/simple; bh=Kd78ByyFT6a8YEwO3HZkgmw1fSvzekjxNAWgwK42edo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mrctTJUHquG5t5EOD9jBhp1/Ldz2gcsqrNJhAHiI+Vq5D6ENGsx5s9WTixLXTOIl7C76xNwnM0xu+OyimY5JtagHC1Za7q+mPlB2EzD7F3MRVCte2x3zRku3CGfsziMqM+Zh+nTXFL/o1iw8fEmADDRJCayxnMhL+2vhr+MqzAA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=oCObCT43; arc=none smtp.client-ip=209.85.215.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-5dbf7b74402so457803a12.0 for ; Wed, 07 Feb 2024 08:08:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707322096; x=1707926896; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=TPcc1Z5tbUu/YfL1Zy2MeFweBmwTVf9DFXiNZ7Rr3v0=; b=oCObCT43ZFjoI6IPa0YJJXy4VxMPOEoRZeWyvb6+NgzlPBsuajpllOkErMuitTwLEt vh2ApUiEfXSNyT5fLTuH1hDKOHY78sLutfVcxy8vWvqpDo8tyz3sUPIlefHzCR2IgHqz h9iXhRN0cZhM7pCYfzYIoTfAUi0eG9NVbrjrM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707322096; x=1707926896; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TPcc1Z5tbUu/YfL1Zy2MeFweBmwTVf9DFXiNZ7Rr3v0=; b=LtNDaa34kdSTOrRsaNiIcVkwXwDCyrBtYy8Ag8ORXDLT2jr2lp+hBpGHZ9vj50whAV mXUwsGNl4RU174X5AclByy3pidx29gDWSYR5xJ1fRkYx8wRSJP/y3Tvy9+MvpVYaREdz 6HKEeISMQLN886U4pJf05bKQL2FGMdVlFcatvyEI8psu4e4S7434dWS6J89Rm3KHawFe 7sU+va43cSpH23shYBIF/9quTYYSRp46G8m5Qiov/bLYUhuk4BFGrkaJoI5xDEZAMQG1 Ll16yRxmYODkDX24kqy+fWELAk6AaUTpU6pqDAEeAHEACEDJMGxumuvL7CB/FTD6yDv0 i0Eg== X-Gm-Message-State: AOJu0YxBpXAMYzZpogIKYAe66wPEoyjjhYeBNsD1Ijd0GLPNgpdCpfXv FiF/e9EcCIHyiMhgjBlUQcz4cMbG/lMq6puXmJ0CE9RWCJDDAJtIgfZ3CkggGw== X-Received: by 2002:a05:6a20:4285:b0:19c:a3e2:58b8 with SMTP id o5-20020a056a20428500b0019ca3e258b8mr5608303pzj.12.1707322096615; Wed, 07 Feb 2024 08:08:16 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUS66k0uHq0b+5MwZzpaLXL0AsgXhY3IvIWBM9QHQ74huP9OpEpSRz771KZ1rqnVr8feMnwNO4Dxne8ARclmqWyEmUWtHsPkrqO6oy3zalSuK1uUr+zVkpIzIGv0WA96sX/0d30CXwOB3fo8/n/HBBzWIOrU9GhSa3XV/M6TCmXF+n3wpXTG8OKnVknN/0xKQEY8dIt8CfDPb+Ihqwtwz5+SRz1dmALXZBYMZbDX0ftsdnv5CMfdxIvg+LN7ogd+Z0wPQ9C+zu7BCVqOewH0RHjLL5+81muPt+q9dp/pXi2Elk3jM1Gh0dmL6Gx7hHMfCV5CopGod/9zQ== Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id y68-20020a62ce47000000b006e0545768dasm1800999pfg.151.2024.02.07.08.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 08:08:16 -0800 (PST) Date: Wed, 7 Feb 2024 08:08:14 -0800 From: Kees Cook To: Andy Shevchenko Cc: Andy Shevchenko , Rasmus Villemoes , Marco Elver , Eric Biggers , Mark Rutland , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org, Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 3/3] overflow: Introduce wrapping_inc() and wrapping_dec() Message-ID: <202402070806.445F7F7F03@keescook> References: <20240207152317.do.560-kees@kernel.org> <20240207152422.3855315-3-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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Feb 07, 2024 at 05:31:54PM +0200, Andy Shevchenko wrote: > On Wed, Feb 7, 2024 at 5:24 PM Kees Cook wrote: > > > > This allows replacements of the idioms "var += offset" and "var -= offset" > > with the wrapping_inc() and wrapping_dec() helpers respectively. They > > will avoid wrap-around sanitizer instrumentation. > > > > Add to the selftests to validate behavior and lack of side-effects. > > I would expect inc/dec to add/subtract 1. So, to me the terminology is > confusing. The list of the C/C++ operators on Wikipedia describes > above as > > += Assignment by sum > -= Assignment by difference > > > Hence the proposal is to have > > wrapping_sum() > wrapping_diff() I think maybe the missing phrase is "assign", which is what makes argument 1 "special" -- it's being changed. Perhaps: wrapping_add_assign() wrapping_sub_assign() ? -- Kees Cook