Received: by 2002:ab2:3c46:0:b0:1f5:f2ab:c469 with SMTP id x6csp108621lqf; Fri, 26 Apr 2024 00:41:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXUhr2ML3i9+SP5sXXWpFM8oa95esBbyGPehUwZflDzVoBBJohpA0yOujNnNx5ys2Mwn8NyAP4Escf58bbFdSJQrt/7S3pzxVY8RTXRaA== X-Google-Smtp-Source: AGHT+IFq7DTcqmVgijOjXIgx1XAvg/wlroySo8HA8TNwWxNlmGxdvHvXdj2dmSfyqp3exul0v/VW X-Received: by 2002:a17:906:3511:b0:a55:b487:5676 with SMTP id r17-20020a170906351100b00a55b4875676mr1526750eja.72.1714117275426; Fri, 26 Apr 2024 00:41:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714117275; cv=pass; d=google.com; s=arc-20160816; b=HE5Aufwl2G6GykC1E98jtrCbnsOCg537Rvxs1glS20axHBpTNELY4I5J3S+UcuBq2T jqVc9fngdhy76e7jhzVY/4Ef8INo/wmQbq/ovF2gczmcxOv7qYxPpYPrdaJ+CX2SMd3z E+KiGnkUfpvIorPx3326DwzUFWuCCRj9SHLUs8klFk0g13BlXZrnSlKGp07LzUYHAVcs 9b78P6ELV2cg5WlfI0a9NnDN5g84KHhJDKSsoN8PQqPYs/sMnIBesRZLjhRFQV+5Pns0 Qrr+EHhuAm34WGIgExgiZn+D/3JD0/ofyRuR9LDKzn3PDMTQSTGoFZzXZ7MN3dzMOYpd HHZg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:content-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:cc:to:references :in-reply-to:from:organization:dkim-signature; bh=8ckphtQtVPyzmtTEJZjcavjTJN2bI8fj5SZ69O4ugW4=; fh=lbDB8EZgXtiQdUEvBaYtnj4K7bBAB89Qlx0lNnuh+ek=; b=Dz+Cv3J/N0njKK5T0MzgjmLe5vEeUYaSKaJQ+6b4EqVKFN3GDyY3uNg8qMdqBuznzS FmHv4a/U7KdQaPzKzjG+dKsuVA6d4Bkwt/+EwEDkmV7oxJTBILuFno2WB9DC3IuJ+WzZ fYsD1q1q++Xom8x6Jzjf4knpckxOou2deZliTAFOsmJWTjHFYGbKtxMfRW/tnVbVe4DV 7HCNDgNn/xJi6PxFvLWX83+mAUGsRfUL2/mEho1xuZiWac4Ycetubm0b++CklC/zwjI1 k7whoJVkQKkOBit/9yQX2OuXCSvNxKDrzcjMJqKmktATDC04Shug1jnZdGsbsGs9WB+G 2uow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="H+D/jY9/"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-159646-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159646-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id hs14-20020a1709073e8e00b00a55a8b88897si7866137ejc.1042.2024.04.26.00.41.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 00:41:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159646-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="H+D/jY9/"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-159646-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159646-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 2C1A41F23148 for ; Fri, 26 Apr 2024 07:41:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06A1713C66E; Fri, 26 Apr 2024 07:41:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="H+D/jY9/" 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 98FD922338 for ; Fri, 26 Apr 2024 07:41:01 +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=lcbxTclc9US33XeKpAuf7mY5/Y9NjOkCgC0amQc/PFAYmpieg4/jQVsrXglU8fFRQZovA2UJOskh0epCSjUcktuxIgy7mbC4zNVSpoeDJ2r6fmIEk10W55wV0b6lB86lmdAk2O2CwBSDCHAHgbw3z7w0pcXvJSC/5ZuNerHn0DE= 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=H+D/jY9/; 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714117260; 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=H+D/jY9/q8qJURomNwhM+GWgduOb3rLGILmdz9LBCHhfgO08opaP+LsFlvpwO7mj7gZWNb QT/aZu2o+8h8u9JwHHCmgAkWa3OTwoICHjz/pAb2Wjv2zwDPVeLoaJ1e00mhxKAMO0H5N8 NKqGEr/mu4xFVJ4ShVgSkyElaIhQaC4= 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-kernel@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