From mboxrd@z Thu Jan 1 00:00:00 1970 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 50CF9C47DDB for ; Tue, 23 Jan 2024 22:42:39 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Y4IlMW19/wDVkauaAf8ef4to+oX7clqMdNKppNMlEUg=; b=Zuum7XiwFRGgXM ewjH9BwMn5Skpm1UYPO1bl89xzJfS2Y2IP14/avXPT0lz2v0BdiQa5gyJBFY2p19dNczG6IRIhY0e WaKAyv9y8HvEQHDA8AnI99oMKD4g3aPlnEDRXxFPfNj3AL8g+mfIR57e629LkK/epeRxK3sM7kHur /8ho0FjQT+Co9Ld8OzeHfWlpFhqWaB+V1amX0UGKJwhL8xH8/3qwMxwgy2soKqa6/Lz+CDLFmk4NQ 8e5lhQwDf4LuOK7bFVXwO9hbt8m2cHdu2jweXvFg8f/a4VXQrGt9XegCJUyjQ7vX951lgZxaRAG9C rVDOdamd5Icn3m/2A7gQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSPT8-000jSd-2D; Tue, 23 Jan 2024 22:42:10 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSPT5-000jRD-1R for linux-arm-kernel@lists.infradead.org; Tue, 23 Jan 2024 22:42:08 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6dd85328325so652403b3a.1 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=lists.infradead.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=hG9iVcJyEQrUjYLffkPTUi+DEKax65xHRz93JYJyPuftSG1iwTzRbTbzHY8XhZH042 YCJjdWA5O4hCv7z7IYK+njErM8c+z5/Kdp6C/oerx8LbfAxHjT7YO2cY0TdG65hnCJtf 4sF+yXklE1pg8EYpZTwuSte0a4YBFh/xBM3Wk= 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=hIxdpEojUpUpfINitpG2S8FP8Hy60WJzc5N5ZiulafJ+PlwJ4MWj6o0vG7JZHwCxz8 iH4kVb+ZQ2H8jXRuKiHri59D3CnyWGYs0KnuW9T4jJAZrkqvLKIUo/GHYUL0T0sP00fY 4AdJOl34G5R2ZkPW9W9YHDL85eorZc+HCJoZeJYZ11rNwbZQ5I1KIVf5VzGcEV13yzkG Las7e8RrYAS8AR8jMY377C12qSLnEzRYCMQoRr5AmmSsMYVSkXV7Bz2NYyEpUSgbNaZT GH0u/p5rHgP5OIWaEpSQJ9up6focFJA/29JRsOgR8vGak3Mn1Gs6IqAGyNThEu+Mnw5o lycg== X-Gm-Message-State: AOJu0YwNGqnm4T7Y2rVXA/2gpA29dsuWQuRqUMnnC726nYnQTMXrOFoz +qW30CAfB23kmtSPFYmMfMDw7WGxlPY+mXx7PoPD2/yDJkBvJSs4te8N4oE9lA== X-Google-Smtp-Source: AGHT+IHwpTHhUNklJYwoOZzlpbiuoqmorVbDQt+RpuA3sITy6NnTDgE24fxse09JSEmVMJKrdG/Alg== 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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240123_144207_487339_65FB869A X-CRM114-Status: GOOD ( 29.44 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel