public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, mw@semihalf.com
Cc: leif@nuviainc.com, ard.biesheuvel@arm.com, jaz@semihalf.com,
	kostap@marvell.com
Subject: Re: [edk2-devel] [edk2-platforms PATCH] Marvell/RealTimeClockLib: Allow only Unix Epoch in LibSetWakeupTime
Date: Mon, 21 Dec 2020 21:09:43 +0100	[thread overview]
Message-ID: <4f9497c7-0097-3a92-6b52-ece4a6defa9f@redhat.com> (raw)
In-Reply-To: <20201221163710.19729-1-mw@semihalf.com>

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 <mw@semihalf.com>
> ---
>  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


  reply	other threads:[~2020-12-21 20:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-21 16:37 [edk2-platforms PATCH] Marvell/RealTimeClockLib: Allow only Unix Epoch in LibSetWakeupTime Marcin Wojtas
2020-12-21 20:09 ` Laszlo Ersek [this message]
2020-12-21 20:32   ` [edk2-devel] " Laszlo Ersek
2021-01-04 17:14     ` Ard Biesheuvel

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-list 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=4f9497c7-0097-3a92-6b52-ece4a6defa9f@redhat.com \
    --to=devel@edk2.groups.io \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox