Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp738495lqd; Wed, 24 Apr 2024 15:52:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXd6/nYaUookdLhYzcd1G851FboD4/ZZ0xiTr6OQUsXb2LpVEyQE7C21Km1dmq9PHaP4xjARcu9gt4k9cD1eM+nVVvjf64K9ow8JIrncA== X-Google-Smtp-Source: AGHT+IHyqGc6aV8oRAsGUk0t9KWQjjLGj4+IkBSgzTmlKAkrR3ze8oMwvl3/aXFL/Qnt9F23Ls6K X-Received: by 2002:a05:6a21:2d06:b0:1ac:c8dc:3e5e with SMTP id tw6-20020a056a212d0600b001acc8dc3e5emr4938671pzb.24.1713999124744; Wed, 24 Apr 2024 15:52:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713999124; cv=pass; d=google.com; s=arc-20160816; b=oqyRA6d7twRMNaHbJiCm4Fhh1gsTKX/dhwpTQlEfy1lBCkL/WOLe/C814Gff/jzGsr L1av4Wjxli5zn7xTWTDrTUuxfZlUi3bYIYMeTgD686oUJnvN/hbRP+7WGZqu/ffTlsit chYTfTNpc3CnN69DLM2VEmDEo0KTpY4fxw34TKG5XUZWV2pdbjojp1zwtVaxyrVl9Cmz wZZGEujECleegxc5osIhBGf8P/mZfYfNSXUWOxdr4c1P2SiKTtOb4DB4K6xncEEeZzJz wiFUaZnC6SU851vUDYPLvMaxzecn8H4I6+4WP8WAu+BNc0lPI5ILIVE00EtUJ/XDGmjv PhKA== 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:dkim-signature; bh=uDrKK9MVu5GzHed4YiXOORHenuiRjCroUzkRtpq7Xr8=; fh=utiYzFb3RiUICF3u+8iAeY6OieAhY8VNVm1gII1PQfw=; b=nNs5sxHY5RD49OBXcFKaIeO8n4lRZ2U8kQv7dWL5dU0v2CPd0uo52C6/Ms+5nNMxs2 gBPNysWd9v/0qC7FXBUS7w/BsGvA0PXW0W8OgpN81jpGKnUykIDuwHa8LShchWSjCfjI LhXFDpp5ROlgXAB8HYiTSCITB1OoIDpJrrwlw9Yw6sXn9loC428gIxIOAUK0qvzTocLI C8N/Bjc5RntWz9V433E7/WeekwHQ8j9DONVk/3ecY+2zme4ZwtpwJ8n0vBDkoovRRi8j 8pIlx3VgNmrmAeHktvJWpuD0pdAzxa/FjhTuWURnErgaAJ5dTIrN9X2C8u2v52VjrAP2 pcZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=IILmx88m; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-157807-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157807-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g20-20020a631114000000b005f751c16a59si12272936pgl.657.2024.04.24.15.52.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 15:52:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157807-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=IILmx88m; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-157807-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157807-linux.lists.archive=gmail.com@vger.kernel.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 D9477286D13 for ; Wed, 24 Apr 2024 22:52:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB2DD16F0D1; Wed, 24 Apr 2024 22:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="IILmx88m" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A30D716E885; Wed, 24 Apr 2024 22:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713999096; cv=none; b=eWKc2W+gcoStE0SRov9o29++CFxnCfo8reTOvT4BVb9xm7oQ7pBKxUrnevwrAjLKEe7DZ8KRt/DLbdsbVZIxjTE/qwf5jEjuBZ3hdcmy2pBXfesmRdfl7wjStOEIc/yxDZqG2m0u1yyO2FPasZUj5TLJCL3i8DHvycfzyCwO6Po= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713999096; c=relaxed/simple; bh=0RsNjdeYSfUc0k8oq/Nv37S+nYzUNW+CoiEKuah2oCQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=P8ki4G3h1GwgLTAphsfSuIdQ303yBzkk9Ft0LvZaKEF3KaJP9qss4tVU0B9OI8+XefzoTfE85KzKRi8Jm7Ug8AQqVihhtfZONDRKpvv+oTVleylnVNpG1UStiulg6a7/JErYViwyMoxODFE3LLr/dAyzM4IjcMNu0svMdOmwmNw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=IILmx88m; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=uDrKK9MVu5GzHed4YiXOORHenuiRjCroUzkRtpq7Xr8=; b=IILmx88mD8vjiMwqrMmrre+9AR zlcY2kqPjYZncZiBJFj6pnDAU0ZhhuV4rlxSZ7HcxKqBCjBa6OOs5ocvCCax/S8NxxWj84EAxqbEL MFaNqZ2luw6imVBZuIGe/aG75GB7MYXZ5lbY0rcrAoNUxUNRBMpXuO1Am0ZJdsHYjENsjxw6Ycf9d 99F8TBD+1jTtbHGf1q71XtM4hbBSu5Sgx4e9bcidXHlwPBNvG5kZMloqH84s7AtrC9VybE9Mi1Ref bJ1tegqi+pDWrgGvKx5eWVrDjQV3HCkjx2HtVZHUWlmRO6p1QgZOtIk+xYyIuM3ifm9ITathoorRw g3AhKNoQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzlSU-00000001qPk-444P; Wed, 24 Apr 2024 22:51:23 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 8F02930040C; Thu, 25 Apr 2024 00:51:22 +0200 (CEST) Date: Thu, 25 Apr 2024 00:51:22 +0200 From: Peter Zijlstra To: Kees Cook Cc: Mark Rutland , Will Deacon , Boqun Feng , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Jakub Kicinski , Catalin Marinas , Arnd Bergmann , Andrew Morton , "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , "Paul E. McKenney" , Uros Bizjak , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH 1/4] locking/atomic/x86: Silence intentional wrapping addition Message-ID: <20240424225122.GF12673@noisy.programming.kicks-ass.net> References: <20240424191225.work.780-kees@kernel.org> <20240424191740.3088894-1-keescook@chromium.org> <20240424224141.GX40213@noisy.programming.kicks-ass.net> 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: <20240424224141.GX40213@noisy.programming.kicks-ass.net> On Thu, Apr 25, 2024 at 12:41:41AM +0200, Peter Zijlstra wrote: > On Wed, Apr 24, 2024 at 12:17:34PM -0700, Kees Cook wrote: > > > @@ -82,7 +83,7 @@ static __always_inline bool arch_atomic_add_negative(int i, atomic_t *v) > > > > static __always_inline int arch_atomic_add_return(int i, atomic_t *v) > > { > > - return i + xadd(&v->counter, i); > > + return wrapping_add(int, i, xadd(&v->counter, i)); > > } > > #define arch_atomic_add_return arch_atomic_add_return > > this is going to get old *real* quick :-/ > > This must be the ugliest possible way to annotate all this, and then > litter the kernel with all this... urgh. Also, what drugs is involved with __builtin_add_overflow() ? Per -fno-strict-overflow everything is 2s complement and you can just do the unsigned add. Over the years we've been writing code with the express knowledge that everything wraps properly, this annotation is going to be utter pain. As I've said before, add an explicit non-wrapping type and use that for the cases you care about actually not wrapping. NAK