linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: fix uninitialized read of rtc_wkalrm.time
@ 2023-11-29  7:36 Nicholas Miehlbradt
  2024-02-29 21:58 ` Alexandre Belloni
  0 siblings, 1 reply; 4+ messages in thread
From: Nicholas Miehlbradt @ 2023-11-29  7:36 UTC (permalink / raw)
  To: a.zummo, alexandre.belloni; +Cc: linux-rtc, linux-kernel, Nicholas Miehlbradt

If either of the first two branches of the if statement in
rtc_read_alarm_internal are taken the fields of alarm->time are not
initialized but are subsequently read by the call to rtc_tm_to_time64.

Refactor so that the time field is only read if the final branch of the
if statment which initializes the field is taken.

Signed-off-by: Nicholas Miehlbradt <nicholas@linux.ibm.com>
---
 drivers/rtc/interface.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 1b63111cdda2..f40e76d2fe2b 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -179,6 +179,7 @@ static int rtc_read_alarm_internal(struct rtc_device *rtc,
 				   struct rtc_wkalrm *alarm)
 {
 	int err;
+	time64_t trace_time = -1;
 
 	err = mutex_lock_interruptible(&rtc->ops_lock);
 	if (err)
@@ -201,11 +202,12 @@ static int rtc_read_alarm_internal(struct rtc_device *rtc,
 		alarm->time.tm_yday = -1;
 		alarm->time.tm_isdst = -1;
 		err = rtc->ops->read_alarm(rtc->dev.parent, alarm);
+		trace_time = rtc_tm_to_time64(&alarm->time);
 	}
 
 	mutex_unlock(&rtc->ops_lock);
 
-	trace_rtc_read_alarm(rtc_tm_to_time64(&alarm->time), err);
+	trace_rtc_read_alarm(trace_time, err);
 	return err;
 }
 
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-08 17:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-29  7:36 [PATCH] rtc: fix uninitialized read of rtc_wkalrm.time Nicholas Miehlbradt
2024-02-29 21:58 ` Alexandre Belloni
2024-03-08  0:53   ` Nicholas Miehlbradt
2024-03-08 17:08     ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).