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 E5A70C6FD19 for ; Thu, 16 Mar 2023 17:47:00 +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: 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: List-Owner; bh=ktJPo302Bz3bTaBzbfF1xqZc1Jl/FO+9eGMoMBAcYO4=; b=SxfjQqKudKUYUB qzletsUfWWIfbAflga8zfVMyf/Iy1nrrUZtUyIaODsu15nfcR+Q+Z2ORTZNGOddLOnGICgptRHEsd dQtSNWlMsX9BGQ4YcyyscILoHLauJLBQyjnRr9jUdH8mNUQmmfUnQ/lSJ5RsJ8nsCOc1fwdVCQ4Ep gIBX46MB/PNIKkuRJnEUlLSy2SX2nUdJlqRDIBC5PFygDzAVM5mkF0D4DaZIIuizKAsg2A7pWf/JY KDCIsnEZ5PKvvKn11D3p5wyw/zNPKB7Xx6uT1rcHF/g7/wzwokdC96+KblolfaCewZ+LWIni4vuFR 4lbk9w5d+IEgyFvdQVLw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcrfy-00HAKJ-26; Thu, 16 Mar 2023 17:46:06 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcrfo-00HAHl-0C for linux-arm-kernel@lists.infradead.org; Thu, 16 Mar 2023 17:46:01 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A34ECB822B2; Thu, 16 Mar 2023 17:45:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 296A2C433A0; Thu, 16 Mar 2023 17:45:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678988753; bh=CBNpFTDMLwkvTBMXcscTR/Y07GKXOZ1tkBPcTpBcJxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pF+noQG1FTLFo0TiqjfSklO63PC3Elu4ZcNrWFTuhIaaG47P2h/O4c83nGsijiGsB 6PoiHjkJ9RwiJ9PC29GAeRCjNx8EGzwVzDlb2J97Z4wcV0sIQZ1JOI2X0xiCoXBoGT rjKL25b6QLzHbwRbb/fcDmtwA3K34/CG7v3IaxBeYYacNhEFkAV8I6f7EGjYI/iOwu KBksGz6fJutVd6aRvnM+T5rvD4jQ+nxHEL7fwPOunrlby6+KpZT1bYq9KsQRQUChzK NdaaQ7bvOrrMgF0/EQjOZ1o1pStAL4pzyBK42IR9O693Ys2xlzYANHVaT4Pq4mBTfs BwwvytpHG1MKQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pcrfi-000eUs-U2; Thu, 16 Mar 2023 17:45:50 +0000 From: Marc Zyngier To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Ard Biesheuvel , Will Deacon , Quentin Perret , Sean Christopherson , David Matlack , stable@vger.kernel.org Subject: [PATCH v2 2/2] KVM: arm64: Check for kvm_vma_mte_allowed in the critical section Date: Thu, 16 Mar 2023 17:45:46 +0000 Message-Id: <20230316174546.3777507-3-maz@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230316174546.3777507-1-maz@kernel.org> References: <20230316174546.3777507-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, ardb@kernel.org, will@kernel.org, qperret@google.com, seanjc@google.com, dmatlack@google.com, stable@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-20230316_104556_402268_EA65BEB7 X-CRM114-Status: GOOD ( 18.02 ) 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 page fault, we find about the VMA that backs the page fault early on, and quickly release the mmap_read_lock. However, using the VMA pointer after the critical section is pretty dangerous, as a teardown may happen in the meantime and the VMA be long gone. Move the sampling of the MTE permission early, and NULL-ify the VMA pointer after that, just to be on the safe side. Signed-off-by: Marc Zyngier Cc: stable@vger.kernel.org --- arch/arm64/kvm/mmu.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index d3d4cdc0f617..e95593736ae3 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1218,7 +1218,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, { int ret = 0; bool write_fault, writable, force_pte = false; - bool exec_fault; + bool exec_fault, mte_allowed; bool device = false; unsigned long mmu_seq; struct kvm *kvm = vcpu->kvm; @@ -1309,6 +1309,10 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, fault_ipa &= ~(vma_pagesize - 1); gfn = fault_ipa >> PAGE_SHIFT; + mte_allowed = kvm_vma_mte_allowed(vma); + + /* Don't use the VMA after the unlock -- it may have vanished */ + vma = NULL; /* * Read mmu_invalidate_seq so that KVM can detect if the results of @@ -1379,7 +1383,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, if (fault_status != ESR_ELx_FSC_PERM && !device && kvm_has_mte(kvm)) { /* Check the VMM hasn't introduced a new disallowed VMA */ - if (kvm_vma_mte_allowed(vma)) { + if (mte_allowed) { sanitise_mte_tags(kvm, pfn, vma_pagesize); } else { ret = -EFAULT; -- 2.34.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel