diff options
author | Ard Biesheuvel <ardb@kernel.org> | 2023-05-04 16:40:18 +0200 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2023-05-05 08:11:22 +0000 |
commit | 94c802e108a082d6f74c854bea8bd98fe7808453 (patch) | |
tree | 9215506007fbcf1778be4d05a3776f75a1232314 /MdePkg/Library/BasePeCoffLib/BasePeCoff.c | |
parent | ff7cb2d7c98f8b832180e054848459fc24a0910a (diff) | |
download | edk2-94c802e108a082d6f74c854bea8bd98fe7808453.tar.gz edk2-94c802e108a082d6f74c854bea8bd98fe7808453.tar.bz2 edk2-94c802e108a082d6f74c854bea8bd98fe7808453.zip |
MdePkg/BasePeCoffLib: Deal with broken debug directories
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>
Diffstat (limited to 'MdePkg/Library/BasePeCoffLib/BasePeCoff.c')
-rw-r--r-- | MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c index 4b71176a0c..86ff2e769b 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -585,6 +585,7 @@ PeCoffLoaderGetImageInfo ( UINTN Size;
UINTN ReadSize;
UINTN Index;
+ UINTN NextIndex;
UINTN DebugDirectoryEntryRva;
UINTN DebugDirectoryEntryFileOffset;
UINTN SectionHeaderOffset;
@@ -755,6 +756,20 @@ PeCoffLoaderGetImageInfo ( ImageContext->ImageSize += DebugEntry.SizeOfData;
}
+ //
+ // Implementations of GenFw before commit 60e85a39fe49071 will
+ // concatenate the debug directory entry and the codeview entry,
+ // and erroneously put the combined size into the debug directory's
+ // size field. If this is the case, no other relevant directory
+ // entries can exist, and we can terminate here.
+ //
+ NextIndex = Index + sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);
+ if ((NextIndex < DebugDirectoryEntry->Size) &&
+ (DebugEntry.FileOffset == (DebugDirectoryEntryFileOffset + NextIndex)))
+ {
+ break;
+ }
+
continue;
}
|