Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp388382rdb; Tue, 23 Jan 2024 02:57:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IH39eqfXwoXuA3D2pSn+ezGWdCCBRWUquZJ7Xm8sf82z59o66a789XZotsHMOOkuQPNW3eM X-Received: by 2002:a05:6830:1514:b0:6dd:f01a:b27a with SMTP id k20-20020a056830151400b006ddf01ab27amr2817943otp.31.1706007477993; Tue, 23 Jan 2024 02:57:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706007477; cv=pass; d=google.com; s=arc-20160816; b=I99gEtIgjLqjZEDiAavMrpGIdRMoMFz5lfCWoHqLEdVV+KNk8BToav595DWHZ7O8/O 7E7jvHuhyqvfVKYor+lli+OWGIdkaIcIwKtjILMruWGjgeoGahnRi1CGnsYzesID/Jn5 XCRifku26xrpQNiF0sAP1w9GITEDeNI38czwteaMgCpOajRB5IN55BkVMS6YK23jnhzH cu5QstBMd3s+62D+/0DuPy6ERkyOtGKY3jQp0c7JbjQxxvT6dleR6MPDeuUtmWoz1Jd5 aZrJTh/pQ+4EyY2U1UOSFDdCMjhX2iySV51joVRRKxuv0gHPn22iJVWX1oxJNuB/gLVe PaFQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=GZ4WofjIMAVndiDmebuw4U62aY9XizTZbXLNQOWxl64=; fh=ojDJq4243pV9Okbft+A6W+kzpDSF/0anNs2tgiG8OtE=; b=mZ7qxLB7VwBPMBrAvsOqT1kkuRz2+sXbUrxFRUP79SsrRfH2p1ilLDLNsQKOV0pEbF 32NwObVAnjzOLWlE7ikw3Ch2LIM4d8p9B2vx8N/J2WExgkwZsGYfgBmbwxWzBszcHdc/ stBfkvYt2KDt7s3+zndWQkOLcSkzHoERaLO1OxI+66ECjamk8tyOCIW/dTNrIyJnHW5o N2ybM5+RNflLXnnWuo4lhvF1jBWXidgu7OqevoCaZ/xx+sFISr5O1P2oaxRUhr4eoIzR 63tK2JSWYPmL8h7Ncngwh5zOLdwnLbR3LdFxQ6NkpjHtmfQls31VPpGOd1blBncF1ZSv jE0A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SqhZRflS; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-35129-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35129-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id m24-20020a63ed58000000b00565db2812a0si9880025pgk.60.2024.01.23.02.57.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 02:57:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35129-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SqhZRflS; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-35129-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35129-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 3A01EB24D9F for ; Tue, 23 Jan 2024 10:50:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0BD965C913; Tue, 23 Jan 2024 10:50:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SqhZRflS" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 321635C8F0; Tue, 23 Jan 2024 10:50:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706007009; cv=none; b=OU/uBRvgxt2cxHjHnM5qmg060AiVKkRLIxyK90Axj24jNY1btJvwjZRfIG3gXvbR2C0kvcgqx7+X4ruUi5JumOWEIiEAj7+p76/M2TgcERanhlmaG51fyIdkfcUpoktv4zxZnqeIOMkwR7EN00t1UPA2VcAHvpjzSafcKFnLFXo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706007009; c=relaxed/simple; bh=NUoP5TWGl92ADNFhVXefbClOKJepyvGfwAUcpjPYGe0=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=c1soBC0p93zF7MmEZEXnHgahkX/tYnxzzleU691RoI8qTxRVZBuJoPZOma4Ubwqowlmbp5B4ZTm9ChC0Vwl4Hz22owde+DXn2ZkSat96MPamuZacN5p5TMHvKLd8tBsQntW/5pvEhubByz15xJv9CnCrQ3zUPjlqJTWg7js3DUE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SqhZRflS; arc=none smtp.client-ip=10.30.226.201 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII 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 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.