Skip to content

Commit 947051e

Browse files
author
Marc Zyngier
committed
KVM: arm64: Fix AArch32 register narrowing on userspace write
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: 90c1f93 ("KVM: arm64: Get rid of the AArch32 register mapping code") Reported-by: Nina Schoetterl-Glausch <[email protected]> Cc: [email protected] Reviewed-by: Nina Schoetterl-Glausch <[email protected]> Acked-by: Oliver Upton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 1613e60 commit 947051e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/arm64/kvm/guest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static int set_core_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
276276
if (*vcpu_cpsr(vcpu) & PSR_MODE32_BIT) {
277277
int i, nr_reg;
278278

279-
switch (*vcpu_cpsr(vcpu)) {
279+
switch (*vcpu_cpsr(vcpu) & PSR_AA32_MODE_MASK) {
280280
/*
281281
* Either we are dealing with user mode, and only the
282282
* first 15 registers (+ PC) must be narrowed to 32bit.

0 commit comments

Comments
 (0)