mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] rtc: Initialized rtc_time->tm_isdst
@ 2011-08-12 21:04 Mike Waychison
  2011-08-12 23:29 ` john stultz
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Waychison @ 2011-08-12 21:04 UTC (permalink / raw)
  To: Alessandro Zummo; +Cc: rtc-linux, linux-kernel, Mike Waychison

Even though the Linux kernel does not use the tm_isdst field, it is
exposed as part of the ABI.  This field can accidentally be left
initialized, which is why we currently memset buffers returned to
userland in rtc_read_time.

There is a case however where the field can return garbage from the
stack though when using the RTC_ALM_READ ioctl on the rtc device.  This
ioctl invokes rtc_read_alarm, which is careful to memset the rtc_wkalrm
buffer that is copied to userland, but it then uses a struct copy to
assign to alarm->time given the return value from rtc_ktime_to_tm().

rtc_ktime_to_tm() is implemented by calling rtc_time_to_tm using a
derivative seconds counds from ktime, but rtc_time_to_tm does not assign
a value to ->tm_isdst.  This results in garbage from rtc_ktime_to_tm()'s
frame ending up being copied out to userland as part of the returned
rtc_wkalrm.

Fix this by initializing rtc_time->tm_isdst to 0 in rtc_time_to_tm.

Signed-off-by: Mike Waychison <mikew@google.com>
---
 drivers/rtc/rtc-lib.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index 075f170..c4cf057 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -85,6 +85,8 @@ void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
 	time -= tm->tm_hour * 3600;
 	tm->tm_min = time / 60;
 	tm->tm_sec = time - tm->tm_min * 60;
+
+	tm->tm_isdst = 0;
 }
 EXPORT_SYMBOL(rtc_time_to_tm);
 
-- 
1.7.3.1


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

* Re: [PATCH] rtc: Initialized rtc_time->tm_isdst
  2011-08-12 21:04 [PATCH] rtc: Initialized rtc_time->tm_isdst Mike Waychison
@ 2011-08-12 23:29 ` john stultz
  0 siblings, 0 replies; 2+ messages in thread
From: john stultz @ 2011-08-12 23:29 UTC (permalink / raw)
  To: Mike Waychison; +Cc: Alessandro Zummo, rtc-linux, linux-kernel

On Fri, Aug 12, 2011 at 2:04 PM, Mike Waychison <mikew@google.com> wrote:
> Even though the Linux kernel does not use the tm_isdst field, it is
> exposed as part of the ABI.  This field can accidentally be left
> initialized, which is why we currently memset buffers returned to
> userland in rtc_read_time.
>
> There is a case however where the field can return garbage from the
> stack though when using the RTC_ALM_READ ioctl on the rtc device.  This
> ioctl invokes rtc_read_alarm, which is careful to memset the rtc_wkalrm
> buffer that is copied to userland, but it then uses a struct copy to
> assign to alarm->time given the return value from rtc_ktime_to_tm().
>
> rtc_ktime_to_tm() is implemented by calling rtc_time_to_tm using a
> derivative seconds counds from ktime, but rtc_time_to_tm does not assign
> a value to ->tm_isdst.  This results in garbage from rtc_ktime_to_tm()'s
> frame ending up being copied out to userland as part of the returned
> rtc_wkalrm.

Thanks for catching this!  I've queued this in my tree.

thanks
-john

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

end of thread, other threads:[~2011-08-12 23:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-12 21:04 [PATCH] rtc: Initialized rtc_time->tm_isdst Mike Waychison
2011-08-12 23:29 ` john stultz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®