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

Laszlo Ersek lersek at redhat.com
Thu Jan 7 09:50:51 UTC 2021


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 at arm.com>
Cc: Jordan Justen <jordan.l.justen at intel.com>
Cc: Philippe Mathieu-Daudé <philmd at redhat.com>
Signed-off-by: Laszlo Ersek <lersek at 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/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-






More information about the edk2-devel-archive mailing list