Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp365427rdb; Tue, 23 Jan 2024 01:58:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgxf+TSj7yEsKpcOtM05idwAgqQKONjZXDsGAxRAKJytdv8vMXl5N9a+0pMaxLkaQXWHi+ X-Received: by 2002:a05:6402:22f6:b0:55c:7163:e3be with SMTP id dn22-20020a05640222f600b0055c7163e3bemr403087edb.92.1706003939407; Tue, 23 Jan 2024 01:58:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706003939; cv=pass; d=google.com; s=arc-20160816; b=l3m/Kb9S5qiPuQnupRAdHygTxw5mPE00EF10z6vkthMJ5oHx14viVScAFLhCivFoGK 1tapElroFBT0zSfRf3YxW/aV5Dto/UG40vpFkABmbrtQVToQq/jUXRiKMm50ezB6UpX9 9LK7KX1RbG27PcjSLIchTrK030Hs6iOrpMxBGg4/6jm85G0PMyHQMTIKRboHZ/KeIf+/ Wd3M0kibSNePaCzYGwGWXACZVD+YnM47KYn9u5d9cu++u1Eflpp+fUkHQ5D1aZPuIkRE QRI3qCnA3lG45jal7/BgAP1cQGKHCJWgYBguZobmeJwpH0gExiqMwvvR4gzy4cyo2VyT 8bjw== 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; bh=zknsbgMAxUxQsdC0B+fHfnUGgV2KFr5lH+8ezoLdxqw=; fh=i0VVmLCnmjWysyTMzr0CDjbFkb0UUmd4HjL4y11N4aE=; b=UtRRN/35Eo6ymeJBrYpwk0XOsY3RfIotlrghinLmBoykU3+q+m9hvlDwk2RxZfdZ1D cZPjA6fLFn60AvrYMf9YT/CDV+Kbmhvx4Qbc+EPVSv5R1Z1CQ3CpFNXwF+ztn/dsXJvO yHa3SdH9ozKWAHhsuh0GSszIglGPrp3G8MmrRdNnxLTdqVvUgBn6hEBQ4hxnHZKTOF+/ yOutOGnrRsA0fgax2F3lsIJwztX+wPKURRBTuydZcFQMoPlCw8c/spFm05AtvDXy0IIH IL4XuvzdacLgKoTnGQon3IIjbfkjalCWCHlTaZDw9A9mzGwsS79VCKJZXXhqfKDaA9DS khdg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-35057-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35057-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ev7-20020a056402540700b0055872d17e56si12320644edb.42.2024.01.23.01.58.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 01:58:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35057-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-35057-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35057-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com 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 07E0A1F2510E for ; Tue, 23 Jan 2024 09:58:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC3265A10B; Tue, 23 Jan 2024 09:58:42 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D1795BAFA; Tue, 23 Jan 2024 09:58:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706003922; cv=none; b=VJGYIuJ3USHACscLymRcNj6juwHjyaV7B/Nk5zyC1bMUbKe3ShfukZpEaouFjqm7URqe8hFdKYPV2RauxWWMy3Pldk1qxMyIQu8gzY7u0mLLKcwwlwKnRqFH8QGjg8E9wkroVwTHM1xUDyxDLZmQTJSHwyWd5Zqf3JlWKnr7rtw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706003922; c=relaxed/simple; bh=nxl7RImlPHt2woc7MH+W+qg3tN0qm3GwTQesAwY6riA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=L/hSOVu7bV0xZosvP5mWLL+ia9aCd4gNepTPhjAYKT5L65q/jt6HQVr6zUCF1Du8FEP8R/PTbhcOeaJfCFuyFEq0SS6MfimKtfHusVD1EUSseJ4/yhEUVIhbzKBmrW/beQscVgv6XQDejUXJTbwrwQSNY070+sp3QLMjQjXcNrc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7820A1FB; Tue, 23 Jan 2024 01:59:25 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.48.47]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E7C533F5A1; Tue, 23 Jan 2024 01:58:37 -0800 (PST) Date: Tue, 23 Jan 2024 09:58:35 +0000 From: Mark Rutland To: Kees Cook Cc: linux-hardening@vger.kernel.org, Catalin Marinas , Will Deacon , Kalesh Singh , Fuad Tabba , Mark Brown , "Madhavan T. Venkataraman" , Marc Zyngier , linux-arm-kernel@lists.infradead.org, "Gustavo A. R. Silva" , Bill Wendling , Justin Stitt , linux-kernel@vger.kernel.org Subject: Re: [PATCH 40/82] arm64: stacktrace: Refactor intentional wrap-around test Message-ID: References: <20240122235208.work.748-kees@kernel.org> <20240123002814.1396804-40-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: <20240123002814.1396804-40-keescook@chromium.org> On Mon, Jan 22, 2024 at 04:27:15PM -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: Catalin Marinas > Cc: Will Deacon > Cc: Kalesh Singh > Cc: Fuad Tabba > Cc: Mark Brown > Cc: "Madhavan T. Venkataraman" > Cc: Marc Zyngier > Cc: Mark Rutland > Cc: linux-arm-kernel@lists.infradead.org > Signed-off-by: Kees Cook > --- > arch/arm64/include/asm/stacktrace/common.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/include/asm/stacktrace/common.h b/arch/arm64/include/asm/stacktrace/common.h > index f63dc654e545..6e0cb84961f8 100644 > --- a/arch/arm64/include/asm/stacktrace/common.h > +++ b/arch/arm64/include/asm/stacktrace/common.h > @@ -49,7 +49,7 @@ static inline bool stackinfo_on_stack(const struct stack_info *info, > if (!info->low) > return false; > > - if (sp < info->low || sp + size < sp || sp + size > info->high) > + if (sp < info->low || add_would_overflow(sp, size) || sp + size > info->high) > return false; This looks fine to me, so FWIW: Acked-by: Mark Rutland Mark. > > return true; > -- > 2.34.1 >