From a5b1555725dbaf0b34f27a53e66b2595094a524a Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 9 Aug 2023 09:50:38 +0300 Subject: [PATCH] Kernel: Validate HPET tick period --- kernel/kernel/Timer/HPET.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/kernel/Timer/HPET.cpp b/kernel/kernel/Timer/HPET.cpp index c4eda02a93..fa226699d8 100644 --- a/kernel/kernel/Timer/HPET.cpp +++ b/kernel/kernel/Timer/HPET.cpp @@ -68,10 +68,14 @@ namespace Kernel m_counter_tick_period_fs = read_register(HPET_REG_CAPABILIES) >> 32; + // period has to be less than 100 ns + if (m_counter_tick_period_fs == 0 || m_counter_tick_period_fs > FS_PER_NS * 100) + return BAN::Error::from_errno(EINVAL); + uint64_t ticks_per_ms = FS_PER_MS / m_counter_tick_period_fs; { - const char* units[] = { "fs", "ps", "ns", "us", "ms", "s" }; + const char* units[] = { "fs", "ps", "ns" }; int index = 0; uint64_t temp = m_counter_tick_period_fs; while (temp >= 1000)