Skip to content

Commit 2a3f934

Browse files
Marc Zyngierwildea01
Marc Zyngier
authored andcommitted
arm64: KVM: Sanitize PSTATE.M when being set from userspace
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: <[email protected]> Fixes: 0d854a6 ("arm64: KVM: enable initialization of a 32bit vcpu") Reviewed-by: Christoffer Dall <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Reviewed-by: Dave Martin <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent d26c25a commit 2a3f934

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

arch/arm64/kvm/guest.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,25 @@ static int set_core_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
152152
}
153153

154154
if (off == KVM_REG_ARM_CORE_REG(regs.pstate)) {
155-
u32 mode = (*(u32 *)valp) & PSR_AA32_MODE_MASK;
155+
u64 mode = (*(u64 *)valp) & PSR_AA32_MODE_MASK;
156156
switch (mode) {
157157
case PSR_AA32_MODE_USR:
158+
if (!system_supports_32bit_el0())
159+
return -EINVAL;
160+
break;
158161
case PSR_AA32_MODE_FIQ:
159162
case PSR_AA32_MODE_IRQ:
160163
case PSR_AA32_MODE_SVC:
161164
case PSR_AA32_MODE_ABT:
162165
case PSR_AA32_MODE_UND:
166+
if (!vcpu_el1_is_32bit(vcpu))
167+
return -EINVAL;
168+
break;
163169
case PSR_MODE_EL0t:
164170
case PSR_MODE_EL1t:
165171
case PSR_MODE_EL1h:
172+
if (vcpu_el1_is_32bit(vcpu))
173+
return -EINVAL;
166174
break;
167175
default:
168176
err = -EINVAL;

0 commit comments

Comments
 (0)