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 A519FC25B79 for ; Fri, 24 May 2024 19:11:47 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Fge1WIBO+dfWT/nTHifKLa9ZZ7IrJnXWIpU3L1EpsC0=; b=gvhAfwsZaWP/s+ MQgtf1zNfdPxugS0H6Ns/2uyxWvtQXJpaUtOGWqkDrvauPlaGBpEu1is1twrGx6mAI5FowvANQxhR JOQwgfY1bZZ22ELNMGwE27PJhMD5TpPfqZKr4S+9BOtwwAaq0RIKgLayBiJPpR8yq3KHl/Q+764Pe /EcTc4zIXTRPl1Gjae6GLEcM0Bf1SUVYD0/b5UDMnEx/24+OAMpqxtAvDk+nt/j4iLoEDdK/dIvL3 r1wOkDbBimlmNBwk0vo5tN0Kx2ZDB5i8TF4HBw9cmMaOkZ0Tv+hZL3jpDVsJfGNaHRev1S8zL+Ozr fbRho7CzFrEUhPKbwSag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sAaKG-00000009fjl-1DNk; Fri, 24 May 2024 19:11:36 +0000 Received: from out-179.mta1.migadu.com ([2001:41d0:203:375::b3]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sAaKC-00000009fh8-3Jsv for linux-arm-kernel@lists.infradead.org; Fri, 24 May 2024 19:11:34 +0000 X-Envelope-To: maz@kernel.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1716577886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=lhqVCrk4TUPu/R/gwdf3f4+jj1RHh1pN1QQ0wWRJLzw=; b=XvmmdnH/ZwwZ+1V+73CmrvodZeZMc6Bnw4R3V1H3u9HCUk5Ygjjp3BF1fCixBMX9PUA9Lo Fs3si+aEcD1ofbR9CG0qgd1gqK4Em5ifZ54Pv1ZQ580jznyrocpvC5SMf2lIxkWI3k/KRU NeSFKs4V+QgSCvE2QFBlo58NCwJKbBE= X-Envelope-To: kvmarm@lists.linux.dev X-Envelope-To: kvm@vger.kernel.org X-Envelope-To: linux-arm-kernel@lists.infradead.org X-Envelope-To: nsg@linux.ibm.com X-Envelope-To: james.morse@arm.com X-Envelope-To: suzuki.poulose@arm.com X-Envelope-To: yuzenghui@huawei.com X-Envelope-To: stable@vger.kernel.org Date: Fri, 24 May 2024 12:11:20 -0700 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Marc Zyngier Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Nina Schoetterl-Glausch , James Morse , Suzuki K Poulose , Zenghui Yu , stable@vger.kernel.org Subject: Re: [PATCH 1/3] KVM: arm64: Fix AArch32 register narrowing on userspace write Message-ID: References: <20240524141956.1450304-1-maz@kernel.org> <20240524141956.1450304-2-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240524141956.1450304-2-maz@kernel.org> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240524_121133_331760_454C18E4 X-CRM114-Status: GOOD ( 23.16 ) 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 Fri, May 24, 2024 at 03:19:54PM +0100, Marc Zyngier wrote: > When userspace writes to once of the core registers, we make s/once/one/ > sure to narrow the corresponding GPRs if PSTATE indicates > an AArch32 context. > > The code tries to check whether the context is EL0 or EL1 so > that it narrows the correct registers. But it does so by checking > the full PSTATE instead of PSTATE.M. > > As a consequence, and if we are restoring an AArch32 EL0 context > in a 64bit guest, and that PSTATE has *any* bit set outside of > PSTATE.M, we narrow *all* registers instead of only the first 15, > destroying the 64bit state. > > Obviously, this is not something the guest is likely to enjoy. > > Correctly masking PSTATE to only evaluate PSTATE.M fixes it. > > Fixes: 90c1f934ed71 ("KVM: arm64: Get rid of the AArch32 register mapping code") > Reported-by: Nina Schoetterl-Glausch > Signed-off-by: Marc Zyngier > Cc: stable@vger.kernel.org > --- > arch/arm64/kvm/guest.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c > index e2f762d959bb..d9617b11f7a8 100644 > --- a/arch/arm64/kvm/guest.c > +++ b/arch/arm64/kvm/guest.c > @@ -276,7 +276,7 @@ static int set_core_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) > if (*vcpu_cpsr(vcpu) & PSR_MODE32_BIT) { > int i, nr_reg; > > - switch (*vcpu_cpsr(vcpu)) { > + switch (*vcpu_cpsr(vcpu) & PSR_AA32_MODE_MASK) { > /* > * Either we are dealing with user mode, and only the > * first 15 registers (+ PC) must be narrowed to 32bit. > -- > 2.39.2 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel