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 6EC4CC61DA4 for ; Mon, 13 Mar 2023 09:16:06 +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=x3F6qj80mlck2ju7JrI2wb4g6etf6OP0gYH1D357asc=; b=NlxDR8nXEIkWxM DoNAZwl/nyqYfrmA5zM6nuG5G+6J5MgPrDAzv/AmEWYf2ES1ZotM6dbZRC8tKXwQDQ0/8bD3QTP24 tMvzYlnl8QTH02Tq++fyqvPq0vpRFARplHnM6597xTDZBop2mSGf3E7/2DUPnoxl9LRm+Ncr6Gckp qRnnPRvIk0qoNWhNdJEr9quw9gicTTo/4ntTB20vpOT44WEqgCJGIkfy5oDAfyFdlezlpI63sRtKR +lWv4Q57ioRSJIWb5M9pE3UKso0Z9b70xGNPCTRRwoNv8BHg9Y4bfJg3Wrb07QDDD6DD4tuefVQRG /ISmW2ONzjx8EvMGsuxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbeGp-004wWl-Vo; Mon, 13 Mar 2023 09:15:08 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbeGa-004wSX-9A for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 09:14:57 +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 dfw.source.kernel.org (Postfix) with ESMTPS id B622D6118E; Mon, 13 Mar 2023 09:14:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5395C433A4; Mon, 13 Mar 2023 09:14:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678698891; bh=Wye0Vl6QFmyMU9FOa/kaj5qWj9XcQLGu7BWa7lw7V9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ewkzT/nuk5WO/zD80cVndUZQKir9qXYDKY1GCbp7xOHH+0x3xDBv4/hWKhbkcwJBt 7L1CmGNRpMRIlGgd0VrEg1oc70SJFCBNYgDSu+m2mz4RFALpMirVskbfdrO0g0EGcQ CWCOfzirYmAhzpMIXWKCb3v4kO4+cPo1/NZRq3Lg/kQghJZDsZJQE5eEQu5EXZKJkx NwT5c0fLPoUKV+0uLbeJ6Uci+i5f35sD2fj+LacYJCJy/EGj7tQhel6Y1FR/dR7QBB pX7Hs44NYUSM7aHpoZX875G/2aKgZVXs2O3X613+p4qiZ0YLjoYLg8bp5GZZWlzted cdMOyEVWTVFJQ== 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 1pbeGW-00HAzq-LW; Mon, 13 Mar 2023 09:14:48 +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 , stable@vger.kernel.org Subject: [PATCH 2/2] KVM: arm64: Check for kvm_vma_mte_allowed in the critical section Date: Mon, 13 Mar 2023 09:14:25 +0000 Message-Id: <20230313091425.1962708-3-maz@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313091425.1962708-1-maz@kernel.org> References: <20230313091425.1962708-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, 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-20230313_021452_975237_432B06AA X-CRM114-Status: GOOD ( 17.20 ) 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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index d7b8b25942df..2424be11eb52 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1208,7 +1208,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; @@ -1285,6 +1285,9 @@ 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 that -- it may have vanished */ + vma = NULL; mmap_read_unlock(current->mm); /* @@ -1375,7 +1378,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