[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 38/47] hw/timer/hpet: Fix expiration time overflow
From: |
Michael Tokarev |
Subject: |
[PATCH 38/47] hw/timer/hpet: Fix expiration time overflow |
Date: |
Wed, 8 Mar 2023 19:57:41 +0300 |
From: Akihiko Odaki <akihiko.odaki@daynix.com>
The expiration time provided for timer_mod() can overflow if a
ridiculously large value is set to the comparator register. The
resulting value can represent a past time after rounded, forcing the
timer to fire immediately. If the timer is configured as periodic, it
will rearm the timer again, and form an endless loop.
Check if the expiration value will overflow, and if it will, stop the
timer instead of rearming the timer with the overflowed time.
This bug was found by Alexander Bulekov when fuzzing igb, a new
network device emulation:
https://patchew.org/QEMU/20230129053316.1071513-1-alxndr@bu.edu/
The fixed test case is:
fuzz/crash_2d7036941dcda1ad4380bb8a9174ed0c949bcefd
Fixes: 16b29ae180 ("Add HPET emulation to qemu (Beth Kon)")
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20230131030037.18856-1-akihiko.odaki@daynix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
(cherry picked from commit 37d2bcbc2a4e9c2e9061bec72a32c7e49b9f81ec)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
hw/timer/hpet.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
index 9520471be2..5f88ffdef8 100644
--- a/hw/timer/hpet.c
+++ b/hw/timer/hpet.c
@@ -352,6 +352,16 @@ static const VMStateDescription vmstate_hpet = {
}
};
+static void hpet_arm(HPETTimer *t, uint64_t ticks)
+{
+ if (ticks < ns_to_ticks(INT64_MAX / 2)) {
+ timer_mod(t->qemu_timer,
+ qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + ticks_to_ns(ticks));
+ } else {
+ timer_del(t->qemu_timer);
+ }
+}
+
/*
* timer expiration callback
*/
@@ -374,13 +384,11 @@ static void hpet_timer(void *opaque)
}
}
diff = hpet_calculate_diff(t, cur_tick);
- timer_mod(t->qemu_timer,
- qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
(int64_t)ticks_to_ns(diff));
+ hpet_arm(t, diff);
} else if (t->config & HPET_TN_32BIT && !timer_is_periodic(t)) {
if (t->wrap_flag) {
diff = hpet_calculate_diff(t, cur_tick);
- timer_mod(t->qemu_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
- (int64_t)ticks_to_ns(diff));
+ hpet_arm(t, diff);
t->wrap_flag = 0;
}
}
@@ -407,8 +415,7 @@ static void hpet_set_timer(HPETTimer *t)
t->wrap_flag = 1;
}
}
- timer_mod(t->qemu_timer,
- qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
(int64_t)ticks_to_ns(diff));
+ hpet_arm(t, diff);
}
static void hpet_del_timer(HPETTimer *t)
--
2.30.2
- [PATCH 26/47] hw/smbios: fix field corruption in type 4 table, (continued)
- [PATCH 26/47] hw/smbios: fix field corruption in type 4 table, Michael Tokarev, 2023/03/08
- [PATCH 27/47] Revert "x86: do not re-randomize RNG seed on snapshot load", Michael Tokarev, 2023/03/08
- [PATCH 25/47] block/iscsi: fix double-free on BUSY or similar statuses, Michael Tokarev, 2023/03/08
- [PATCH 30/47] Revert "x86: use typedef for SetupData struct", Michael Tokarev, 2023/03/08
- [PATCH 33/47] vhost-user-gpio: Configure vhost_dev when connecting, Michael Tokarev, 2023/03/08
- [PATCH 28/47] Revert "x86: re-initialize RNG seed when selecting kernel", Michael Tokarev, 2023/03/08
- [PATCH 29/47] Revert "x86: reinitialize RNG seed on system reboot", Michael Tokarev, 2023/03/08
- [PATCH 32/47] Revert "hw/i386: pass RNG seed via setup_data entry", Michael Tokarev, 2023/03/08
- [PATCH 31/47] Revert "x86: return modified setup_data only if read as memory, not as file", Michael Tokarev, 2023/03/08
- [PATCH 34/47] vhost-user-i2c: Back up vqs before cleaning up vhost_dev, Michael Tokarev, 2023/03/08
- [PATCH 38/47] hw/timer/hpet: Fix expiration time overflow,
Michael Tokarev <=
- [PATCH 41/47] libvhost-user: check for NULL when allocating a virtqueue element, Michael Tokarev, 2023/03/08
- [PATCH 40/47] vhost: avoid a potential use of an uninitialized variable in vhost_svq_poll(), Michael Tokarev, 2023/03/08
- [PATCH 37/47] virtio-rng-pci: fix transitional migration compat for vectors, Michael Tokarev, 2023/03/08
- [PATCH 43/47] intel-iommu: fail MAP notifier without caching mode, Michael Tokarev, 2023/03/08
- [PATCH 44/47] intel-iommu: fail DEVIOTLB_UNMAP without dt mode, Michael Tokarev, 2023/03/08
- [PATCH 35/47] vhost-user-rng: Back up vqs before cleaning up vhost_dev, Michael Tokarev, 2023/03/08
- [PATCH 39/47] vdpa: stop all svq on device deletion, Michael Tokarev, 2023/03/08
- [PATCH 42/47] chardev/char-socket: set s->listener = NULL in char_socket_finalize, Michael Tokarev, 2023/03/08
- [PATCH 45/47] block: Handle curl 7.55.0, 7.85.0 version changes, Michael Tokarev, 2023/03/08
- [PATCH 46/47] tests/tcg: fix unused variable in linux-test, Michael Tokarev, 2023/03/08