]> xenbits.xensource.com Git - ovmf.git/commitdiff
MdePkg/BasePeCoffLib: Deal with broken debug directories
authorArd Biesheuvel <ardb@kernel.org>
Thu, 4 May 2023 14:40:18 +0000 (16:40 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 5 May 2023 08:11:22 +0000 (08:11 +0000)
Older versions of GenFw put the wrong value in the debug directory size
field in the PE/COFF header: instead of putting the combined size of all
the entries, it puts the size of the only entry it creates, but adds the
size of the NB10 payload that the entry points to. This confuses the
loader now that we started using additional debug directory entries to
describe DLL characteristics.

GenFw was fixed in commit 60e85a39fe49071, but the binaries that were
generated with it still need to be supported.

So let's detect this condition, and check whether the size of the debug
directory is consistent with the NB10 payload: if we should expect
additional directory entries where we observe the NB10 payload, the size
field is clearly wrong, and we can break from the loop.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4425
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Tested-by: Liming Gao <gaoliming@byosoft.com.cn>
Acked-by: Michael Kubacki <michael.kubacki@microsoft.com>
MdePkg/Library/BasePeCoffLib/BasePeCoff.c

index 4b71176a0c7c2ed06b3a5025b1541effbf87de0b..86ff2e769b007c5c2dc7dc44ae1c0e1dced262ca 100644 (file)
@@ -585,6 +585,7 @@ PeCoffLoaderGetImageInfo (
   UINTN                                Size;\r
   UINTN                                ReadSize;\r
   UINTN                                Index;\r
+  UINTN                                NextIndex;\r
   UINTN                                DebugDirectoryEntryRva;\r
   UINTN                                DebugDirectoryEntryFileOffset;\r
   UINTN                                SectionHeaderOffset;\r
@@ -755,6 +756,20 @@ PeCoffLoaderGetImageInfo (
               ImageContext->ImageSize += DebugEntry.SizeOfData;\r
             }\r
 \r
+            //\r
+            // Implementations of GenFw before commit 60e85a39fe49071 will\r
+            // concatenate the debug directory entry and the codeview entry,\r
+            // and erroneously put the combined size into the debug directory's\r
+            // size field. If this is the case, no other relevant directory\r
+            // entries can exist, and we can terminate here.\r
+            //\r
+            NextIndex = Index + sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);\r
+            if ((NextIndex < DebugDirectoryEntry->Size) &&\r
+                (DebugEntry.FileOffset == (DebugDirectoryEntryFileOffset + NextIndex)))\r
+            {\r
+              break;\r
+            }\r
+\r
             continue;\r
           }\r
 \r