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 F0EB2C47258 for ; Tue, 23 Jan 2024 10:50:44 +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:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3OVCmsnCd6+Mp9KUgG861AtlWmfhgw6ViCLaZnExFOs=; b=2lqFxDYRBy5rpd l7goUl+z5nb52rVmCqFXneIoBVBuig1Rygvz9JAWVgxHwBIRpxM2PA1wWPR4F4aXB2KSGjd8MDycR V5geyqaLZYlwIh04T82QVlKND8kOQ2tBSaG2t/7lEPdavyaaHCxqnYVq4pAxsUXie5LXAvD0boVHl 2afsT0RBcZOxw5lP+wKqPBItCfsUb2+71rgaosdCUHwuCEuVIh/eVWX0Hb6ZI2sRFY8wO8eKiANlG cMdT0Y4rpiDuJfXtSUmRR4ChnJpoIaxXGCdt3yrruatkfRBoCVBkbLU+WBtrfK2HJfwky9YdGSHRF bZyoYsTxZAO0Pv4HAoCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSEMC-00G1ID-1W; Tue, 23 Jan 2024 10:50:16 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSEM9-00G1Fw-07 for linux-arm-kernel@lists.infradead.org; Tue, 23 Jan 2024 10:50:14 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id DA073CE2E1D; Tue, 23 Jan 2024 10:50:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05022C433F1; Tue, 23 Jan 2024 10:50:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706007009; bh=NUoP5TWGl92ADNFhVXefbClOKJepyvGfwAUcpjPYGe0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=SqhZRflS3o+AWzVwix/lgC2sZpWh/AIiRFB/HvgxHXTSdwTwEyuw02aSWb0t9OjGo 6HJdSNQlOx9GlQmWp48UaqoRlwMiW5XjmYAvFrQD8MOuynu3v8fi6AepknKd5JYmdM cjaVsAA56G1GowgyoCjuRnmetGUQpcx6qJeKIRXsELD1ZtuxW0SUBipuI5JfrQ1JRF 2nqApcfYZk7BA+9wzjzquKvSYPK1Bb0Wx3Wm9SV7do3iY+xfuVPsQW5k8NqqTZrjlW fkn7wpDrZ2svtccnvtmlVTOJlaLAeoBGiVqANUIA7e2HOVaDbnMoOCPK1qdoqGMBPV fZD+8ztB/Eniw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rSEM2-00Dw1i-PD; Tue, 23 Jan 2024 10:50:06 +0000 Date: Tue, 23 Jan 2024 10:50:06 +0000 Message-ID: <86mssw8gtd.wl-maz@kernel.org> From: Marc Zyngier To: Kees Cook Cc: linux-hardening@vger.kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Eric Auger , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, "Gustavo A. R. Silva" , Bill Wendling , Justin Stitt , linux-kernel@vger.kernel.org Subject: Re: [PATCH 57/82] KVM: arm64: vgic-v3: Refactor intentional wrap-around test In-Reply-To: <20240123002814.1396804-57-keescook@chromium.org> References: <20240122235208.work.748-kees@kernel.org> <20240123002814.1396804-57-keescook@chromium.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: keescook@chromium.org, linux-hardening@vger.kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, eric.auger@redhat.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, gustavoars@kernel.org, morbo@google.com, justinstitt@google.com, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240123_025013_418193_B72C58CA X-CRM114-Status: GOOD ( 26.83 ) 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, 23 Jan 2024 00:27:32 +0000, 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: Marc Zyngier > Cc: Oliver Upton > Cc: James Morse > Cc: Suzuki K Poulose > Cc: Zenghui Yu > Cc: Catalin Marinas > Cc: Will Deacon > Cc: Eric Auger > Cc: linux-arm-kernel@lists.infradead.org > Cc: kvmarm@lists.linux.dev > Signed-off-by: Kees Cook > --- > arch/arm64/kvm/vgic/vgic-mmio-v3.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c > index c15ee1df036a..860b774c0c13 100644 > --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c > +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c > @@ -863,7 +863,7 @@ static int vgic_v3_alloc_redist_region(struct kvm *kvm, uint32_t index, > int ret; > > /* cross the end of memory ? */ > - if (base + size < base) > + if (add_would_overflow(base, size)) > return -EINVAL; > > if (list_empty(rd_regions)) { Acked-by: Marc Zyngier M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel