Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp363764rdb; Tue, 23 Jan 2024 01:54:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwo8FXdVzItRw8xaQVBLSxaEt8l9KU+vpjSZS4crDkdEl7boqfVyiLf3J7afMy78NC3Oen X-Received: by 2002:a05:6808:f06:b0:3bd:bf13:c7d8 with SMTP id m6-20020a0568080f0600b003bdbf13c7d8mr1777196oiw.4.1706003646876; Tue, 23 Jan 2024 01:54:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706003646; cv=pass; d=google.com; s=arc-20160816; b=ool7JJQRYSJnKqetwIvCWeeMgSmF1dtuUJk0tpOlwCHN86GUbTjoTmCXt5y1t9HCqX S0Omy3SD+cSX9/1DaMeWw/gPc0IXQBtq1FQnqIXNBNAilC0FB7Ml+dJYaV1H6hRafazO 9GEolo12RlN3aqwDzF0ZMpL5DetB/YT6b/4opatWnPJ9wJuTzRk7+E34bnI1UVpjcCrH fFWE+RSglChwWYDEfdA0BBRD1uuXs8YhheX8FbenIrqXBDhNGHVAlebypJbAUC1fB0+W ggM+0QoCM12wcVtVMXMr99FOOb/DOZ0Vb39ziBUKL0lKf4swmq9O2hrHfjBRM0ocbbB7 SS8g== 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=nkgV4LR6Y3GjpwYvx2b3E0S5KC48YZEl1ocSP1eqXg0=; fh=lYJ+WgdFs/6ZdBQDigKOmGaJZSXgZLgm4Kk9QkTKXSc=; b=frjnyZ3KIdZOwELBfJ0wLZ6pdGlRbi8e3UR2cgnSDRf007V6PCG9D/YrzYfsModp55 qgfkLL2Yk8958TL5RqCIlFeiJsYFkVMlUzjhLTCnaCvIY5ADpiT2wo03ZHgoLFIDmPsq MQdLK0owjTOWk+7keAb3RGakqK44vldiYbJKS0s1qb0n2y6EyVi5Fgoi3VIB4cd5V4le C4meWpA4wZ+lEo8DnrggyU/cVfmLjQHreTOYeODnd+T6Mz3nLBctrI+jR07NlMzgTqKb Rm6xuHX+nOSp2FlEGTDX1taF5OPkog4ZGIGgWuXvv42Y3QCEsphBD2dV5NsMF/DM1fNv KI8g== 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-35044-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35044-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 1-20020ac84e81000000b0042a3f505199si4132574qtp.108.2024.01.23.01.54.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 01:54:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35044-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-35044-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35044-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8C1401C22BB7 for ; Tue, 23 Jan 2024 09:54:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1FCA059B7A; Tue, 23 Jan 2024 09:54:00 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D9975A0E1; Tue, 23 Jan 2024 09:53:57 +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=1706003639; cv=none; b=OvVOB1odNxO/5IUqezOw9M7kPmhZrtKnekQ95T6WWvhhxAjEncIqPZ734JJeXfQXILKtHtN4rrb2Ike+8euv2Nz6OT1MABXRHQXUHf7r4WY9ciiOsWAJdbYVMWYJrp2asXyF93kr14PTvulN9CqlOBuFRUbktSqIWJlFUneRMVQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706003639; c=relaxed/simple; bh=6I1RyUH8EJbIPoPIXyA3hEnC5RVsu6NE5fOFPtUVz70=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jQ6qmX1QDvlebCm/o9ZjJt70giMBhDXfWHK+SdQf9VC6WCk5iyoh419hGUabLZhbxzTsL/GogNdHl/HlUjBkJk7mRylF/Uxz8qj0t0HVTtLfBcweotXRMl3q8G0uqtmQFkVTTu2gbTpHxj5vv7hz+72w+F0MBaUyonpCLj2LRnE= 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 15AEB1FB; Tue, 23 Jan 2024 01:54:41 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.48.47]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E68F13F5A1; Tue, 23 Jan 2024 01:53:53 -0800 (PST) Date: Tue, 23 Jan 2024 09:53:51 +0000 From: Mark Rutland To: Kees Cook Cc: linux-hardening@vger.kernel.org, Will Deacon , Peter Zijlstra , Boqun Feng , Catalin Marinas , linux-arm-kernel@lists.infradead.org, "Gustavo A. R. Silva" , Bill Wendling , Justin Stitt , linux-kernel@vger.kernel.org Subject: Re: [PATCH 11/82] arm64: atomics: lse: Silence intentional wrapping addition Message-ID: References: <20240122235208.work.748-kees@kernel.org> <20240123002814.1396804-11-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: <20240123002814.1396804-11-keescook@chromium.org> On Mon, Jan 22, 2024 at 04:26:46PM -0800, Kees Cook wrote: > Annotate atomic_add_return() and atomic_sub_return() to avoid signed > overflow instrumentation. They are expected to wrap around. > > Cc: Will Deacon > Cc: Peter Zijlstra > Cc: Boqun Feng > Cc: Mark Rutland > Cc: Catalin Marinas > Cc: linux-arm-kernel@lists.infradead.org > Signed-off-by: Kees Cook > --- > arch/arm64/include/asm/atomic_lse.h | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/include/asm/atomic_lse.h b/arch/arm64/include/asm/atomic_lse.h > index 87f568a94e55..30572458d702 100644 > --- a/arch/arm64/include/asm/atomic_lse.h > +++ b/arch/arm64/include/asm/atomic_lse.h > @@ -79,13 +79,13 @@ ATOMIC_FETCH_OP_SUB( ) > #undef ATOMIC_FETCH_OP_SUB > > #define ATOMIC_OP_ADD_SUB_RETURN(name) \ > -static __always_inline int \ > +static __always_inline __signed_wrap int \ > __lse_atomic_add_return##name(int i, atomic_t *v) \ > { \ > return __lse_atomic_fetch_add##name(i, v) + i; \ > } \ I'd strongly prefer using add_wrap() rather than annotating the function, i.e. make this: static __always_inline int \ __lse_atomic_add_return##name(int i, atomic_t *v) \ { \ return add_wrap(__lse_atomic_fetch_add##name(i, v), i); \ } \ Likewise for the other instances below. With that, this looks fine to me. Mark. > \ > -static __always_inline int \ > +static __always_inline __signed_wrap int \ > __lse_atomic_sub_return##name(int i, atomic_t *v) \ > { \ > return __lse_atomic_fetch_sub(i, v) - i; \ > @@ -186,13 +186,13 @@ ATOMIC64_FETCH_OP_SUB( ) > #undef ATOMIC64_FETCH_OP_SUB > > #define ATOMIC64_OP_ADD_SUB_RETURN(name) \ > -static __always_inline long \ > +static __always_inline __signed_wrap long \ > __lse_atomic64_add_return##name(s64 i, atomic64_t *v) \ > { \ > return __lse_atomic64_fetch_add##name(i, v) + i; \ > } \ > \ > -static __always_inline long \ > +static __always_inline __signed_wrap long \ > __lse_atomic64_sub_return##name(s64 i, atomic64_t *v) \ > { \ > return __lse_atomic64_fetch_sub##name(i, v) - i; \ > -- > 2.34.1 >