From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.1509.1608581390964286159 for ; Mon, 21 Dec 2020 12:09:51 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Os3uy5vs; spf=pass (domain: redhat.com, ip: 216.205.24.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608581390; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NXstwVE74fQ++YHJsOklPrMp4CUBp/wtK65gVwcqe/s=; b=Os3uy5vscoq9MiohZYGPLvf9Fy4PTCd/CYoekPaUsGdyE3Uo5PxmPEbUQl3BF5H1+tNTT3 f1fcOVhnaojXB491LVrfg471aTXWMnmxME2ENPKmnO5VIy6Ut5CM+kidkND1zVTJ/8oJZ2 XBQz+nJSXxYBpGfUPaLSyinoQkJ3Ebo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-237-6T9yjzBkPsyjEpOfoQX_8w-1; Mon, 21 Dec 2020 15:09:47 -0500 X-MC-Unique: 6T9yjzBkPsyjEpOfoQX_8w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 69112107ACE4; Mon, 21 Dec 2020 20:09:46 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-71.ams2.redhat.com [10.36.114.71]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E2AB1002391; Mon, 21 Dec 2020 20:09:44 +0000 (UTC) Subject: Re: [edk2-devel] [edk2-platforms PATCH] Marvell/RealTimeClockLib: Allow only Unix Epoch in LibSetWakeupTime To: devel@edk2.groups.io, mw@semihalf.com Cc: leif@nuviainc.com, ard.biesheuvel@arm.com, jaz@semihalf.com, kostap@marvell.com References: <20201221163710.19729-1-mw@semihalf.com> From: "Laszlo Ersek" Message-ID: <4f9497c7-0097-3a92-6b52-ece4a6defa9f@redhat.com> Date: Mon, 21 Dec 2020 21:09:43 +0100 MIME-Version: 1.0 In-Reply-To: <20201221163710.19729-1-mw@semihalf.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Hi Marcin, On 12/21/20 17:37, Marcin Wojtas wrote: > Because the Armada RTC uses a 32-bit counter for seconds, > the maximum time span is just over 136 years. > Time is stored in Unix Epoch format, so it starts in 1970, > Therefore it can not exceed the year 2106. > > The issue emerged during ACS test case, which does not pass > Unix Epoch-relative time and caused EfiTimeToEpoch to assert. > > Signed-off-by: Marcin Wojtas > --- > Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c b/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c > index a811fd368e..40ab01ed41 100644 > --- a/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c > +++ b/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c > @@ -179,6 +179,16 @@ LibSetWakeupTime ( > { > UINTN WakeupSeconds; > > + // > + // Because the Armada RTC uses a 32-bit counter for seconds, > + // the maximum time span is just over 136 years. > + // Time is stored in Unix Epoch format, so it starts in 1970, > + // Therefore it can not exceed the year 2106. > + // > + if ((Time->Year < 1970) || (Time->Year >= 2106)) { > + return EFI_UNSUPPORTED; > + } > + > // Convert time to raw seconds > WakeupSeconds = EfiTimeToEpoch (Time); > if (WakeupSeconds > MAX_UINT32) { > please see: - edk2-platforms commit fbdfe8c4100d ("Silicon/Marvell/RealTimeClockLib: make EpochSeconds, WakeupSeconds UINTN", 2020-12-21) -- part of this is already visible in the context above, - edk2 commit c06635ea3f4b ("EmbeddedPkg/TimeBaseLib: remove useless truncation to 32-bit", 2020-12-21). If you advance the edk2 submodule reference in edk2-platforms to or past c06635ea3f4b, then the "Time->Year >= 2106" condition will be covered already, by the (WakeupSeconds > MAX_UINT32) check. Preventing ASSERT (JulianDate >= EPOCH_JULIAN_DATE) from firing in EfiGetEpochDays() still makes sense, so the (Time->Year < 1970) check can still be added usefully, I think. Thanks Laszlo