From patchwork Thu Oct 27 12:09:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13021998 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 1EDD1ECAAA1 for ; Thu, 27 Oct 2022 12:11:16 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date:Subject:Cc:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=M9EvoNwxRqleuUBNTHR6gJddTmShUEERC/1wQGGJgg0=; b=R/WRnU2HAIKGIV SYTpfYTGsGIDcrYWdq18fZOfS7njFUydum+bZFEJb4GHWq9v7zRPFu9TerNfmI/O8JULV1LE6nv4Y suU+Ou2YIPRF2qpddgcsc2pDOQmVchYlH7FAuawtu4U317DnNAXCnUzVk8YaS8L7yPYvrtZtmSdQO 7YBXtHhErL32TNeLrbDl12AP95qNsacE1cyhTQEyFEWSGh1693C8a6fXDP0LQ7YDuwDc1LkSRZtKZ fq/JpiEHrPJ9C75+PX1f/stv8FwKtOYo7+ZrMXH6JO852Gn5IstNOLXq6hBQp+8vIMV26yDwSIfAm xbucK4xvNm5ebDRRyjsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo1iB-00D8DH-1G; Thu, 27 Oct 2022 12:10:15 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo1i7-00D8Bk-IE for linux-arm-kernel@lists.infradead.org; Thu, 27 Oct 2022 12:10:13 +0000 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 6141C23A; Thu, 27 Oct 2022 05:10:08 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.169]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8DA863F7B4; Thu, 27 Oct 2022 05:10:00 -0700 (PDT) From: Ryan Roberts To: Marc Zyngier Cc: Ryan Roberts , Steven Price , James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu Subject: [PATCH v1] KVM: arm64: Fix bad dereference on MTE-enabled systems. Date: Thu, 27 Oct 2022 13:09:45 +0100 Message-Id: <20221027120945.29679-1-ryan.roberts@arm.com> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221027_051011_684264_C27A876B X-CRM114-Status: GOOD ( 10.65 ) 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org enter_exception64() performs an MTE check, which involves dereferencing vcpu->kvm. While vcpu has already been fixed up for hyp va, kvm is still a kern va pointer. Fix this by first converting kvm to a hyp va pointer. If the system does not support MTE, the dereference is avoided in the first place. Fixes: ea7fc1bb1cd1 ("KVM: arm64: Introduce MTE VM feature") Signed-off-by: Ryan Roberts Reviewed-by: Steven Price --- arch/arm64/kvm/hyp/exception.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/arch/arm64/kvm/hyp/exception.c b/arch/arm64/kvm/hyp/exception.c index b7557b25ed56..791d3de76771 100644 --- a/arch/arm64/kvm/hyp/exception.c +++ b/arch/arm64/kvm/hyp/exception.c @@ -13,6 +13,7 @@ #include #include #include +#include #if !defined (__KVM_NVHE_HYPERVISOR__) && !defined (__KVM_VHE_HYPERVISOR__) #error Hypervisor code only! @@ -115,7 +116,7 @@ static void enter_exception64(struct kvm_vcpu *vcpu, unsigned long target_mode, new |= (old & PSR_C_BIT); new |= (old & PSR_V_BIT); - if (kvm_has_mte(vcpu->kvm)) + if (kvm_has_mte(kern_hyp_va(vcpu->kvm))) new |= PSR_TCO_BIT; new |= (old & PSR_DIT_BIT);