public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, ard.biesheuvel@arm.com
Cc: "Jordan Justen" <jordan.l.justen@intel.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: Re: [edk2-devel] [PATCH] OvmfPkg/VirtioFsDxe: call IsTimeValid() before EfiTimeToEpoch()
Date: Thu, 7 Jan 2021 15:16:20 +0100	[thread overview]
Message-ID: <4933644c-2bfc-ab30-4eef-f4e0995b029e@redhat.com> (raw)
In-Reply-To: <54be7422-3c3a-255e-96f7-6b03313ec873@arm.com>

On 01/07/21 10:52, Ard Biesheuvel wrote:
> On 1/7/21 10:50 AM, Laszlo Ersek wrote:
>> EmbeddedPkg/TimeBaseLib provides a verification function called
>> IsTimeValid(), for enforcing the UEFI spec requirements on an EFI_TIME
>> object.
>>
>> When EFI_FILE_PROTOCOL.SetInfo() is called in order to update the
>> timestamps on the file, let's invoke IsTimeValid() first, before passing
>> the new EFI_FILE_INFO.{CreateTime,LastAccessTime,ModificationTime} values
>> to EfiTimeToEpoch().
>>
>> This patch is not expected to make a practical difference, but it's better
>> to ascertain the preconditions of EfiTimeToEpoch() on the
>> EFI_FILE_PROTOCOL.SetInfo() caller. The FAT driver (EnhancedFatDxe) has a
>> similar check, namely in FatSetFileInfo() -> FatIsValidTime().
>>
>> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
>> Cc: Jordan Justen <jordan.l.justen@intel.com>
>> Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
>> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> 
> Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>

Merged via <https://github.com/tianocore/edk2/pull/1314>, as commit
e9c5ff3d2730.

Thanks!
Laszlo

> 
> 
>> ---
>>  OvmfPkg/VirtioFsDxe/Helpers.c | 20 +++++++++++++++-----
>>  1 file changed, 15 insertions(+), 5 deletions(-)
>>
>> diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c
>> index 443bbdc616ac..b81c04e0a4e8 100644
>> --- a/OvmfPkg/VirtioFsDxe/Helpers.c
>> +++ b/OvmfPkg/VirtioFsDxe/Helpers.c
>> @@ -2237,26 +2237,33 @@ VirtioFsGetFuseSizeUpdate (
>>  
>>    @param[out] Atime        If UpdateAtime is set to TRUE, then Atime provides
>>                             the last access timestamp to set (as seconds since
>>                             the Epoch). Otherwise, Atime is not written to.
>>  
>>    @param[out] Mtime        If UpdateMtime is set to TRUE, then Mtime provides
>>                             the last modification timestamp to set (as seconds
>>                             since the Epoch). Otherwise, Mtime is not written
>>                             to.
>>  
>> -  @retval EFI_SUCCESS        Output parameters have been set successfully.
>> +  @retval EFI_SUCCESS            Output parameters have been set successfully.
>>  
>> -  @retval EFI_ACCESS_DENIED  NewInfo requests changing both CreateTime and
>> -                             ModificationTime, but to values that differ from
>> -                             each other. The Virtio Filesystem device does not
>> -                             support this.
>> +  @retval EFI_INVALID_PARAMETER  At least one of the CreateTime, LastAccessTime
>> +                                 and ModificationTime fields in NewInfo
>> +                                 represents an actual update relative to the
>> +                                 current state of the file (expressed in Info),
>> +                                 but does not satisfy the UEFI spec
>> +                                 requirements on EFI_TIME.
>> +
>> +  @retval EFI_ACCESS_DENIED      NewInfo requests changing both CreateTime and
>> +                                 ModificationTime, but to values that differ
>> +                                 from each other. The Virtio Filesystem device
>> +                                 does not support this.
>>  **/
>>  EFI_STATUS
>>  VirtioFsGetFuseTimeUpdates (
>>    IN     EFI_FILE_INFO *Info,
>>    IN     EFI_FILE_INFO *NewInfo,
>>       OUT BOOLEAN       *UpdateAtime,
>>       OUT BOOLEAN       *UpdateMtime,
>>       OUT UINT64        *Atime,
>>       OUT UINT64        *Mtime
>>    )
>> @@ -2278,20 +2285,23 @@ VirtioFsGetFuseTimeUpdates (
>>    //
>>    // Determine which timestamps differ from the current state. (A zero time
>>    // means "don't update", per UEFI spec.) For each timestamp that's being
>>    // changed, calculate the seconds since the Epoch.
>>    //
>>    for (Idx = 0; Idx < ARRAY_SIZE (Time); Idx++) {
>>      if (CompareMem (NewTime[Idx], &ZeroTime, sizeof (EFI_TIME)) == 0 ||
>>          CompareMem (NewTime[Idx], Time[Idx], sizeof (EFI_TIME)) == 0) {
>>        Change[Idx] = FALSE;
>>      } else {
>> +      if (!IsTimeValid (NewTime[Idx])) {
>> +        return EFI_INVALID_PARAMETER;
>> +      }
>>        Change[Idx] = TRUE;
>>        Seconds[Idx] = EfiTimeToEpoch (NewTime[Idx]);
>>      }
>>    }
>>  
>>    //
>>    // If a change is requested for exactly one of CreateTime and
>>    // ModificationTime, we'll change the last modification time. If changes are
>>    // requested for both, and to the same timestamp, we'll similarly update the
>>    // last modification time. If changes are requested for both, but to
>>
> 
> 
> 
> 
> 
> 


      reply	other threads:[~2021-01-07 14:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-07  9:50 [PATCH] OvmfPkg/VirtioFsDxe: call IsTimeValid() before EfiTimeToEpoch() Laszlo Ersek
2021-01-07  9:52 ` Ard Biesheuvel
2021-01-07 14:16   ` Laszlo Ersek [this message]

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=4933644c-2bfc-ab30-4eef-f4e0995b029e@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