Skip to content

Commit efa1368

Browse files
committed
KVM: arm64: Commit exceptions from KVM_SET_VCPU_EVENTS immediately
syzkaller has found that it can trip a warning in KVM's exception emulation infrastructure by repeatedly injecting exceptions into the guest. While it's unlikely that a reasonable VMM will do this, further investigation of the issue reveals that KVM can potentially discard the "pending" SEA state. While the handling of KVM_GET_VCPU_EVENTS presumes that userspace-injected SEAs are realized immediately, in reality the emulated exception entry is deferred until the next call to KVM_RUN. Hack-a-fix the immediate issues by committing the pending exceptions to the vCPU's architectural state immediately in KVM_SET_VCPU_EVENTS. This is no different to the way KVM-injected exceptions are handled in KVM_RUN where we potentially call __kvm_adjust_pc() before returning to userspace. Reported-by: [email protected] Reported-by: [email protected] Reviewed-by: Marc Zyngier <[email protected]> Signed-off-by: Oliver Upton <[email protected]>
1 parent f9e4e0a commit efa1368

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

arch/arm64/kvm/guest.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,19 @@ int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
834834
return 0;
835835
}
836836

837+
static void commit_pending_events(struct kvm_vcpu *vcpu)
838+
{
839+
if (!vcpu_get_flag(vcpu, PENDING_EXCEPTION))
840+
return;
841+
842+
/*
843+
* Reset the MMIO emulation state to avoid stepping PC after emulating
844+
* the exception entry.
845+
*/
846+
vcpu->mmio_needed = false;
847+
kvm_call_hyp(__kvm_adjust_pc, vcpu);
848+
}
849+
837850
int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
838851
struct kvm_vcpu_events *events)
839852
{
@@ -843,8 +856,15 @@ int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
843856
u64 esr = events->exception.serror_esr;
844857
int ret = 0;
845858

846-
if (ext_dabt_pending)
859+
/*
860+
* Immediately commit the pending SEA to the vCPU's architectural
861+
* state which is necessary since we do not return a pending SEA
862+
* to userspace via KVM_GET_VCPU_EVENTS.
863+
*/
864+
if (ext_dabt_pending) {
847865
ret = kvm_inject_sea_dabt(vcpu, kvm_vcpu_get_hfar(vcpu));
866+
commit_pending_events(vcpu);
867+
}
848868

849869
if (ret < 0)
850870
return ret;
@@ -863,6 +883,12 @@ int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
863883
else
864884
ret = kvm_inject_serror(vcpu);
865885

886+
/*
887+
* We could've decided that the SError is due for immediate software
888+
* injection; commit the exception in case userspace decides it wants
889+
* to inject more exceptions for some strange reason.
890+
*/
891+
commit_pending_events(vcpu);
866892
return (ret < 0) ? ret : 0;
867893
}
868894

0 commit comments

Comments
 (0)