mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-03 18:20:25 +02:00 
			
		
		
		
	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: 6610e0893b ("RTC: Rework RTC code to use timerqueue for events")
Signed-off-by: Yongliang Gao <leonylgao@tencent.com>
Acked-by: Jingqun Li <jingqunli@tencent.com>
Link: https://lore.kernel.org/r/20241011043153.3788112-1-leonylgao@gmail.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
			
			
This commit is contained in:
		
							parent
							
								
									00f1bb9b84
								
							
						
					
					
						commit
						e8ba8a2bc4
					
				
					 1 changed files with 6 additions and 1 deletions
				
			
		| 
						 | 
					@ -904,13 +904,18 @@ void rtc_timer_do_work(struct work_struct *work)
 | 
				
			||||||
	struct timerqueue_node *next;
 | 
						struct timerqueue_node *next;
 | 
				
			||||||
	ktime_t now;
 | 
						ktime_t now;
 | 
				
			||||||
	struct rtc_time tm;
 | 
						struct rtc_time tm;
 | 
				
			||||||
 | 
						int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct rtc_device *rtc =
 | 
						struct rtc_device *rtc =
 | 
				
			||||||
		container_of(work, struct rtc_device, irqwork);
 | 
							container_of(work, struct rtc_device, irqwork);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mutex_lock(&rtc->ops_lock);
 | 
						mutex_lock(&rtc->ops_lock);
 | 
				
			||||||
again:
 | 
					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);
 | 
						now = rtc_tm_to_ktime(tm);
 | 
				
			||||||
	while ((next = timerqueue_getnext(&rtc->timerqueue))) {
 | 
						while ((next = timerqueue_getnext(&rtc->timerqueue))) {
 | 
				
			||||||
		if (next->expires > now)
 | 
							if (next->expires > now)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue