From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 4A3C513C3E2 for ; Fri, 26 Apr 2024 07:41:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714117263; cv=none; b=gLAmnpE38XcqXXiisTVZkhEeHKnMFbpjhEomtZ7lANoDYcheofiMd0ETNMwK08m85s30vWlDA9+qfDidLFYpITxRgf51zOLo0XYGdXQHmtDl1O+aATwmN9SVGbVk8xGfUPh9rlisDP70wqqbj0OT43IvalIWMoMBf6ScOsXaFLk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714117263; c=relaxed/simple; bh=a33sSvhsy7w8Kh3QHnL7F3iWxGtqcRtc9AZE85+hn7Q=; h=From:In-Reply-To:References:To:Cc:Subject:MIME-Version: Content-Type:Date:Message-ID; b=iwlNk4vGyw1puzqhbhjZSPgQYG8JpXZhaHDhZDRVnF5pg9LZ3Zck1OQ8QRE3XhdR/03Hx01pH/Fy/ymBWO+WxFGy4K2X8oHIfA6rXnPcB3kcyDSVdWg1w6VLBAN+rkHzhsUHWLO0J0E7T5m+4fAnySJVX82qU2341ptbFYDwfQc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=OhDo7d13; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OhDo7d13" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714117261; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=8ckphtQtVPyzmtTEJZjcavjTJN2bI8fj5SZ69O4ugW4=; b=OhDo7d13dVnZN6Wj2CivFup0zHVM8A8amLGsFTLPVCS9q6EU0mN02oi8eA9vUD0xZdyypx R7epW+TxI0bUawCJCVYlKUXN+Pd1KG4PaNUoN6r5RbcehET3polI5tK3I+SPE06T3VPjER iiRnaRnkqsaxxNbCrjiHvNANSAbOOxU= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-280-Pdjurq_MNPGagr7Tk27mhQ-1; Fri, 26 Apr 2024 03:40:55 -0400 X-MC-Unique: Pdjurq_MNPGagr7Tk27mhQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 993BE3C025B3; Fri, 26 Apr 2024 07:40:54 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.200]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11903C26A4D; Fri, 26 Apr 2024 07:40:50 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <20240424191740.3088894-1-keescook@chromium.org> References: <20240424191740.3088894-1-keescook@chromium.org> <20240424191225.work.780-kees@kernel.org> To: Kees Cook Cc: dhowells@redhat.com, Mark Rutland , Will Deacon , Peter Zijlstra , 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 Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2100616.1714117250.1@warthog.procyon.org.uk> Date: Fri, 26 Apr 2024 08:40:50 +0100 Message-ID: <2100617.1714117250@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Kees Cook wrote: > - return i + xadd(&v->counter, i); > + return wrapping_add(int, i, xadd(&v->counter, i)); Ewww. Can't you just mark the variable as wrapping in some way, either by: unsigned int __cyclic counter; or, to use rxrpc packet sequence numbers as an example: typedef unsigned int __cyclic rxrpc_seq_t; rxrpc_seq_t tx_top; Then you can get the compiler to spit out a warning if you use <, <=, > or >= on the numbers as an added bonus. (You should use before() and after() instead). David