From patchwork Wed Apr 24 19:17:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13642448 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 EFFE0C4345F for ; Wed, 24 Apr 2024 19:18:15 +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: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:In-Reply-To:References: List-Owner; bh=tb3SD83oeD5SSrDD77Nj1XGpbQ9ZDhypvruyy8l9jak=; b=dDIJcQt3MJ4xuk VOXJBovRPH2Mt147y7PQ9T9jQs+iWTzptzQeiBhwwsUtJh2c2+81GGTZKK2JZaAcH9RVFSLVDj71l GamlXKzvZJmXfOAFQeOYkhqGT/YfdnI0ySqPEQWY98w2r5WX2vsG7EIbipVbVLBD1beVNYSYPlGq7 5llqB4Kzupb4QEW/MTIW9q3pQXED8QeaAsCdAjHOh/edoQzf4YyzDrUeCk6sIeQK3FVCpRk5B+0Yn 39eU7fviNRmwF7u5t9ZZvgo4va/0XQ/ihrSWHABpLx/ZoR2+TpRFs0WXp1djhNIT3EyCfXu1seCxJ sB92HZ2MLocXY0isVisw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzi81-00000005cUH-0WRX; Wed, 24 Apr 2024 19:18:01 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzi7o-00000005cLh-1MCB for linux-arm-kernel@lists.infradead.org; Wed, 24 Apr 2024 19:17:51 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6ed627829e6so297621b3a.1 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:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lK6fStXdfyST1TlQT33JqKtHmOFdPx874FRFgnYIMq0=; b=K5iLP34MwpNpFrCjjYXOPYGAtsrZDm0KlIgXTfdEUO3py2eD3nAt88aoc9yr1duBDZ HCQEUCqSReqmBlzrc5XlRThxPVsknC2F3Xv/QBONMu4WCopMDAe6ChhdoHhRLsnyEPtn vjM/kQiBrb7izQnWlVJ4VQH8uZMkctw68MdAg= 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:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lK6fStXdfyST1TlQT33JqKtHmOFdPx874FRFgnYIMq0=; b=vTYLuNjJDofdjGeu5O/LNEP1kk892MBTKbg4HO8IQVJt5GkxHFQxZMdBZE+wraJHQF o3eAFBjt/Zl+8AQ01N6ta9z1yjVAcNhL87IONUF2ecVhkbfP7JAs6TC5gf2SpXXmNBOv pvE9kSZAijUMF98hcMCwlXO/bVwSPl7pQE/xYXbFw24ulA4nFxdzIlALgq4jlP0V1FsX OwrvBRn5+MrMwaPQdREJUWrgNLMzSOuaqFnoy8Ylf1N8Dw2MoeMher7TuU/DYPkK4Sje lgUiRvlcT5zSWFtykyFUxzSwwFZzYBQqUWUDiw3I4KlqnRbd9r9tsYMet2RAI/cFJ4zf 3hmA== X-Forwarded-Encrypted: i=1; AJvYcCVvbkiPgBYK8i3fuZXBwKNx8C2C3wNpM86PUmJgSKvt9293NhnbCIKm2Z0HSJKyAMBvkBnx7hQ+dBXGE4avQWHlcVd1qSmcTIeUq+GzbdSDNn8gO60= X-Gm-Message-State: AOJu0Yx6xWwfI85yQLPBAJdJS2ZiVvkljWwJrusc1draGW4LrmnraY2N dEV1HfIM6R0jPG7bRH8zu8hennC2M/GsKc+YxDH0kD+TKL/CaROLmM+neBGTQQ== X-Google-Smtp-Source: AGHT+IGJLxaAQi7YYyI9XbiHvHbGRPs5if1SJBeA9ajOFNVl3JLCYaCGsqMFSmevBkhPO0HvlcVaaQ== X-Received: by 2002:a05:6a20:3c94:b0:1ac:e379:5548 with SMTP id b20-20020a056a203c9400b001ace3795548mr3896074pzj.45.1713986263198; Wed, 24 Apr 2024 12:17:43 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id km18-20020a056a003c5200b006efbc365de9sm11772738pfb.121.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 , Jakub Kicinski , Will Deacon , Peter Zijlstra , Boqun Feng , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , 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, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH 0/4] Annotate atomics for signed integer wrap-around Date: Wed, 24 Apr 2024 12:17:33 -0700 Message-Id: <20240424191225.work.780-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1984; i=keescook@chromium.org; h=from:subject:message-id; bh=thTGd+hT/FhiSvmm/b+nzZnBJHdZOOvS+xvizd9J118=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBmKVrQ9CtzJNlSzJGvLo6MaPqAU2ghmpei4/WPg q/q196TYOWJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZila0AAKCRCJcvTf3G3A Jk/MD/9b08KF50tco7aDBOr3+0y32I2X/aj83XHW9qi8joeu8U8WCW+0yQp0s09qE1TvMVnDUsS EmaaBlYOva9kFzL63LQCuJl4n83UUm5u/bZNye8GJpH/NDD6lIpip+WZC53FIZx55YclzxrknXa 7mu4138bls6ycciUIlHSFTrGcjphUCaw//r6fzm2MX78GftZKNCtURzKpPKCYivqGDAHaVKwego wHYUvRSi5QJCtIheikvkR2OTaScKZeZCAaWCokTIBhfJW5y+HZEpIBm9g23TIIb3AlQR7zO/SBg EMSdjJXPqeqfNVfWyP6QZo8ljWyXUh1ZcF68EriCKbaBWpd6Dwe7cwUwLeYuQr05KBTeJxqJ/4E A4VDBN+MQ+H5y68uRWT32gvAenZHYoIy84wLnukKJHtl55cBw7em3LxDyzApDUFoO0A7luGMnvf XLZ7RFzf7vX2Tjz4qQk0WfmujcwpCgiLtkrKY7pa97e2k9Be230TyBG9mhHnVgiZnnce3hAvzMc g100s4qtOfFkQub38z8Rb5f7Khr1uUDKdzDAnGpFG2nPDs5BmqNBL3dJW5hw1Or8MP6E08bQhdu 7RpghTVeiCyYB1WgF7c691itQEBxSBTDz3jZ959PdEaIVu77HU5Xf6kIoWBJVWjiKW1LcaILhIm 5OE1koy Q41ty9nA== 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_421887_80B5F163 X-CRM114-Status: GOOD ( 15.46 ) 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 Hi, As part of enabling the signed integer overflow sanitizer for production use, we have to annotated the atomics which expect to use wrapping signed values. Do this for x86, arm64, and the fallbacks. Additionally annotate the first place anyone will trip over signed integer wrap-around: ipv4, which has traditionally included the comment hint about how to debug sanitizer issues. Since this touches 2 architectures and netdev, I think it might be easiest if I carry this in the hardening tree, or maybe via the netdev tree. Thoughts? Thanks! -Kees Kees Cook (4): locking/atomic/x86: Silence intentional wrapping addition arm64: atomics: lse: Silence intentional wrapping addition locking/atomic: Annotate generic atomics with wrapping ipv4: Silence intentional wrapping addition arch/arm64/include/asm/atomic_lse.h | 10 ++++++---- arch/x86/include/asm/atomic.h | 3 ++- arch/x86/include/asm/atomic64_32.h | 2 +- arch/x86/include/asm/atomic64_64.h | 2 +- include/asm-generic/atomic.h | 6 +++--- include/asm-generic/atomic64.h | 6 +++--- include/linux/atomic/atomic-arch-fallback.h | 19 ++++++++++--------- include/linux/atomic/atomic-instrumented.h | 3 ++- include/linux/atomic/atomic-long.h | 3 ++- include/net/ip.h | 4 ++-- lib/atomic64.c | 10 +++++----- net/ipv4/route.c | 10 +++++----- scripts/atomic/fallbacks/dec_if_positive | 2 +- scripts/atomic/fallbacks/dec_unless_positive | 2 +- scripts/atomic/fallbacks/fetch_add_unless | 2 +- scripts/atomic/fallbacks/inc_unless_negative | 2 +- scripts/atomic/gen-atomic-fallback.sh | 1 + scripts/atomic/gen-atomic-instrumented.sh | 1 + scripts/atomic/gen-atomic-long.sh | 1 + 19 files changed, 49 insertions(+), 40 deletions(-)