Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3918651pxv; Mon, 28 Jun 2021 16:38:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPGcfy5kmbYX6sDR/9QxjSUAn+vfMquv+J5PTHlxO9xx02hb/6R5yLO1jcMm0IWpBE9StB X-Received: by 2002:a5d:9f4b:: with SMTP id u11mr1497138iot.144.1624923538336; Mon, 28 Jun 2021 16:38:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624923538; cv=none; d=google.com; s=arc-20160816; b=aiw3mS9ERofX9iCArj756HW6L5t9PsosLs+vcv2oYVUb1inxQ6pv3Ny4V6pbv7uAqC N4y88mcSHs1pnIhIzmCAGfMeyBxQh1lhd5rYBcOi6GKIVBVD/ojLOH27zLCvqQcZAvHm +P3KVW2EQXl6CmKUEvjYhWPBlR6lmrX2l05E6RAtPu6NDLWI0OLlzHuVxKF80ocHNgTr cZ4idR84BrYTDU2eTQmMY9lD5imBQblFl8RhJJyAIDu28eV7gdGI12IQZ6UvOjkbumzn Sw/ZqZeTZkqXenVES6/tweSEa6UZV2asCnFY7wWL16tz7bblyowevJ8XQ17EP8r211Ks AhQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=PQH1Y6bqFxKcPx11bScRq05kNNoCn1lLrR64wscq7OQ=; b=xe4n+Afw+TRW6i0aulCIjVM4rbxqFWximjve6VJmN/ZSBsFd+D3RaALGkWlopQFx2O KPyxB+1gbAtHPmFh1OC8ZeerAU5wSyE9ldv5mxIpzR1sTF1C57XC2DGEzmObHiG55Iye 1XDbQNtRVBn2OPkdIFu8vR0uSPN115WOldcLn3qWtmw94fVuw0gsU8HKIeLK4w6BNuDj iFYCw+rfXirZKIw2mBaiODWfEKE+CQcEXhS9pUmHNPeqoV9F8Msy4LYv/gVLkm3bvGwV q8cZ+BPVdNw2Q5eeR+nHY1Ovt3/p3bUY3qerxv6Ko/U0pPa20P4/GJ0orhGX9R0ahWnQ AgqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w10si18271880jao.68.2021.06.28.16.38.45; Mon, 28 Jun 2021 16:38:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231750AbhF1QhA (ORCPT + 99 others); Mon, 28 Jun 2021 12:37:00 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:51335 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231743AbhF1Qg6 (ORCPT ); Mon, 28 Jun 2021 12:36:58 -0400 Received: (Authenticated sender: alexandre.belloni@bootlin.com) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id ECDD7240003; Mon, 28 Jun 2021 16:34:30 +0000 (UTC) Date: Mon, 28 Jun 2021 18:34:30 +0200 From: Alexandre Belloni To: Werner Zeh Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, a.zummo@towertech.it, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] x86/kernel/rtc: add sanity check for RTC date and time Message-ID: References: <20210614110946.15587-1-werner.zeh@siemens.com> <20210624081507.15602-1-werner.zeh@siemens.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210624081507.15602-1-werner.zeh@siemens.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > [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 > #include > #include > +#include > > #include > #include > @@ -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? -- Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com