Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd/gnu-efi/dist/lib The device path passed to ...



details:   https://anonhg.NetBSD.org/src/rev/f77a37d6445c
branches:  trunk
changeset: 1024427:f77a37d6445c
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Oct 23 15:20:26 2021 +0000

description:
The device path passed to EFI_BOOT_SERVICES.LocateDevicePath() may be
modified and the resulting device path may not be aligned in such a way
that the PathName string is not 16-bit aligned.

Fix OpenSimpleFileRead to make a copy of the device path to ensure
alignment before attempting to open a file. Idea from Tianocore's EFI
shell Library/FileIO.c LibOpenFile().

diffstat:

 sys/external/bsd/gnu-efi/dist/lib/sread.c |  22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diffs (60 lines):

diff -r f36a18b5cc47 -r f77a37d6445c sys/external/bsd/gnu-efi/dist/lib/sread.c
--- a/sys/external/bsd/gnu-efi/dist/lib/sread.c Sat Oct 23 07:45:03 2021 +0000
+++ b/sys/external/bsd/gnu-efi/dist/lib/sread.c Sat Oct 23 15:20:26 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sread.c,v 1.1.1.1 2014/04/01 16:16:07 jakllsch Exp $   */
+/*     $NetBSD: sread.c,v 1.2 2021/10/23 15:20:26 jmcneill Exp $       */
 
 /*++
 
@@ -61,11 +61,13 @@
     EFI_DEVICE_PATH             *TempFilePath;
     EFI_DEVICE_PATH             *TempFilePathPtr;
     FILEPATH_DEVICE_PATH        *FilePathNode;
+    EFI_DEVICE_PATH_PROTOCOL    *AlignedFilePath;
     EFI_FILE_HANDLE             FileHandle, LastHandle;
     EFI_STATUS                  Status;
     EFI_LOAD_FILE_INTERFACE     *LoadFile;
   
     FHand = NULL;
+    AlignedFilePath = NULL;
     UserFilePath = *FilePath;
 
     //
@@ -106,12 +108,24 @@
     Status = FileHandle ? EFI_SUCCESS : EFI_UNSUPPORTED;
 
     //
+    // Duplicate FilePath to make sure it is aligned so that
+    // FilePathNode->PathName below is 16-bit aligned.
+    //
+    AlignedFilePath = DuplicateDevicePath(*FilePath);
+    if (AlignedFilePath == NULL) {
+        if (FileHandle != NULL) {
+            uefi_call_wrapper(FileHandle->Close, 1, FileHandle);
+        }
+        return EFI_OUT_OF_RESOURCES;
+    }
+
+    //
     // To access as a filesystem, the filepath should only
     // contain filepath components.  Follow the filepath nodes
     // and find the target file
     //
 
-    FilePathNode = (FILEPATH_DEVICE_PATH *) *FilePath;
+    FilePathNode = (FILEPATH_DEVICE_PATH *)AlignedFilePath;
     while (!IsDevicePathEnd(&FilePathNode->Header)) {
 
         //
@@ -262,6 +276,10 @@
 
 Done:
 
+    if (AlignedFilePath) {
+        FreePool (AlignedFilePath);
+    }
+
     //
     // If the file was not accessed, clean up
     //



Home | Main Index | Thread Index | Old Index