Skip to content

Commit

Permalink
rtc: check if __rtc_read_time was successful in rtc_timer_do_work()
Browse files Browse the repository at this point in the history
[ Upstream commit e8ba8a2bc4f60a1065f23d6a0e7cbea945a0f40d ]

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: 6610e08 ("RTC: Rework RTC code to use timerqueue for events")
Signed-off-by: Yongliang Gao <[email protected]>
Acked-by: Jingqun Li <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexandre Belloni <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Yongliang Gao authored and gregkh committed Dec 5, 2024
1 parent 1cfae95 commit 39ad0a1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/rtc/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -914,13 +914,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)
Expand Down

0 comments on commit 39ad0a1

Please sign in to comment.