From 94af9da84b850a6552b384f5c2dcc4ddb5050486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Ha=CC=88user?= <8659494+mhaeuser@users.noreply.github.com> Date: Sat, 1 Apr 2023 23:14:48 +0200 Subject: [PATCH] MdePkg/BasePeCoffLib2: Distinguish between unsupported and corrupted --- MdePkg/Library/BasePeCoffLib2/PeCoffDebug.c | 22 +++--- MdePkg/Library/BasePeCoffLib2/PeCoffHash.c | 12 +-- MdePkg/Library/BasePeCoffLib2/PeCoffHii.c | 26 +++---- MdePkg/Library/BasePeCoffLib2/PeCoffInit.c | 76 +++++++++---------- MdePkg/Library/BasePeCoffLib2/PeCoffLoad.c | 2 +- .../Library/BasePeCoffLib2/PeCoffRelocate.c | 36 ++++----- 6 files changed, 85 insertions(+), 89 deletions(-) diff --git a/MdePkg/Library/BasePeCoffLib2/PeCoffDebug.c b/MdePkg/Library/BasePeCoffLib2/PeCoffDebug.c index 75b9ee9db1..e35d620235 100644 --- a/MdePkg/Library/BasePeCoffLib2/PeCoffDebug.c +++ b/MdePkg/Library/BasePeCoffLib2/PeCoffDebug.c @@ -107,7 +107,7 @@ PeCoffGetPdbPath ( default: ASSERT (FALSE); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Debug Directory is not empty. @@ -125,7 +125,7 @@ PeCoffGetPdbPath ( // Since this violates the spec and nobody but Apple has access // to the DEBUG symbols, just ignore this debug information. // - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Debug Directory is in bounds of the Image buffer. @@ -137,7 +137,7 @@ PeCoffGetPdbPath ( ); if (Overflow || DebugDirTop > Context->SizeOfImage) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Determine the raw file offset of the Debug Directory. @@ -157,7 +157,7 @@ PeCoffGetPdbPath ( // if (SectionIndex == Context->NumberOfSections) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Debug Directory data is in bounds of the Image section. @@ -170,7 +170,7 @@ PeCoffGetPdbPath ( DebugDirSectionRawTop = DebugDirSectionOffset + DebugDir->Size; if (DebugDirSectionRawTop > Sections[SectionIndex].SizeOfRawData) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Debug Directory raw file offset is sufficiently aligned. @@ -190,7 +190,7 @@ PeCoffGetPdbPath ( if (!IS_ALIGNED (DebugDirFileOffset, ALIGNOF (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY))) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } DebugEntries = (CONST EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) (CONST VOID *) ( @@ -217,7 +217,7 @@ PeCoffGetPdbPath ( if (CodeViewEntry->SizeOfData < sizeof (UINT32)) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } DebugEntryFileOffset = CodeViewEntry->FileOffset; @@ -230,7 +230,7 @@ PeCoffGetPdbPath ( ); if (Overflow) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } else { ASSERT (Context->TeStrippedOffset == 0); @@ -247,7 +247,7 @@ PeCoffGetPdbPath ( if (Overflow || DebugEntryFileOffsetTop > Context->FileSize || !IS_ALIGNED (DebugEntryFileOffset, ALIGNOF (UINT32))) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } CodeView = (CONST CHAR8 *) Context->FileBuffer + DebugEntryFileOffset; @@ -298,7 +298,7 @@ PeCoffGetPdbPath ( ); if (Overflow || PdbNameSize == 0) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the PDB path is correctly terminated. @@ -306,7 +306,7 @@ PeCoffGetPdbPath ( PdbName = CodeView + PdbOffset; if (PdbName[PdbNameSize - 1] != 0) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } *PdbPath = PdbName; diff --git a/MdePkg/Library/BasePeCoffLib2/PeCoffHash.c b/MdePkg/Library/BasePeCoffLib2/PeCoffHash.c index 9418b4d6ba..f35d5ac25c 100644 --- a/MdePkg/Library/BasePeCoffLib2/PeCoffHash.c +++ b/MdePkg/Library/BasePeCoffLib2/PeCoffHash.c @@ -381,7 +381,7 @@ PeCoffGetFirstCertificate ( if (WinCertificate->dwLength < sizeof (WIN_CERTIFICATE) || WinCertificate->dwLength > Context->SecDirSize) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the certificate size is sufficiently aligned, if the policy demands @@ -391,7 +391,7 @@ PeCoffGetFirstCertificate ( if ((PcdGet32 (PcdImageLoaderAlignmentPolicy) & PCD_ALIGNMENT_POLICY_CERTIFICATE_SIZES) == 0) { if (!IS_ALIGNED (WinCertificate->dwLength, IMAGE_CERTIFICATE_ALIGN)) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } @@ -446,7 +446,7 @@ PeCoffGetNextCertificate ( // if (Context->SecDirSize - CertOffset < sizeof (WIN_CERTIFICATE)) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the certificate has a well-formed size. @@ -456,7 +456,7 @@ PeCoffGetNextCertificate ( ); if (WinCertificate->dwLength < sizeof (WIN_CERTIFICATE)) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the certificate size is sufficiently aligned, if the policy demands @@ -465,7 +465,7 @@ PeCoffGetNextCertificate ( if ((PcdGet32 (PcdImageLoaderAlignmentPolicy) & PCD_ALIGNMENT_POLICY_CERTIFICATE_SIZES) == 0) { if (!IS_ALIGNED (WinCertificate->dwLength, IMAGE_CERTIFICATE_ALIGN)) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } // @@ -478,7 +478,7 @@ PeCoffGetNextCertificate ( ); if (Overflow || CertEnd > Context->SecDirSize) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } *Certificate = WinCertificate; diff --git a/MdePkg/Library/BasePeCoffLib2/PeCoffHii.c b/MdePkg/Library/BasePeCoffLib2/PeCoffHii.c index 99bfcf1678..c4ba470d06 100644 --- a/MdePkg/Library/BasePeCoffLib2/PeCoffHii.c +++ b/MdePkg/Library/BasePeCoffLib2/PeCoffHii.c @@ -97,7 +97,7 @@ PeCoffGetHiiDataRva ( // if (!IS_ALIGNED (ResDirTable->VirtualAddress, ALIGNOF (EFI_IMAGE_RESOURCE_DIRECTORY))) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // FIXME: Verify against first Image section / Headers due to XIP TE. // @@ -110,7 +110,7 @@ PeCoffGetHiiDataRva ( ); if (Overflow || TopOffset > Context->SizeOfImage) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } ResourceDir = (CONST EFI_IMAGE_RESOURCE_DIRECTORY *) (CONST VOID *) ( @@ -127,7 +127,7 @@ PeCoffGetHiiDataRva ( ((UINT32) ResourceDir->NumberOfNamedEntries + ResourceDir->NumberOfIdEntries); if (TopOffset > ResDirTable->Size) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Try to locate the "HII" Resource entry. @@ -151,7 +151,7 @@ PeCoffGetHiiDataRva ( ); if (Overflow || TopOffset > ResDirTable->Size) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Resource Directory String offset is sufficiently aligned. @@ -159,7 +159,7 @@ PeCoffGetHiiDataRva ( Offset = ResDirTable->VirtualAddress + ResourceDirEntry->u1.s.NameOffset; if (!IS_ALIGNED (Offset, ALIGNOF (EFI_IMAGE_RESOURCE_DIRECTORY_STRING))) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } ResourceDirString = (CONST EFI_IMAGE_RESOURCE_DIRECTORY_STRING *) (CONST VOID *) ( @@ -176,7 +176,7 @@ PeCoffGetHiiDataRva ( ); if (Overflow || TopOffset > ResDirTable->Size) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the type name matches "HII". @@ -211,7 +211,7 @@ PeCoffGetHiiDataRva ( // if (ResourceDirEntry->u2.s.OffsetToDirectory > ResDirTable->Size - sizeof (EFI_IMAGE_RESOURCE_DIRECTORY) + sizeof (*ResourceDir->Entries)) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the next Relocation Directory offset is sufficiently aligned. @@ -219,7 +219,7 @@ PeCoffGetHiiDataRva ( Offset = ResDirTable->VirtualAddress + ResourceDirEntry->u2.s.OffsetToDirectory; if (!IS_ALIGNED (Offset, ALIGNOF (EFI_IMAGE_RESOURCE_DIRECTORY))) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Resource Directory has at least one entry. @@ -229,7 +229,7 @@ PeCoffGetHiiDataRva ( ); if ((UINT32) ResourceDir->NumberOfIdEntries + ResourceDir->NumberOfNamedEntries == 0) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Always take the first entry for simplicity. @@ -241,7 +241,7 @@ PeCoffGetHiiDataRva ( // if (ResourceDirEntry->u2.s.DataIsDirectory != 0) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Resource Directory Table fits at least the Resource Directory. @@ -252,7 +252,7 @@ PeCoffGetHiiDataRva ( ); if (ResourceDirEntry->u2.OffsetToData > ResDirTable->Size - sizeof (EFI_IMAGE_RESOURCE_DATA_ENTRY)) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Relocation Directory Entry offset is sufficiently aligned. @@ -260,7 +260,7 @@ PeCoffGetHiiDataRva ( Offset = ResDirTable->VirtualAddress + ResourceDirEntry->u2.OffsetToData; if (!IS_ALIGNED (Offset, ALIGNOF (EFI_IMAGE_RESOURCE_DATA_ENTRY))) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } ResourceDataEntry = (CONST EFI_IMAGE_RESOURCE_DATA_ENTRY *) (CONST VOID *) ( @@ -276,7 +276,7 @@ PeCoffGetHiiDataRva ( ); if (Overflow || HiiRvaEnd > Context->SizeOfImage) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } *HiiRva = ResourceDataEntry->OffsetToData; diff --git a/MdePkg/Library/BasePeCoffLib2/PeCoffInit.c b/MdePkg/Library/BasePeCoffLib2/PeCoffInit.c index b4e747e0b2..cffb1410db 100644 --- a/MdePkg/Library/BasePeCoffLib2/PeCoffInit.c +++ b/MdePkg/Library/BasePeCoffLib2/PeCoffInit.c @@ -70,7 +70,7 @@ InternalVerifySections ( // Images without Sections have no usable data, disallow them. // if (Context->NumberOfSections == 0) { - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } Sections = (CONST EFI_IMAGE_SECTION_HEADER *) (CONST VOID *) ( @@ -89,7 +89,7 @@ InternalVerifySections ( if (!PcdGetBool (PcdImageLoaderProhibitTe)) { if (Context->ImageType == PeCoffLoaderTypeTe) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } else { ASSERT (Context->ImageType != PeCoffLoaderTypeTe); @@ -109,7 +109,7 @@ InternalVerifySections ( ); if (Overflow) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } else { NextSectRva = Context->SizeOfHeaders; @@ -128,7 +128,7 @@ InternalVerifySections ( if (PcdGetBool (PcdImageLoaderWXorX) && !PcdGetBool (PcdImageLoaderRemoveXForWX)) { if ((Sections[SectionIndex].Characteristics & (EFI_IMAGE_SCN_MEM_EXECUTE | EFI_IMAGE_SCN_MEM_WRITE)) == (EFI_IMAGE_SCN_MEM_EXECUTE | EFI_IMAGE_SCN_MEM_WRITE)) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } // @@ -140,12 +140,12 @@ InternalVerifySections ( if ((PcdGet32 (PcdImageLoaderAlignmentPolicy) & PCD_ALIGNMENT_POLICY_CONTIGUOUS_SECTIONS) == 0) { if (Sections[SectionIndex].VirtualAddress != NextSectRva) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } else { if (Sections[SectionIndex].VirtualAddress < NextSectRva) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // If the Image section address is not aligned by the Image section @@ -176,7 +176,7 @@ InternalVerifySections ( if (!PcdGetBool (PcdImageLoaderProhibitTe)) { if (Context->TeStrippedOffset > Sections[SectionIndex].PointerToRawData) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } else { ASSERT (Context->TeStrippedOffset == 0); @@ -189,7 +189,7 @@ InternalVerifySections ( ); if (Overflow) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } if (!PcdGetBool (PcdImageLoaderProhibitTe)) { @@ -201,7 +201,7 @@ InternalVerifySections ( if (EffectiveSectRawEnd > FileSize) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } // @@ -214,7 +214,7 @@ InternalVerifySections ( ); if (Overflow) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // VirtualSize does not need to be aligned, so align the result if needed. @@ -227,7 +227,7 @@ InternalVerifySections ( ); if (Overflow) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } } @@ -311,14 +311,14 @@ InternalValidateRelocInfo ( // if (sizeof (EFI_IMAGE_BASE_RELOCATION_BLOCK) > Context->RelocDirSize) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Relocation Directory does not overlap with the Image Headers. // if (StartAddress > Context->RelocDirRva) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Relocation Directory is contained in the Image memory space. @@ -330,14 +330,14 @@ InternalValidateRelocInfo ( ); if (Overflow || SectRvaEnd > Context->SizeOfImage) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Relocation Directory start is sufficiently aligned. // if (!IS_ALIGNED (Context->RelocDirRva, ALIGNOF (EFI_IMAGE_BASE_RELOCATION_BLOCK))) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } // @@ -346,7 +346,7 @@ InternalValidateRelocInfo ( // FIXME: Only with force-aligned sections? What to do with XIP? if (!IS_ALIGNED (Context->ImageBase, (UINT64) Context->SectionAlignment)) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } return RETURN_SUCCESS; @@ -401,7 +401,7 @@ InternalInitializeTe ( ); if (Overflow) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } STATIC_ASSERT ( @@ -420,7 +420,7 @@ InternalInitializeTe ( // if (Context->SizeOfHeaders - Context->TeStrippedOffset > FileSize) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } STATIC_ASSERT ( @@ -456,7 +456,7 @@ InternalInitializeTe ( // if (TeHdr->AddressOfEntryPoint >= Context->SizeOfImage) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } Context->Machine = TeHdr->Machine; @@ -542,7 +542,7 @@ InternalInitializePe ( // if (sizeof (*Pe32) > FileSize - Context->ExeHdrOffset) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // The PE32 header offset is always sufficiently aligned. @@ -580,7 +580,7 @@ InternalInitializePe ( // if (sizeof (*Pe32Plus) > FileSize - Context->ExeHdrOffset) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the PE32+ header offset is sufficiently aligned. @@ -588,7 +588,7 @@ InternalInitializePe ( if (!PcdGetBool (PcdImageLoaderAllowMisalignedOffset) && !IS_ALIGNED (Context->ExeHdrOffset, ALIGNOF (EFI_IMAGE_NT_HEADERS64))) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Populate the common data with information from the Optional Header. @@ -625,14 +625,14 @@ InternalInitializePe ( // if (NumberOfRvaAndSizes > EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Image alignment is a power of 2. // if (!IS_POW2 (Context->SectionAlignment)) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } STATIC_ASSERT ( @@ -653,7 +653,7 @@ InternalInitializePe ( ); if (Overflow) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Section Headers offset is sufficiently aligned. @@ -661,7 +661,7 @@ InternalInitializePe ( if (!PcdGetBool (PcdImageLoaderAllowMisalignedOffset) && !IS_ALIGNED (Context->SectionsOffset, ALIGNOF (EFI_IMAGE_SECTION_HEADER))) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // This arithmetic cannot overflow because all values are sufficiently @@ -686,7 +686,7 @@ InternalInitializePe ( ); if (Overflow) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Image Header sizes are sane. SizeOfHeaders contains all header @@ -694,19 +694,19 @@ InternalInitializePe ( // if (MinSizeOfOptionalHeader > PeCommon->FileHeader.SizeOfOptionalHeader) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } if (MinSizeOfHeaders > Context->SizeOfHeaders) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Image Headers are in bounds of the file buffer. // if (Context->SizeOfHeaders > FileSize) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Populate the Image context with information from the Common Header. @@ -724,7 +724,7 @@ InternalInitializePe ( if (Context->RelocsStripped && Context->RelocDirSize != 0) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } else { ASSERT (Context->RelocDirRva == 0); @@ -744,14 +744,14 @@ InternalInitializePe ( ); if (Overflow || SecDirEnd > FileSize) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Security Directory is sufficiently aligned. // if (!IS_ALIGNED (Context->SecDirOffset, IMAGE_CERTIFICATE_ALIGN)) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Security Directory size is sufficiently aligned, and that if @@ -761,7 +761,7 @@ InternalInitializePe ( && (!IS_ALIGNED (Context->SecDirSize, IMAGE_CERTIFICATE_ALIGN) || Context->SecDirSize < sizeof (WIN_CERTIFICATE))) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } else { // @@ -789,7 +789,7 @@ InternalInitializePe ( // if (Context->AddressOfEntryPoint >= Context->SizeOfImage) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the basic Relocation information is well-formed. @@ -836,7 +836,7 @@ PeCoffInitializeContext ( if (sizeof (EFI_IMAGE_DOS_HEADER) > DosHdr->e_lfanew || DosHdr->e_lfanew > FileSize) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } Context->ExeHdrOffset = DosHdr->e_lfanew; @@ -863,7 +863,6 @@ PeCoffInitializeContext ( // Verify the file buffer can hold a PE Common Header. // if (FileSize - Context->ExeHdrOffset < sizeof (EFI_IMAGE_NT_HEADERS_COMMON_HDR) + sizeof (UINT16)) { - DEBUG_RAISE (); return RETURN_UNSUPPORTED; } // @@ -871,7 +870,6 @@ PeCoffInitializeContext ( // if (!PcdGetBool (PcdImageLoaderAllowMisalignedOffset) && !IS_ALIGNED (Context->ExeHdrOffset, ALIGNOF (EFI_IMAGE_NT_HEADERS_COMMON_HDR))) { - DEBUG_RAISE (); return RETURN_UNSUPPORTED; } @@ -883,7 +881,6 @@ PeCoffInitializeContext ( // Verify the Image Executable Header has a PE signature. // if (*(CONST UINT32 *) (CONST VOID *) ((CONST CHAR8 *) FileBuffer + Context->ExeHdrOffset) != EFI_IMAGE_NT_SIGNATURE) { - DEBUG_RAISE (); return RETURN_UNSUPPORTED; } // @@ -891,7 +888,6 @@ PeCoffInitializeContext ( // Status = InternalInitializePe (Context, FileSize); if (Status != RETURN_SUCCESS) { - DEBUG_RAISE (); return Status; } diff --git a/MdePkg/Library/BasePeCoffLib2/PeCoffLoad.c b/MdePkg/Library/BasePeCoffLib2/PeCoffLoad.c index 8923dec707..0a33419440 100644 --- a/MdePkg/Library/BasePeCoffLib2/PeCoffLoad.c +++ b/MdePkg/Library/BasePeCoffLib2/PeCoffLoad.c @@ -160,7 +160,7 @@ PeCoffLoadImageInplaceNoBase ( if (Sections[SectionIndex].PointerToRawData != Sections[SectionIndex].VirtualAddress || Sections[SectionIndex].SizeOfRawData != AlignedSize) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } diff --git a/MdePkg/Library/BasePeCoffLib2/PeCoffRelocate.c b/MdePkg/Library/BasePeCoffLib2/PeCoffRelocate.c index 34a598cb73..e46d70ea49 100644 --- a/MdePkg/Library/BasePeCoffLib2/PeCoffRelocate.c +++ b/MdePkg/Library/BasePeCoffLib2/PeCoffRelocate.c @@ -269,7 +269,7 @@ InternalApplyRelocation ( ); if (Overflow) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } Overflow = BaseOverflowSubU32 ( @@ -279,7 +279,7 @@ InternalApplyRelocation ( ); if (Overflow) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } Fixup = (CHAR8 *) Context->ImageBuffer + RelocTargetRva; @@ -303,7 +303,7 @@ InternalApplyRelocation ( // if (sizeof (UINT32) > RemRelocTargetSize) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Image Base Relocation does not target the Image Relocation @@ -312,7 +312,7 @@ InternalApplyRelocation ( if (RelocTargetRva + sizeof (UINT32) > Context->RelocDirRva && Context->RelocDirRva + Context->RelocDirSize > RelocTargetRva) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Relocate the target instruction. @@ -336,7 +336,7 @@ InternalApplyRelocation ( // if (sizeof (UINT64) > RemRelocTargetSize) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Image Base Relocation does not target the Image Relocation @@ -345,7 +345,7 @@ InternalApplyRelocation ( if (RelocTargetRva + sizeof (UINT64) > Context->RelocDirRva && Context->RelocDirRva + Context->RelocDirSize > RelocTargetRva) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Relocate target the instruction. @@ -368,14 +368,14 @@ InternalApplyRelocation ( // if ((PcdGet32 (PcdImageLoaderRelocTypePolicy) & PCD_RELOC_TYPE_POLICY_ARM) == 0) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Base Relocation target is in bounds of the Image buffer. // if (sizeof (UINT64) > RemRelocTargetSize) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Base Relocation target is sufficiently aligned. @@ -383,7 +383,7 @@ InternalApplyRelocation ( // if (!IS_ALIGNED (RelocTargetRva, ALIGNOF (UINT32))) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Base Relocation does not target the Relocation Directory. @@ -391,7 +391,7 @@ InternalApplyRelocation ( if (RelocTargetRva + sizeof (UINT64) > Context->RelocDirRva && Context->RelocDirRva + Context->RelocDirSize > RelocTargetRva) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Relocate the target instruction. @@ -493,7 +493,7 @@ PeCoffRelocateImage ( ); if (Overflow) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } // @@ -513,7 +513,7 @@ PeCoffRelocateImage ( ); if (Overflow) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Verify the Base Relocation Block is in bounds of the Relocation @@ -521,7 +521,7 @@ PeCoffRelocateImage ( // if (SizeOfRelocs > RelocBlockOffsetMax - RelocBlockOffset) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Advance to the next Base Relocation Block offset based on the alignment @@ -534,7 +534,7 @@ PeCoffRelocateImage ( // if (!IS_ALIGNED (RelocBlockSize, ALIGNOF (EFI_IMAGE_BASE_RELOCATION_BLOCK))) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } } else { // @@ -603,7 +603,7 @@ PeCoffRelocateImage ( // if (RelocBlockOffset != TopOfRelocDir) { DEBUG_RAISE (); - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } // // Initialise the remaining uninitialised portion of the Image runtime @@ -674,7 +674,7 @@ InternalApplyRelocationRuntime ( return RETURN_SUCCESS; } - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } Fixup32 += (UINT32) Adjust; @@ -692,7 +692,7 @@ InternalApplyRelocationRuntime ( return RETURN_SUCCESS; } - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } Fixup64 += Adjust; @@ -712,7 +712,7 @@ InternalApplyRelocationRuntime ( return RETURN_SUCCESS; } - return RETURN_UNSUPPORTED; + return RETURN_VOLUME_CORRUPTED; } ThumbMovwMovtImmediateFixup (Fixup, Adjust);