]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: arm64: Fix AArch32 register narrowing on userspace write
authorMarc Zyngier <maz@kernel.org>
Fri, 24 May 2024 14:19:54 +0000 (15:19 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 16 Jun 2024 11:41:37 +0000 (13:41 +0200)
commit 947051e361d551e0590777080ffc4926190f62f2 upstream.

When userspace writes to one of the core registers, we make
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 <nsg@linux.ibm.com>
Cc: stable@vger.kernel.org
Reviewed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Acked-by: Oliver Upton <oliver.upton@linux.dev>
Link: https://lore.kernel.org/r/20240524141956.1450304-2-maz@kernel.org
Signed-off-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/arm64/kvm/guest.c

index f44ae09a51956e1c51d7790d5958df55d19a9269..9ee887a9523d8f8e62dfc7d70b5cd3936f75ed26 100644 (file)
@@ -270,7 +270,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.