Skip to content

Commit 3128387

Browse files
Marc Zyngiergregkh
authored andcommitted
KVM: arm64: Prevent mixed-width VM creation
commit 66e94d5 upstream. It looks like we have tolerated creating mixed-width VMs since... forever. However, that was never the intention, and we'd rather not have to support that pointless complexity. Forbid such a setup by making sure all the vcpus have the same register width. Reported-by: Steven Price <steven.price@arm.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Cc: stable@vger.kernel.org Acked-by: Mark Rutland <mark.rutland@arm.com> Link: https://lore.kernel.org/r/20210524170752.1549797-1-maz@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent bb2e3ad commit 3128387

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

‎arch/arm64/include/asm/kvm_emulate.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,4 +505,9 @@ static __always_inline void __kvm_skip_instr(struct kvm_vcpu *vcpu)
505505
write_sysreg_el2(*vcpu_pc(vcpu), SYS_ELR);
506506
}
507507

508+
static inline bool vcpu_has_feature(struct kvm_vcpu *vcpu, int feature)
509+
{
510+
return test_bit(feature, vcpu->arch.features);
511+
}
512+
508513
#endif /* __ARM64_KVM_EMULATE_H__ */

‎arch/arm64/kvm/reset.c‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,25 @@ static int kvm_vcpu_enable_ptrauth(struct kvm_vcpu *vcpu)
223223
return 0;
224224
}
225225

226+
static bool vcpu_allowed_register_width(struct kvm_vcpu *vcpu)
227+
{
228+
struct kvm_vcpu *tmp;
229+
bool is32bit;
230+
int i;
231+
232+
is32bit = vcpu_has_feature(vcpu, KVM_ARM_VCPU_EL1_32BIT);
233+
if (!cpus_have_const_cap(ARM64_HAS_32BIT_EL1) && is32bit)
234+
return false;
235+
236+
/* Check that the vcpus are either all 32bit or all 64bit */
237+
kvm_for_each_vcpu(i, tmp, vcpu->kvm) {
238+
if (vcpu_has_feature(tmp, KVM_ARM_VCPU_EL1_32BIT) != is32bit)
239+
return false;
240+
}
241+
242+
return true;
243+
}
244+
226245
/**
227246
* kvm_reset_vcpu - sets core registers and sys_regs to reset value
228247
* @vcpu: The VCPU pointer
@@ -274,13 +293,14 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
274293
}
275294
}
276295

296+
if (!vcpu_allowed_register_width(vcpu)) {
297+
ret = -EINVAL;
298+
goto out;
299+
}
300+
277301
switch (vcpu->arch.target) {
278302
default:
279303
if (test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features)) {
280-
if (!cpus_have_const_cap(ARM64_HAS_32BIT_EL1)) {
281-
ret = -EINVAL;
282-
goto out;
283-
}
284304
pstate = VCPU_RESET_PSTATE_SVC;
285305
} else {
286306
pstate = VCPU_RESET_PSTATE_EL1;

0 commit comments

Comments
 (0)