<div dir="ltr"><div dir="ltr">On Fri, Dec 9, 2022 at 4:11 PM Savva Mitrofanov <<a href="mailto:savvamtr@gmail.com">savvamtr@gmail.com</a>> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Missing such comparison leads to infinite loop states, for example code<br>
which trying to read entire file can easily get out of bound of<br>
file size by passing position value which exceeds file size without this<br>
check. So we need to add there missing comparison between the desired<br>
position to be set and file size<br>
<br>
+  FileSize = EXT4_INODE_SIZE (File->Inode);<br>
+<br>
   // -1 (0xffffff.......) seeks to the end of the file<br>
   if (Position == (UINT64)-1) {<br>
-    Position = EXT4_INODE_SIZE (File->Inode);<br>
+    Position = FileSize;<br>
+  } else if (Position > FileSize) {<br>
+    DEBUG ((DEBUG_FS, "[ext4] Ext4SetPosition Cannot seek to #%Lx of %Lx\n", Position, FileSize));<br>
+    return EFI_UNSUPPORTED;<br>
   }<br>
<br>
   File->Position = Position;<br clear="all"></blockquote><div><br></div><div>On further inspection, this case is covered in the UEFI spec.</div><div><br></div><div><a href="https://uefi.org/specs/UEFI/2.10/13_Protocols_Media_Access.html#efi-file-protocol-read">https://uefi.org/specs/UEFI/2.10/13_Protocols_Media_Access.html#efi-file-protocol-read</a> says:</div><div><br></div><div>> EFI_DEVICE_ERROR     On entry, the current file position is beyond the end of the file.</div><div><br></div><div>while the standard does not say SetPosition() can error out for bad seeks.<br></div><div><br></div><div>So I think we should allow this in SetPosition() and error out in Read(). Does this look good to you?</div><div> <br></div></div><div dir="ltr" class="gmail_signature"><div dir="ltr">Pedro<br></div></div></div>


 <div width="1" style="color:white;clear:both">_._,_._,_</div> <hr>   Groups.io Links:<p>   You receive all messages sent to this group.    <p> <a target="_blank" href="https://edk2.groups.io/g/devel/message/97214">View/Reply Online (#97214)</a> |    |  <a target="_blank" href="https://groups.io/mt/95563280/1813853">Mute This Topic</a>  | <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>    <a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> | <a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |  <a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>  [edk2-devel-archive@redhat.com]<br> <div width="1" style="color:white;clear:both">_._,_._,_</div>