mirror of
https://github.com/torvalds/linux.git
synced 2026-09-24 06:24:02 +02:00
LoongArch: KVM: Prevent division by zero in periodic timer restore
A guest can write CSR.TCFG with the periodic bit set but a period value
of zero. When kvm_restore_timer() later enters the periodic branch,
period = cfg & CSR_TCFG_VAL evaluates to 0, causing (delta % period) to
trigger a division by zero and crash the host kernel.
Clamp the period to 1 to avoid the panic.
Fixes: a5857b9ff6 ("LoongArch: KVM: Implement vcpu timer operations")
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
This commit is contained in:
parent
fe41c0759b
commit
01c823f14e
|
|
@ -135,6 +135,8 @@ void kvm_restore_timer(struct kvm_vcpu *vcpu)
|
|||
delta = ktime_to_tick(vcpu, ktime_sub(expire, now));
|
||||
else if (cfg & CSR_TCFG_PERIOD) {
|
||||
period = cfg & CSR_TCFG_VAL;
|
||||
if (!period)
|
||||
period = 1;
|
||||
delta = ktime_to_tick(vcpu, ktime_sub(now, expire));
|
||||
delta = period - (delta % period);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user