From patchwork Sat Dec 31 00:35:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [resend] rtc: Fix alarm rollover when day or month is out-of-range Date: Fri, 30 Dec 2011 14:35:52 -0000 From: Jonathan Nieder X-Patchwork-Id: 133705 Message-Id: <20111231003552.GB22266@elie.Belkin> To: "P." Cc: rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org, Alessandro Zummo , John Stultz , Ben Hutchings From: Ben Hutchings Date: Thu, 29 Dec 2011 16:41:56 +0100 Commit f44f7f96a20a ('RTC: Initialize kernel state from RTC') introduced a potential infinite loop. If an alarm time contains a wildcard month and an invalid day (> 31), or a wildcard year and an invalid month (>= 12), the loop searching for the next matching date will never terminate. Treat the invalid values as wildcards. Fixes , Reported-by: leo weppelman Reported-by: "P. van Gaans" Cc: stable@vger.kernel.org Signed-off-by: Ben Hutchings Signed-off-by: Jonathan Nieder --- P. wrote: > Following the advice from Jonathan Nieder I am sending this mail. Old advice. :) Here's a patch that was sent to the rtc-linux list, but I can't seem to find it with search.gmane.org. drivers/rtc/interface.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index 3bcc7cfcaba7..67b68c4543d0 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -232,11 +232,11 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) alarm->time.tm_hour = now.tm_hour; /* For simplicity, only support date rollover for now */ - if (alarm->time.tm_mday == -1) { + if (alarm->time.tm_mday < 1 || alarm->time.tm_mday > 31) { alarm->time.tm_mday = now.tm_mday; missing = day; } - if (alarm->time.tm_mon == -1) { + if ((unsigned)alarm->time.tm_mon >= 12) { alarm->time.tm_mon = now.tm_mon; if (missing == none) missing = month;