From: Yongliang Gao Date: Fri, 11 Oct 2024 04:31:53 +0000 (+0800) Subject: rtc: check if __rtc_read_time was successful in rtc_timer_do_work() X-Git-Tag: v6.13-rc1~17^2~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e8ba8a2bc4f60a1065f23d6a0e7cbea945a0f40d;p=thirdparty%2Fkernel%2Flinux.git rtc: check if __rtc_read_time was successful in rtc_timer_do_work() If the __rtc_read_time call fails,, the struct rtc_time tm; may contain uninitialized data, or an illegal date/time read from the RTC hardware. When calling rtc_tm_to_ktime later, the result may be a very large value (possibly KTIME_MAX). If there are periodic timers in rtc->timerqueue, they will continually expire, may causing kernel softlockup. Fixes: 6610e0893b8b ("RTC: Rework RTC code to use timerqueue for events") Signed-off-by: Yongliang Gao Acked-by: Jingqun Li Link: https://lore.kernel.org/r/20241011043153.3788112-1-leonylgao@gmail.com Signed-off-by: Alexandre Belloni --- diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index cca650b2e0b94..aaf76406cd7d7 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -904,13 +904,18 @@ void rtc_timer_do_work(struct work_struct *work) struct timerqueue_node *next; ktime_t now; struct rtc_time tm; + int err; struct rtc_device *rtc = container_of(work, struct rtc_device, irqwork); mutex_lock(&rtc->ops_lock); again: - __rtc_read_time(rtc, &tm); + err = __rtc_read_time(rtc, &tm); + if (err) { + mutex_unlock(&rtc->ops_lock); + return; + } now = rtc_tm_to_ktime(tm); while ((next = timerqueue_getnext(&rtc->timerqueue))) { if (next->expires > now)