* [PATCH] OvmfPkg/VirtioFsDxe: call IsTimeValid() before EfiTimeToEpoch()
@ 2021-01-07 9:50 Laszlo Ersek
2021-01-07 9:52 ` Ard Biesheuvel
0 siblings, 1 reply; 3+ messages in thread
From: Laszlo Ersek @ 2021-01-07 9:50 UTC (permalink / raw)
To: edk2-devel-groups-io
Cc: Ard Biesheuvel, Jordan Justen, Philippe Mathieu-Daudé
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] OvmfPkg/VirtioFsDxe: call IsTimeValid() before EfiTimeToEpoch()
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 ` [edk2-devel] " Laszlo Ersek
0 siblings, 1 reply; 3+ messages in thread
From: Ard Biesheuvel @ 2021-01-07 9:52 UTC (permalink / raw)
To: Laszlo Ersek, edk2-devel-groups-io
Cc: Jordan Justen, Philippe Mathieu-Daudé
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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [edk2-devel] [PATCH] OvmfPkg/VirtioFsDxe: call IsTimeValid() before EfiTimeToEpoch()
2021-01-07 9:52 ` Ard Biesheuvel
@ 2021-01-07 14:16 ` Laszlo Ersek
0 siblings, 0 replies; 3+ messages in thread
From: Laszlo Ersek @ 2021-01-07 14:16 UTC (permalink / raw)
To: devel, ard.biesheuvel; +Cc: Jordan Justen, Philippe Mathieu-Daudé
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
>>
>
>
>
>
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-07 14:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [edk2-devel] " Laszlo Ersek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox