hw/timer/hpet: Fix expiration time overflow
authorAkihiko Odaki <akihiko.odaki@daynix.com>
Tue, 31 Jan 2023 03:00:37 +0000 (12:00 +0900)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 2 Mar 2023 08:10:47 +0000 (03:10 -0500)
commit37d2bcbc2a4e9c2e9061bec72a32c7e49b9f81ec
treeb622e7bf0ab92ad37f2508cdb66c912a2fc61c27
parent62bdb8871512076841f4464f7e26efdc7783f78d
hw/timer/hpet: Fix expiration time overflow

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>
hw/timer/hpet.c