[edk2-devel] [edk2-platforms][PATCH v1 06/12] Ext4Pkg: Add comparison between Position and FileSize in Ext4SetPosition
Pedro Falcato
pedro.falcato at gmail.com
Fri Dec 9 22:12:27 UTC 2022
On Fri, Dec 9, 2022 at 4:11 PM Savva Mitrofanov <savvamtr at gmail.com> wrote:
> Missing such comparison leads to infinite loop states, for example code
> which trying to read entire file can easily get out of bound of
> file size by passing position value which exceeds file size without this
> check. So we need to add there missing comparison between the desired
> position to be set and file size
>
> + FileSize = EXT4_INODE_SIZE (File->Inode);
> +
> // -1 (0xffffff.......) seeks to the end of the file
> if (Position == (UINT64)-1) {
> - Position = EXT4_INODE_SIZE (File->Inode);
> + Position = FileSize;
> + } else if (Position > FileSize) {
> + DEBUG ((DEBUG_FS, "[ext4] Ext4SetPosition Cannot seek to #%Lx of
> %Lx\n", Position, FileSize));
> + return EFI_UNSUPPORTED;
> }
>
> File->Position = Position;
>
On further inspection, this case is covered in the UEFI spec.
https://uefi.org/specs/UEFI/2.10/13_Protocols_Media_Access.html#efi-file-protocol-read
says:
> EFI_DEVICE_ERROR On entry, the current file position is beyond the
end of the file.
while the standard does not say SetPosition() can error out for bad seeks.
So I think we should allow this in SetPosition() and error out in Read().
Does this look good to you?
Pedro
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97214): https://edk2.groups.io/g/devel/message/97214
Mute This Topic: https://groups.io/mt/95563280/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/edk2-devel-archive/attachments/20221209/9aa19e6d/attachment.htm>
More information about the edk2-devel-archive
mailing list