]> git.hungrycats.org Git - linux/commitdiff
arm64: KVM: Sanitize PSTATE.M when being set from userspace
authorMarc Zyngier <marc.zyngier@arm.com>
Thu, 27 Sep 2018 15:53:22 +0000 (16:53 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 13 Oct 2018 07:09:28 +0000 (09:09 +0200)
commit 2a3f93459d689d990b3ecfbe782fec89b97d3279 upstream.

Not all execution modes are valid for a guest, and some of them
depend on what the HW actually supports. Let's verify that what
userspace provides is compatible with both the VM settings and
the HW capabilities.

Cc: <stable@vger.kernel.org>
Fixes: 0d854a60b1d7 ("arm64: KVM: enable initialization of a 32bit vcpu")
Reviewed-by: Christoffer Dall <christoffer.dall@arm.com>
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/arm64/include/asm/kvm_emulate.h
arch/arm64/kvm/guest.c

index 865a7e28ea2d166efc0f27911970fd480bce4c3d..3d0098d7b47e13f9bf98a91334613974435ff2db 100644 (file)
@@ -38,6 +38,11 @@ void kvm_inject_undefined(struct kvm_vcpu *vcpu);
 void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr);
 void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr);
 
+static inline bool vcpu_el1_is_32bit(struct kvm_vcpu *vcpu)
+{
+       return !(vcpu->arch.hcr_el2 & HCR_RW);
+}
+
 static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
 {
        vcpu->arch.hcr_el2 = HCR_GUEST_FLAGS;
index 5d93c9f2484758072107005416712bfc9d3a15dd..286453f462df21204365195c4d594240b20dbe39 100644 (file)
@@ -141,17 +141,25 @@ static int set_core_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
        }
 
        if (off == KVM_REG_ARM_CORE_REG(regs.pstate)) {
-               u32 mode = (*(u32 *)valp) & COMPAT_PSR_MODE_MASK;
+               u64 mode = (*(u64 *)valp) & COMPAT_PSR_MODE_MASK;
                switch (mode) {
                case COMPAT_PSR_MODE_USR:
+                       if ((read_cpuid(ID_AA64PFR0_EL1) & 0xf) != 2)
+                               return -EINVAL;
+                       break;
                case COMPAT_PSR_MODE_FIQ:
                case COMPAT_PSR_MODE_IRQ:
                case COMPAT_PSR_MODE_SVC:
                case COMPAT_PSR_MODE_ABT:
                case COMPAT_PSR_MODE_UND:
+                       if (!vcpu_el1_is_32bit(vcpu))
+                               return -EINVAL;
+                       break;
                case PSR_MODE_EL0t:
                case PSR_MODE_EL1t:
                case PSR_MODE_EL1h:
+                       if (vcpu_el1_is_32bit(vcpu))
+                               return -EINVAL;
                        break;
                default:
                        err = -EINVAL;