Function kvm_vcpu_ioctl_interrupt() can be called from userspace, here add irq validility cheking in kvm_vcpu_ioctl_interrupt(). Also add msgint feature checking if irq number is INT_AVEC. Signed-off-by: Bibo Mao --- arch/loongarch/kvm/interrupt.c | 5 ----- arch/loongarch/kvm/vcpu.c | 22 +++++++++++++++------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/arch/loongarch/kvm/interrupt.c b/arch/loongarch/kvm/interrupt.c index a18c60dffbba..48dd56aa4dc5 100644 --- a/arch/loongarch/kvm/interrupt.c +++ b/arch/loongarch/kvm/interrupt.c @@ -36,8 +36,6 @@ static int kvm_irq_deliver(struct kvm_vcpu *vcpu, unsigned int priority) switch (priority) { case INT_AVEC: - if (!kvm_guest_has_msgint(&vcpu->arch)) - break; dmsintc_inject_irq(vcpu); fallthrough; case INT_TI: @@ -75,9 +73,6 @@ static int kvm_irq_clear(struct kvm_vcpu *vcpu, unsigned int priority) switch (priority) { case INT_AVEC: - if (!kvm_guest_has_msgint(&vcpu->arch)) - break; - fallthrough; case INT_TI: case INT_IPI: case INT_SWI0: diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index e28084c49e68..dc2a1f56650b 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -1487,15 +1487,23 @@ void kvm_lose_fpu(struct kvm_vcpu *vcpu) int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq) { int intr = (int)irq->irq; + int vector; - if (intr > 0) - kvm_queue_irq(vcpu, intr); - else if (intr < 0) - kvm_dequeue_irq(vcpu, -intr); - else { - kvm_err("%s: invalid interrupt ioctl %d\n", __func__, irq->irq); + vector = intr; + if (intr < 0) + vector = -intr; + + if (vector >= EXCCODE_INT_NUM) return -EINVAL; - } + + if (!kvm_guest_has_msgint(&vcpu->arch) && (vector == INT_AVEC)) + return -EINVAL; + + /* Clear irq function with intr == 0 is missing... */ + if (intr >= 0) + kvm_queue_irq(vcpu, vector); + else + kvm_dequeue_irq(vcpu, vector); kvm_vcpu_kick(vcpu); -- 2.39.3