Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp749391rdb; Tue, 23 Jan 2024 13:56:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3kR6ZdTJoEIPP0PiBS06z3XPFC8ZAPkU+Z4JEDYgADxsk2h84mBPwQf1FxBUhPddy3DeD X-Received: by 2002:a17:907:8b94:b0:a30:74da:41a0 with SMTP id tb20-20020a1709078b9400b00a3074da41a0mr222927ejc.71.1706047008473; Tue, 23 Jan 2024 13:56:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706047008; cv=pass; d=google.com; s=arc-20160816; b=N/T4OsY3Yxb0Z+aqo9s8TQMgyuCL3na+oFFk9v5FRuAI25DokPRD9NSpgQIQ5SspaI UM+9lyJBAs9DkOqiOiKPFmKnX52I9e8djjjFjhhva26N797OVDYbloddFpgOQaXJk9Vs ltsOs33wstnJahfkWJko1dmyfuB8l9wyooEpS4nXl1EA5bcwQrqY/+TjqG6nhLwexKZX NIp6QRFPEGMuw7LLYmZjO6sJi2j2TUr5mwfw22UFjXHOOx8JvfNXSM7D2sLRlyuLisWB 3yhM878x1jlfAXVvvLHNyXzlahvXIgwfC76xiX5+cTOmwKgVAyb6cx5glnt2z33+ZLn2 ZVLA== 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:dkim-signature; bh=E9lSja7LT9ZtyMjrI1OsUow8Sb3Qq23rG9UTWBb1Ccs=; fh=CIc4AFBkognnOSEW2UguNSGi4Dj25ijZHXatpWMY+ow=; b=tCBjpm0uEt+jZn7fK1J6z+ijVZm4YqRi9GRLmaNZGyTz0ywNcqLJmz4k4CNpZMJI8R rnmKwS5XW0q7kozPULIE5biqyhm5Ns5ADj9kIy+SiAkquX83lY5F09li83khV7LQvlQ+ nTPda84DZCtFqioPfnyNvbmJUCLiUO3QRUwHyWrzUGFELYlk7wjNIzwaSkmkHvmjUthr mh0GIDvRkl+VkoXMxeNZaK5wwCvseiycrWLATQxtPGMeEFTs/zibeXbRKNv0UoUNRZYv Yah25t4T5Y705cYsiCtDFoZkst8J3xQpfgPVe/e815H6AfwRRb+UmbYMSsZt3IY2A510 oVbQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dnUsN6DK; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-36098-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36098-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id bv19-20020a170906b1d300b00a303de87ddbsi2690811ejb.50.2024.01.23.13.56.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 13:56:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36098-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=@chromium.org header.s=google header.b=dnUsN6DK; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-36098-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36098-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org 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 15D131F2540A for ; Tue, 23 Jan 2024 21:56:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5DAA148CDC; Tue, 23 Jan 2024 21:56:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="dnUsN6DK" Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47B2048CC5 for ; Tue, 23 Jan 2024 21:56:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706046997; cv=none; b=iBH143rmrKWHGa6MepuOj+rkxT14TRQLuCVXC0aKxIvvgdKfEl+1mm5HMtO74Rd04SjcL2koxf+Tdri7OithSC2SYBTjjQi13f80xzaQiQ2j59yMCvVV9gwjFrIt2nt/PGaEeKtUHJajZ0q7q9GIjX2a3U/8PLFlDqpNOzNnIjg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706046997; c=relaxed/simple; bh=0c0F7eeZoGxLjeqmmKMm57vl0kvVl9qLdYbdVXMjG/M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UcrVD/eeKfpz3H7KYrV3yqO9U2E1iy1lHUgbcJdll3/mRdFRii4lvZ5IRrU3iidGRdVTzF2Af7C4kWpxGZVABgDjAERrpCKBCOPb0mGk5Ufl4P93GTA1U+jAVc/m7Pcgg4QCqpRtMkWVFDuqI8eQddTl6BpsvceWiHGPj9rtpg0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=dnUsN6DK; arc=none smtp.client-ip=209.85.210.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-6e0a64d9449so3087899a34.2 for ; Tue, 23 Jan 2024 13:56:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1706046995; x=1706651795; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=E9lSja7LT9ZtyMjrI1OsUow8Sb3Qq23rG9UTWBb1Ccs=; b=dnUsN6DKQh+VpiCCuR37lloHK4N+7R+RrkbATSNTwzOVUoquPjBXkYO4b4/1E0a/Bb Lvj+F1d9YgEK79pu6YXtXvLijPzWslhB4cKK7R7DeP9LnP5vcULVDKtKiTfqRxJL0Ewb es1itWf9x4GhHLJsHK04rMahYijelxnFy4qZM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706046995; x=1706651795; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=E9lSja7LT9ZtyMjrI1OsUow8Sb3Qq23rG9UTWBb1Ccs=; b=lhrLgXj0er5AjXNEnp4OcTqfoWNCmhcTwk6e+Gds+hnCijOcpw1unZGsSEgOr2//H/ Yq324QPaOKdmZHZRacIX765ntYr69Os1vs3+xxLES6wEag6h5e3jb5yYtN6ijvkqQCob tKRf619oAZ8flUGucyGXYPCm+Foqe71WWrS/KxBmMrnelDIJp7ozJmM/GvZqbYf3W69H RnpIzYJeEPgRHvvAYq5+VuqMWYJgVSiWwAGWdTFk0IPedAcyuLbpqQGWZh8EnR4MfH9C eZwVpHvlnvMk4CcmdoHdnvvj77TqI33ixp7O8DtQ7G5YYxocG1BLofBkfvbBbGe+ycVq EGoA== X-Gm-Message-State: AOJu0Yy9OsH7SCmow/oba5RYuWOivOp6CifOIvmgh3MLY3e5R+eJy0Hf PnMp+ti002Bp1rLfPR2KrlDBkMz/4OjFKy1VRrog/dipwk78o1URxqLsCCb29Q== X-Received: by 2002:a05:6359:4598:b0:176:860c:cc5a with SMTP id no24-20020a056359459800b00176860ccc5amr588759rwb.5.1706046995347; Tue, 23 Jan 2024 13:56:35 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id y14-20020a62f24e000000b006dd85222cc3sm683579pfl.134.2024.01.23.13.56.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 13:56:35 -0800 (PST) Date: Tue, 23 Jan 2024 13:56:34 -0800 From: Kees Cook To: Mark Rutland Cc: linux-hardening@vger.kernel.org, "Gustavo A. R. Silva" , Bill Wendling , Justin Stitt , linux-kernel@vger.kernel.org Subject: Re: [PATCH 00/82] overflow: Refactor open-coded arithmetic wrap-around Message-ID: <202401231355.A94FADCAE@keescook> References: <20240122235208.work.748-kees@kernel.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: On Tue, Jan 23, 2024 at 09:46:35AM +0000, Mark Rutland wrote: > With that in mind, I note that this patch primarily modifies addition > operations, but leaves subtraction operations unchanged (even though those > permit the value to go below the minimum, or above the maximum if a negative > value is used as the subtrahend). Right, this was kind of a "first pass" on what I'd found so far. > Shouldn't we address both at the same time? I'll note that in many places the > same logic is used for both the add and sub, and can legitimately overflow or > underflow; I hope that whatever we use to suppress overflow warnings also > ignores underflow. > > [...] > > Looking at the diffstat, I think you've missed a few places: > > [...] > > This misses the include/asm-generic/{atomic,atomic64}.h implementations. > > This also misses the include/linux/atomic/atomic-arch-fallback.h > implementations. Those are generated from the scripts/atomic/fallbacks/* > templates, and you'll need to adjust at least fetch_add_unless and > inc_unless_negative. As noted on other patches, my preference is to use > add_wrap() in those. > [...] > This misses lib/atomic64.c. Thanks! I'll take a closer look at places we can use the helpers on the atomics. -Kees -- Kees Cook