[edk2-devel] [PATCH] OvmfPkg/VirtioFsDxe: call IsTimeValid() before EfiTimeToEpoch()

Laszlo Ersek posted 1 patch 3 years, 3 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/edk2 tags/patchew/20210107095051.22715-1-lersek@redhat.com
OvmfPkg/VirtioFsDxe/Helpers.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
[edk2-devel] [PATCH] OvmfPkg/VirtioFsDxe: call IsTimeValid() before EfiTimeToEpoch()
Posted by Laszlo Ersek 3 years, 3 months ago
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>
---
 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
-- 
2.19.1.3.g30247aa5d201



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#69907): https://edk2.groups.io/g/devel/message/69907
Mute This Topic: https://groups.io/mt/79495773/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH] OvmfPkg/VirtioFsDxe: call IsTimeValid() before EfiTimeToEpoch()
Posted by Ard Biesheuvel 3 years, 3 months ago
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>


> ---
>  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
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#69908): https://edk2.groups.io/g/devel/message/69908
Mute This Topic: https://groups.io/mt/79495773/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH] OvmfPkg/VirtioFsDxe: call IsTimeValid() before EfiTimeToEpoch()
Posted by Laszlo Ersek 3 years, 3 months ago
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
>>
> 
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#69922): https://edk2.groups.io/g/devel/message/69922
Mute This Topic: https://groups.io/mt/79495773/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-