From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: "Zeh, Werner" <werner.zeh@siemens.com>
Cc: "tglx@linutronix.de" <tglx@linutronix.de>,
"mingo@redhat.com" <mingo@redhat.com>,
"bp@alien8.de" <bp@alien8.de>, "x86@kernel.org" <x86@kernel.org>,
"a.zummo@towertech.it" <a.zummo@towertech.it>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/1] x86/kernel/rtc: add sanity check for RTC date and time
Date: Fri, 2 Jul 2021 16:10:54 +0200 [thread overview]
Message-ID: <YN8ebqVR0JYTurDY@piout.net> (raw)
In-Reply-To: <AM0PR10MB2580E68ADF9D1AC6804DB2DF9F019@AM0PR10MB2580.EURPRD10.PROD.OUTLOOK.COM>
On 30/06/2021 06:25:44+0000, Zeh, Werner wrote:
> Hi Alexandre
>
> > Hello,
> >
> > On 24/06/2021 10:15:07+0200, Werner Zeh wrote:
> > > The timekeeper is synchronized with the CMOS RTC when it is initialized.
> > > If the RTC buffering is bad (not buffered at all, empty battery) the
> > > RTC registers can contain random data. In order to avoid date and time
> > > being completely rubbish check the sanity of the registers before
> > > calling mktime64. If the values are not valid, set tv_sec to 0 so that
> > > at least the starting time is valid.
> > >
> > > Signed-off-by: Werner Zeh <werner.zeh@siemens.com>
> > > ---
> > > [resent due to wrong lkml address]
> > > [added RTC maintainers to the recipients] This change introduces the
> > > same validity check that is already done in drivers/rtc/interface.c.
> > > If it is not done here, the timekeeper can be set up wrongly in the
> > > first run and won't be corrected once the RTC driver is started
> > > because the validity check in the RTC driver drops the time and date
> > > due to invalid entries.
> > >
> > > arch/x86/kernel/rtc.c | 12 +++++++++++-
> > > 1 file changed, 11 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c index
> > > 586f718b8e95..f4af7b18c6c0 100644
> > > --- a/arch/x86/kernel/rtc.c
> > > +++ b/arch/x86/kernel/rtc.c
> > > @@ -9,6 +9,7 @@
> > > #include <linux/export.h>
> > > #include <linux/pnp.h>
> > > #include <linux/of.h>
> > > +#include <linux/rtc.h>
> > >
> > > #include <asm/vsyscall.h>
> > > #include <asm/x86_init.h>
> > > @@ -64,6 +65,7 @@ void mach_get_cmos_time(struct timespec64 *now)
> > {
> > > unsigned int status, year, mon, day, hour, min, sec, century = 0;
> > > unsigned long flags;
> > > + struct rtc_time tm = {0};
> > >
> > > /*
> > > * If pm_trace abused the RTC as storage, set the timespec to 0, @@
> > > -118,7 +120,15 @@ void mach_get_cmos_time(struct timespec64 *now)
> > > } else
> > > year += CMOS_YEARS_OFFS;
> > >
> > > - now->tv_sec = mktime64(year, mon, day, hour, min, sec);
> > > + tm.tm_sec = sec;
> > > + tm.tm_min = min;
> > > + tm.tm_hour = hour;
> > > + tm.tm_mday = day;
> > > + tm.tm_mon = mon;
> > > + tm.tm_year = year;
> > > + now->tv_sec = 0;
> > > + if (rtc_valid_tm(&tm) == 0)
> >
> > Doesn't that make the x86 architecture depend on CONFIG_RTC_LIB?
> >
> CONFIG_RTC_LIB is already default enabled for x86, see arch/x86/Kconfig.
> Do you have any other dependencies in mind I have overseen?
>
Nope, everything is fine, it would be better if we could get rid of
mach_get_cmos_time but I don't have any clue as to why this is
necessary.
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2021-07-02 14:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-14 11:09 [PATCH 1/1] x86/kernel/rtc: add sanity check for RTC date and time Werner Zeh
2021-06-24 8:15 ` Werner Zeh
2021-06-28 16:34 ` Alexandre Belloni
2021-06-30 6:25 ` AW: " Zeh, Werner
2021-07-02 14:10 ` Alexandre Belloni [this message]
2021-12-09 8:05 ` Zeh, Werner
2021-12-09 8:50 ` Alexandre Belloni
2021-12-09 9:07 ` Zeh, Werner
2021-12-17 21:53 ` Alexandre Belloni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YN8ebqVR0JYTurDY@piout.net \
--to=alexandre.belloni@bootlin.com \
--cc=a.zummo@towertech.it \
--cc=bp@alien8.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=werner.zeh@siemens.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.