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 8C551C282DE for ; Sun, 16 Mar 2025 10:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ffzijhZVfH5kiGfQcAgPWv79ALJ229rFLFS/1lcorW4=; b=kqW3SK6+wI1mgUY672OQBNrJM3 qpnhLKMd7QiSospctURPNwAE9JbwLQEOjubT8RXOji3Koc5x33b/uuhY2XmHpP2koBMmDsB301oqZ JnWUnkVeCmE4pzvZWv3DPsfOFaoZpFhPFgSgA3Y/lKJK+2R11RhzpzspvSVkf5lRtaPhZO9FpCApM b0xeZBEabxvGNVe/NAyzFyVaZ4/bx76Zt7UvYkuRhkxt3RKFrZaI+WfwKQG7RF/P/MCxWwyiOwdoH 0Y9sYmRjQPWUoSwvmdMYdKdenbQHC6VeXfQrGRPw+MNIB/bgwv7VcSEYL57w2DsVfA1CJOYcJzyP2 ed5592AQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1ttlPd-000000003z1-47Kg; Sun, 16 Mar 2025 10:40:09 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1ttlNy-000000003qt-13Nq for linux-arm-kernel@lists.infradead.org; Sun, 16 Mar 2025 10:38:27 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BE5065C0579; Sun, 16 Mar 2025 10:36:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52991C4CEDD; Sun, 16 Mar 2025 10:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742121505; bh=ucfDcVDXjcWOKkPOItkoGktnegmxA36i+Qi8b/Jl410=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=tzoUnGUJYmLLjkfW4T7p2RLqA4jzYzCkibx3MtvizJlWr+Cxzm9P761vIPHs9POf4 ROTqpgwo0dXDjhaL0X2n3UekeGmt6n9kb7nzDztHvHcMatY+u+ttLRxecE//YGLa8R mylic3yWL5yS8fW78Q2hu2wHs0CPIqdztq6iHYrGmpv4Av0Ma6fSqMXg3rwzG4J/1b x6xNBqM+A+YchzEStpg+E4lC8ARnUVkKO1z+H/aL63GBm2mtRahe4pMcxAhCW/VDgh 9GmdnZqGO/hDHq7qRJICGglt2PsRUbnhfPYwza60Z0Z1uRB+cHq8QWQE3YMFscOGeC dKIq8SYq61cIQ== 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 1ttlNv-00Dy89-3i; Sun, 16 Mar 2025 10:38:23 +0000 Date: Sun, 16 Mar 2025 10:38:21 +0000 Message-ID: <868qp5ntuq.wl-maz@kernel.org> From: Marc Zyngier To: Will Deacon Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org, Oliver Upton , Quentin Perret Subject: Re: [PATCH] KVM: arm64: Tear down vGIC on failed vCPU creation In-Reply-To: <20250314133409.9123-1-will@kernel.org> References: <20250314133409.9123-1-will@kernel.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.4 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) 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: will@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org, oliver.upton@linux.dev, qperret@google.com 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-20250316_033826_376974_7CBF5267 X-CRM114-Status: GOOD ( 23.17 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, 14 Mar 2025 13:34:09 +0000, Will Deacon wrote: > > If kvm_arch_vcpu_create() fails to share the vCPU page with the > hypervisor, we propagate the error back to the ioctl but leave the > vGIC vCPU data initialised. Note only does this leak the corresponding > memory when the vCPU is destroyed but it can also lead to use-after-free > if the redistributor device handling tries to walk into the vCPU. > > Add the missing cleanup to kvm_arch_vcpu_create(), ensuring that the > vGIC vCPU structures are destroyed on error. > > Cc: > Cc: Marc Zyngier > Cc: Oliver Upton > Cc: Quentin Perret > Signed-off-by: Will Deacon > --- > > It's hard to come up with a "Fixes:" tag for this. Prior to 3f868e142c0b > ("KVM: arm64: Introduce kvm_share_hyp()"), create_hyp_mappings() could > still have failed, although if you go back before 66c57edd3bc7 ("KVM: > arm64: Restrict EL2 stage-1 changes in protected mode") then it's > vanishingly unlikely. > > arch/arm64/kvm/arm.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index b8e55a441282..fa71cee02faa 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -466,7 +466,11 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) > if (err) > return err; > > - return kvm_share_hyp(vcpu, vcpu + 1); > + err = kvm_share_hyp(vcpu, vcpu + 1); > + if (err) > + kvm_vgic_vcpu_destroy(vcpu); > + > + return err; > } > > void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu) Reviewed-by: Marc Zyngier M. -- Without deviation from the norm, progress is not possible.