From nobody Fri Apr 26 00:39:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69907+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69907+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1610013063; cv=none; d=zohomail.com; s=zohoarc; b=SIN7SB0sIdHJBrTRO1HauraUh2dJrc8SRwIBQjLYtOtc1EyLma7KxCW2Vq3sEX1/T31qfL1Jp47/C4A01HUb0knr6pNrIcic9SFLbogfwek48Xz4hgeOmC9dN6gqjxN/2Fl8pUDSXAESyH+h39RUWxt3nMl1JTFRWwebf9cOjVs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610013063; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=PAWe6B/FM995sfQXCZCRwghDonRxygt9buTWGL2Gg38=; b=mCsiWzkYrpSN/yjku/T2piczz7zV870+DOeJbhyzgL8+bIGNJs7n6qUVOCHiz7mkUjGyBV7ka0v0SeUtQvQYPHAmKx6kC5cvsJFL4zQ1iF4cRwsS7MPwdiv9XlJV88qDms7aDDEkdQyQFIhIcAdFvHPVHtf/7Fi0Wx/OfvuKkd8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69907+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1610013063441793.4687845524727; Thu, 7 Jan 2021 01:51:03 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id HIYhYY1788612xwUDvoLJyH6; Thu, 07 Jan 2021 01:51:03 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web11.6164.1610013057611835777 for ; Thu, 07 Jan 2021 01:50:57 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-319-G9i5pJDYMvOc5SdDklDKLw-1; Thu, 07 Jan 2021 04:50:55 -0500 X-MC-Unique: G9i5pJDYMvOc5SdDklDKLw-1 X-Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F15C1100F343; Thu, 7 Jan 2021 09:50:53 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-119.ams2.redhat.com [10.36.114.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id D645C5D9DC; Thu, 7 Jan 2021 09:50:52 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [PATCH] OvmfPkg/VirtioFsDxe: call IsTimeValid() before EfiTimeToEpoch() Date: Thu, 7 Jan 2021 10:50:51 +0100 Message-Id: <20210107095051.22715-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: XVMT6ekPrYr28UBtgT6bwKTTx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610013063; bh=PAWe6B/FM995sfQXCZCRwghDonRxygt9buTWGL2Gg38=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=tQ/s4/9cpK4xwAZ+sMILMCpFekWg9zRIiX6kjzXYQzAAnIBz+gtOkC4gOrI5y+IYswW RaodF4lCcKdUaCcWbnFQyyoVN5hWEi99/6uHlt8gg55AsofAZB2Z0CbtNWSydrxLSApXT IRxaWhg1KBee9tvYtYtp2rBlXOukDZvcXG0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" 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 Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- 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 ( =20 @param[out] Atime If UpdateAtime is set to TRUE, then Atime provi= des the last access timestamp to set (as seconds si= nce the Epoch). Otherwise, Atime is not written to. =20 @param[out] Mtime If UpdateMtime is set to TRUE, then Mtime provi= des the last modification timestamp to set (as seco= nds since the Epoch). Otherwise, Mtime is not writt= en to. =20 - @retval EFI_SUCCESS Output parameters have been set successfully. + @retval EFI_SUCCESS Output parameters have been set successfu= lly. =20 - @retval EFI_ACCESS_DENIED NewInfo requests changing both CreateTime and - ModificationTime, but to values that differ f= rom - each other. The Virtio Filesystem device does= not - support this. + @retval EFI_INVALID_PARAMETER At least one of the CreateTime, LastAcces= sTime + and ModificationTime fields in NewInfo + represents an actual update relative to t= he + current state of the file (expressed in I= nfo), + 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 diff= er + from each other. The Virtio Filesystem de= vice + 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 =3D 0; Idx < ARRAY_SIZE (Time); Idx++) { if (CompareMem (NewTime[Idx], &ZeroTime, sizeof (EFI_TIME)) =3D=3D 0 || CompareMem (NewTime[Idx], Time[Idx], sizeof (EFI_TIME)) =3D=3D 0) { Change[Idx] =3D FALSE; } else { + if (!IsTimeValid (NewTime[Idx])) { + return EFI_INVALID_PARAMETER; + } Change[Idx] =3D TRUE; Seconds[Idx] =3D EfiTimeToEpoch (NewTime[Idx]); } } =20 // // 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 --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-