]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VirtioFsDxe: call IsTimeValid() before EfiTimeToEpoch()
authorLaszlo Ersek <lersek@redhat.com>
Thu, 7 Jan 2021 09:50:51 +0000 (10:50 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 7 Jan 2021 14:13:44 +0000 (14:13 +0000)
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>
Message-Id: <20210107095051.22715-1-lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
OvmfPkg/VirtioFsDxe/Helpers.c

index 443bbdc616ac039bead49dd1847b5608cff3222e..b81c04e0a4e81df5d72f99d164c8f49d6784e15d 100644 (file)
@@ -2244,12 +2244,19 @@ VirtioFsGetFuseSizeUpdate (
                            since the Epoch). Otherwise, Mtime is not written\r
                            to.\r
 \r
-  @retval EFI_SUCCESS        Output parameters have been set successfully.\r
-\r
-  @retval EFI_ACCESS_DENIED  NewInfo requests changing both CreateTime and\r
-                             ModificationTime, but to values that differ from\r
-                             each other. The Virtio Filesystem device does not\r
-                             support this.\r
+  @retval EFI_SUCCESS            Output parameters have been set successfully.\r
+\r
+  @retval EFI_INVALID_PARAMETER  At least one of the CreateTime, LastAccessTime\r
+                                 and ModificationTime fields in NewInfo\r
+                                 represents an actual update relative to the\r
+                                 current state of the file (expressed in Info),\r
+                                 but does not satisfy the UEFI spec\r
+                                 requirements on EFI_TIME.\r
+\r
+  @retval EFI_ACCESS_DENIED      NewInfo requests changing both CreateTime and\r
+                                 ModificationTime, but to values that differ\r
+                                 from each other. The Virtio Filesystem device\r
+                                 does not support this.\r
 **/\r
 EFI_STATUS\r
 VirtioFsGetFuseTimeUpdates (\r
@@ -2285,6 +2292,9 @@ VirtioFsGetFuseTimeUpdates (
         CompareMem (NewTime[Idx], Time[Idx], sizeof (EFI_TIME)) == 0) {\r
       Change[Idx] = FALSE;\r
     } else {\r
+      if (!IsTimeValid (NewTime[Idx])) {\r
+        return EFI_INVALID_PARAMETER;\r
+      }\r
       Change[Idx] = TRUE;\r
       Seconds[Idx] = EfiTimeToEpoch (NewTime[Idx]);\r
     }\r