Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp767624rdb; Tue, 23 Jan 2024 14:42:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IHluJySKb89jehbXSLOMLrwNbRPtGjBhHclZpkBTqXr7LiposgYqmIAoRAOjwcz20KswAfy X-Received: by 2002:a05:620a:208d:b0:783:930f:e59f with SMTP id e13-20020a05620a208d00b00783930fe59fmr5410249qka.6.1706049730752; Tue, 23 Jan 2024 14:42:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706049730; cv=pass; d=google.com; s=arc-20160816; b=yrygApC5yNnU1TOIyueYmwS/4pCsJhPHEy/5wpJKM3ssw0qFCKnqAhfbqE/kmCAyG4 y2uT7onjPeEUIveoEPgResvxxV+J+mz8AiFwDBfXa0AwwJrSWJ5oes7cv3FxpRg6kV1E 7v3N+gOwm23Nn8JMjpJ6/6c15tzQb2othHEIf/c/8qqlU3s3R66hgZGt5GodwQh9MbYO Gm66O4MP9LIe97Fwe1Bx0gAnJb8sqDXupK58Qtfxntm5kg/85kRKk6QsgwCI+1P/z1PQ zrmlw+2mG+eP5ySVPfzasNO2d86WdqkHvNrJR3Gem2JfZ0Tlj821qJquIRDAP6ZVEEzI EzmA== 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=NLP204yME76cKWvSKqR4QvH8/WxYNOPL78/EyvH5yzk=; fh=ag3msKaUnpCo5iiAumh1Dk9r/HuVzmD62dfhUET6ohY=; b=J7RQSISGSZ2zdAyE6wpmg0qDidzpU1/lmMO7BoXocMotSJqshQFgdqkRMywPc10E+q NNXO9eDffmpTKdVsI8hYfeAW38TLpsFfTECIvXYUUgS33cEtD1+nMujy2cRw3EITd7Sf fShlEfofX19Cx7GHDC1E7VpHE5pBrifECUcdLIljjA1csgXB7bXMzbJdBbNKlMtc3bUE 7yM85SYVrX8MpDKlywpAUu/BrCYp5NVG+xpHZdlPBKmoR9exv3mK/XvHNiDkVvfrqFI+ Ouqq13rawFzKtJlSnSGxyhheqXvj7lv7RRK6VYLpc1cQB2iR50WgQAfBKDsFCpPsC3i+ ihqA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=A7C2args; 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-36153-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36153-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u13-20020a05620a0c4d00b0078377888dbfsi9258419qki.406.2024.01.23.14.42.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 14:42:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36153-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=A7C2args; 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-36153-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36153-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 400931C270CE for ; Tue, 23 Jan 2024 22:42:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7CFA95380E; Tue, 23 Jan 2024 22:42:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="A7C2args" Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 4ABA251010 for ; Tue, 23 Jan 2024 22:42:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706049722; cv=none; b=E9eK95ttZ7LDQn5ANqadBBoneVypQjFZpwrtjr51KHbUQ41lWRtUKYnDMDw+C+/4qD1bRXjqwq2EFl5/eQYPpxEHzpIUzqJxIwK1k0FGIsBQLCD5R3jBycIJkF1b/Oaejl53BzatPxEPIp3jYtf8RoMU/cF6zbcmhlM+LdRYtC8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706049722; c=relaxed/simple; bh=zKrh9Cm8LBMdmMkZwJbUhPVyyd35s47X76PNGXAhQBo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZaMqNEx7K3fShSBUtJr1MO/4a34J//Sp7tBNkn0zgNubKUC2JTkzZxhyuPJMimyfrkfF/DxN1H/eT5WvzeQUoN69Bu7MCTn0gbuUrhLEhwP9KeT/4CUK/fGhYKgTpTxMxQxuyQ1It92BqOdvpNaE7/qD8gdpiFANTidGmlc965c= 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=A7C2args; arc=none smtp.client-ip=209.85.210.179 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-pf1-f179.google.com with SMTP id d2e1a72fcca58-6d9b13fe9e9so3931268b3a.2 for ; Tue, 23 Jan 2024 14:42:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1706049720; x=1706654520; 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=NLP204yME76cKWvSKqR4QvH8/WxYNOPL78/EyvH5yzk=; b=A7C2argsd3w1FTAqLxve7TteXsyWVG+pgmxReCn2t0rVKKDeQI8i0DZxUyQUulG//H 7NXwjNUhMY/+uLxTo+BvibNxtnB1+tuMjREgkpQvI1twX5dYst7kqTkEeReA0gVAmeOg VD0WojfvS6MrngQ7AAduFdFv3hPiiG957MXps= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706049720; x=1706654520; 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=NLP204yME76cKWvSKqR4QvH8/WxYNOPL78/EyvH5yzk=; b=IaA58TlsbLeMxOnRwuz13QIXZYd4fKgMdz9Ej9Z5s/LV063Vox5zfSDhfki2I7awWH 1Y/WpvBYBR6EKn7mNcsS/hrW5MtkWic7DRqfjT4bFDgL8pNJhOZLyH/S4kl2I5h25fVr nqg7AzZeIBtKJcfSrphx7XvSHvoo9UQoypNzKnXz9vqgPCi1bAklgUFmP/9At7WsfRN+ 4ybUhYM85EyLPs1dkQeA+eTtTKKO9uheZsOseoTa/NZVtL9Ru5gXbrlzWfpZfganJFkG wk1qkdZoxWjaSLD23vQllq2BDFdwuFuHRfydzv8V6nMvJluQjYaIR2fOCR/ck43bqlPE BTDg== X-Gm-Message-State: AOJu0Yyh8mEwRyfw/28K2Y4h7hhUSpfBRKYrOhkfp6MxkCKBUFzpb0w7 SYY+knV/7kOkOxVQ3Ayol9kP+n8BLnQ8Lj0l/SiNXVid41IsLd40/KfbEXQROw== X-Received: by 2002:aa7:9f4d:0:b0:6dd:81e6:e93c with SMTP id h13-20020aa79f4d000000b006dd81e6e93cmr1032305pfr.63.1706049720687; Tue, 23 Jan 2024 14:42:00 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id hq15-20020a056a00680f00b006dbd2231184sm6411616pfb.70.2024.01.23.14.42.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 14:42:00 -0800 (PST) Date: Tue, 23 Jan 2024 14:41:59 -0800 From: Kees Cook To: Mark Rutland Cc: linux-hardening@vger.kernel.org, Russell King , linux-arm-kernel@lists.infradead.org, "Gustavo A. R. Silva" , Bill Wendling , Justin Stitt , linux-kernel@vger.kernel.org Subject: Re: [PATCH 38/82] arm: 3117/1: Refactor intentional wrap-around test Message-ID: <202401231441.7A15A53419@keescook> References: <20240122235208.work.748-kees@kernel.org> <20240123002814.1396804-38-keescook@chromium.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:56:22AM +0000, Mark Rutland wrote: > The commit title is odd here; '3117/1' is the patch tracker name for the last > patch. The title should probably be: > > arm: nwfpe: Refactor intentional wrap-around test Whoops, yes. I need to teach my prefix-guessing script to drop the ARM patch tracker numbers... -Kees > > Mark. > > On Mon, Jan 22, 2024 at 04:27:13PM -0800, Kees Cook wrote: > > In an effort to separate intentional arithmetic wrap-around from > > unexpected wrap-around, we need to refactor places that depend on this > > kind of math. One of the most common code patterns of this is: > > > > VAR + value < VAR > > > > Notably, this is considered "undefined behavior" for signed and pointer > > types, which the kernel works around by using the -fno-strict-overflow > > option in the build[1] (which used to just be -fwrapv). Regardless, we > > want to get the kernel source to the position where we can meaningfully > > instrument arithmetic wrap-around conditions and catch them when they > > are unexpected, regardless of whether they are signed[2], unsigned[3], > > or pointer[4] types. > > > > Refactor open-coded wrap-around addition test to use add_would_overflow(). > > This paves the way to enabling the wrap-around sanitizers in the future. > > > > Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] > > Link: https://github.com/KSPP/linux/issues/26 [2] > > Link: https://github.com/KSPP/linux/issues/27 [3] > > Link: https://github.com/KSPP/linux/issues/344 [4] > > Cc: Russell King > > Cc: linux-arm-kernel@lists.infradead.org > > Signed-off-by: Kees Cook > > --- > > arch/arm/nwfpe/softfloat.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/arch/arm/nwfpe/softfloat.c b/arch/arm/nwfpe/softfloat.c > > index ffa6b438786b..0635b1eda1d3 100644 > > --- a/arch/arm/nwfpe/softfloat.c > > +++ b/arch/arm/nwfpe/softfloat.c > > @@ -603,7 +603,7 @@ static floatx80 > > roundBits = zSig0 & roundMask; > > if ( 0x7FFD <= (bits32) ( zExp - 1 ) ) { > > if ( ( 0x7FFE < zExp ) > > - || ( ( zExp == 0x7FFE ) && ( zSig0 + roundIncrement < zSig0 ) ) > > + || ( ( zExp == 0x7FFE ) && (add_would_overflow(zSig0, roundIncrement)) ) > > ) { > > goto overflow; > > } > > -- > > 2.34.1 > > > > -- Kees Cook