From patchwork Wed Apr 24 19:17:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13642447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63A03C4345F for ; Wed, 24 Apr 2024 19:18:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hHPF9/wAz06pnLAKgDab/v5JVAU+ryx6wbaZjSeyoDo=; b=SZg3zG+dIQeHlW eeToCY8JqJCV6uaMBMJhOtnbBQJ6sUsPSu3bOTPKHoDqV1kx+nqy7b3hpwUdEuVV+xeenneXMgiUe NFe8wZEutTcfzZ0btQffqYWOIeaQXwLt7rrhtWoj8IpJRAKndOgztKm4fF+YHfblgpSRAU0pGVgn0 e7ofENidazhTahFaaYnzfJdy+4DQc7BKa8jYv5vkQ7Km4l8LstZuUtmRj7gDJGMopao+qImBG2Ms8 QmzZx2dt3eU4xmfzoLiW1pZArRKNvl4BlslfaqdgjJsyb37y/ljmMFHNmhROJiwHxwJl9XqNhCm3F ywtaUnxiowoqeqvg6pUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzi82-00000005cVc-1ICb; Wed, 24 Apr 2024 19:18:02 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzi7o-00000005cLI-0pSe for linux-arm-kernel@lists.infradead.org; Wed, 24 Apr 2024 19:17:51 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6ed0e9ccca1so286346b3a.0 for ; Wed, 24 Apr 2024 12:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713986263; x=1714591063; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/ovZNJsNh+Q5y3YBgmePtlPx3aXBNKsLPIMy6gD2e/k=; b=oU4Sa7CxQpScQbKHycL19PaVDy0GM2zgyxk4Sjqtqe+YMS+OZNskvepwxyzhitdwSf f+qkmoAmOQrvvhaJqgBB1+lNYoWZD+S/p6TON7moy+x9Y1UFePdGOE8lzz4+N0sr4+BF hmvp9uPFBN60aqwiH7vbXmYSuDS9LRwZCLDeE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713986263; x=1714591063; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/ovZNJsNh+Q5y3YBgmePtlPx3aXBNKsLPIMy6gD2e/k=; b=coy5AXWW0i4gN6Iz3r+myJIN03kJxTI+A1sKOAJfgOzRWN9mAjWVsonP8ljI5Md0b7 xpCAY6iU2MZVJJUXTZhpuzmQ+v3iyos+Zi/5r39o4aznM7tRqvctdVQgQqpTi1ot8nlh W2nDs7ag5zoBiMGlupG89PTupEkJ4hgHUZ+EqZ1AIVSnA2b29ejU4qjCozJL4h164PJ9 XAxzoZrnNSu32seXaBEMJzIcseqdhAJsenwBGQiA4pojLREtoDDDN/A5hGVi7Bj0Vlgm t+7bXfNJ1Pq/tGZQNbYQcCGniEAM665L3F0H41Kblkli21PWDGaqOQWUKWnofOd23vz4 NvPw== X-Forwarded-Encrypted: i=1; AJvYcCXTiYucMBuIfEZqG4qGrNO/3wv34mr0/hpbXWzFVwLHDBZyS+F171FydszJkMKIhbitwB4BqWaJ4FWpHjhywl3pTZws+PcmjG/ElO92SFtVEYQK1UI= X-Gm-Message-State: AOJu0YyShiTinX6tNMLuvZFWVdBl7haSEJXnCWo/coEwa6kPbNMb2Tf6 ptFHszlUZwSfH4+wbjMULzffdiFk0fHYwyQm77LFvTZ1gn52jHGH+UfIQIJdGw== X-Google-Smtp-Source: AGHT+IH5PxCoRC7r3PuTmsotsJWh4LNkWmqcpOxpDSEhbERbm5LugRo2mXC3N2+7jUPKaLXdawyW1w== X-Received: by 2002:a05:6a00:21cd:b0:6e7:3939:505e with SMTP id t13-20020a056a0021cd00b006e73939505emr4435012pfj.2.1713986262601; Wed, 24 Apr 2024 12:17:42 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id p7-20020a056a000a0700b006ea8ba9902asm11784540pfh.28.2024.04.24.12.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 12:17:40 -0700 (PDT) From: Kees Cook To: Mark Rutland Cc: Kees Cook , Will Deacon , Peter Zijlstra , Boqun Feng , Catalin Marinas , linux-arm-kernel@lists.infradead.org, Jakub Kicinski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Arnd Bergmann , Andrew Morton , "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , "Paul E. McKenney" , Uros Bizjak , linux-kernel@vger.kernel.org, x86@kernel.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH 2/4] arm64: atomics: lse: Silence intentional wrapping addition Date: Wed, 24 Apr 2024 12:17:35 -0700 Message-Id: <20240424191740.3088894-2-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240424191225.work.780-kees@kernel.org> References: <20240424191225.work.780-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2182; i=keescook@chromium.org; h=from:subject; bh=xwLB8JfQnGZ+68nfRnKXcpeprEGbIQ5N7eZM3lFRlVk=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBmKVrRbqMbwLvcfN/CYeO2dTbShkdvlexcHwL/5 YEg6VqdugyJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZila0QAKCRCJcvTf3G3A JmxbEACdESTOy4jkKFG20/bUsA+2niWwljmd0zr7tKnSdR7jpksWerZepL1D4SjqYa4O/LavsJ5 lFd/o7p1MTmSLppqZ5RNFhrAXffGJhvjZs/LhFSfihaH32GxNP/5smFSj95gTaKIgpghcplMG5J ByNnCX4z1k1dih5igMvnndR1vEj3i5zmohj/juFh6Gwur0F0eZDDT/hKmkzXLs89XHe4T8D+9mw +Ak5yTBAesLT4zSQ7cgFT4ihOnocVSo/S6GGmN4SNypgaWIWVr528R6/4/jlw2bssx8Sbkt2fZi vzwM8TMrof0cGiMS0h3BEPIlHo5o465p4D6Ns2/40gF9l/5yMIr2RrOIDyQisudC/hM3NGnrVt6 Rpr3L2g9GgwoqTupgCCes+a3Z/pL8Ehn2iwtlW3+8nMbU0vCQLI10C34kkBQyz7tzEuA+/d0yf4 EgjvKrBdM9sIoKmoI1sDwkDcII5r5mROTGOv4FEEj8Kh7W5aVZhk9k8uoYmuiYnG102+zY7hSe3 zI5EKKzAoFfA1FRCUqbu3rd/sdd9swVFJgjLylGG2OwkUn7DaH1HAEm4w05ft2MnZnWZmiuaoKS jPCSl6Ouz4rBGE4yLDtYT/3JLzIFZWH/GWFyXG3+I4o1/A6qeIn5xvfrkMOrWLLJby5smfXa2vt f4Zqx35NAt41MRw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240424_121748_307313_6B9BB34F X-CRM114-Status: GOOD ( 13.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Annotate atomic_add_return() and atomic_sub_return() to avoid signed overflow instrumentation. They are expected to wrap around. Signed-off-by: Kees Cook --- Cc: Will Deacon Cc: Peter Zijlstra Cc: Boqun Feng Cc: Mark Rutland Cc: Catalin Marinas Cc: linux-arm-kernel@lists.infradead.org --- arch/arm64/include/asm/atomic_lse.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/atomic_lse.h b/arch/arm64/include/asm/atomic_lse.h index 87f568a94e55..a33576b20b52 100644 --- a/arch/arm64/include/asm/atomic_lse.h +++ b/arch/arm64/include/asm/atomic_lse.h @@ -10,6 +10,8 @@ #ifndef __ASM_ATOMIC_LSE_H #define __ASM_ATOMIC_LSE_H +#include + #define ATOMIC_OP(op, asm_op) \ static __always_inline void \ __lse_atomic_##op(int i, atomic_t *v) \ @@ -82,13 +84,13 @@ ATOMIC_FETCH_OP_SUB( ) static __always_inline int \ __lse_atomic_add_return##name(int i, atomic_t *v) \ { \ - return __lse_atomic_fetch_add##name(i, v) + i; \ + return wrapping_add(int, __lse_atomic_fetch_add##name(i, v), i);\ } \ \ static __always_inline int \ __lse_atomic_sub_return##name(int i, atomic_t *v) \ { \ - return __lse_atomic_fetch_sub(i, v) - i; \ + return wrapping_sub(int, __lse_atomic_fetch_sub(i, v), i); \ } ATOMIC_OP_ADD_SUB_RETURN(_relaxed) @@ -189,13 +191,13 @@ ATOMIC64_FETCH_OP_SUB( ) static __always_inline long \ __lse_atomic64_add_return##name(s64 i, atomic64_t *v) \ { \ - return __lse_atomic64_fetch_add##name(i, v) + i; \ + return wrapping_add(s64, __lse_atomic64_fetch_add##name(i, v), i); \ } \ \ static __always_inline long \ __lse_atomic64_sub_return##name(s64 i, atomic64_t *v) \ { \ - return __lse_atomic64_fetch_sub##name(i, v) - i; \ + return wrapping_sub(s64, __lse_atomic64_fetch_sub##name(i, v), i); \ } ATOMIC64_OP_ADD_SUB_RETURN(_relaxed)