MdePkg/BasePeCoffLib2: Distinguish between unsupported and corrupted

This commit is contained in:
Marvin Häuser 2023-04-01 23:14:48 +02:00
parent 35731d9829
commit 94af9da84b
6 changed files with 85 additions and 89 deletions

View File

@ -107,7 +107,7 @@ PeCoffGetPdbPath (
default: default:
ASSERT (FALSE); ASSERT (FALSE);
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Debug Directory is not empty. // Verify the Debug Directory is not empty.
@ -125,7 +125,7 @@ PeCoffGetPdbPath (
// Since this violates the spec and nobody but Apple has access // Since this violates the spec and nobody but Apple has access
// to the DEBUG symbols, just ignore this debug information. // 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. // Verify the Debug Directory is in bounds of the Image buffer.
@ -137,7 +137,7 @@ PeCoffGetPdbPath (
); );
if (Overflow || DebugDirTop > Context->SizeOfImage) { if (Overflow || DebugDirTop > Context->SizeOfImage) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Determine the raw file offset of the Debug Directory. // Determine the raw file offset of the Debug Directory.
@ -157,7 +157,7 @@ PeCoffGetPdbPath (
// //
if (SectionIndex == Context->NumberOfSections) { if (SectionIndex == Context->NumberOfSections) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Debug Directory data is in bounds of the Image section. // Verify the Debug Directory data is in bounds of the Image section.
@ -170,7 +170,7 @@ PeCoffGetPdbPath (
DebugDirSectionRawTop = DebugDirSectionOffset + DebugDir->Size; DebugDirSectionRawTop = DebugDirSectionOffset + DebugDir->Size;
if (DebugDirSectionRawTop > Sections[SectionIndex].SizeOfRawData) { if (DebugDirSectionRawTop > Sections[SectionIndex].SizeOfRawData) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Debug Directory raw file offset is sufficiently aligned. // 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))) { if (!IS_ALIGNED (DebugDirFileOffset, ALIGNOF (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY))) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
DebugEntries = (CONST EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) (CONST VOID *) ( DebugEntries = (CONST EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) (CONST VOID *) (
@ -217,7 +217,7 @@ PeCoffGetPdbPath (
if (CodeViewEntry->SizeOfData < sizeof (UINT32)) { if (CodeViewEntry->SizeOfData < sizeof (UINT32)) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
DebugEntryFileOffset = CodeViewEntry->FileOffset; DebugEntryFileOffset = CodeViewEntry->FileOffset;
@ -230,7 +230,7 @@ PeCoffGetPdbPath (
); );
if (Overflow) { if (Overflow) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
} else { } else {
ASSERT (Context->TeStrippedOffset == 0); ASSERT (Context->TeStrippedOffset == 0);
@ -247,7 +247,7 @@ PeCoffGetPdbPath (
if (Overflow || DebugEntryFileOffsetTop > Context->FileSize if (Overflow || DebugEntryFileOffsetTop > Context->FileSize
|| !IS_ALIGNED (DebugEntryFileOffset, ALIGNOF (UINT32))) { || !IS_ALIGNED (DebugEntryFileOffset, ALIGNOF (UINT32))) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
CodeView = (CONST CHAR8 *) Context->FileBuffer + DebugEntryFileOffset; CodeView = (CONST CHAR8 *) Context->FileBuffer + DebugEntryFileOffset;
@ -298,7 +298,7 @@ PeCoffGetPdbPath (
); );
if (Overflow || PdbNameSize == 0) { if (Overflow || PdbNameSize == 0) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the PDB path is correctly terminated. // Verify the PDB path is correctly terminated.
@ -306,7 +306,7 @@ PeCoffGetPdbPath (
PdbName = CodeView + PdbOffset; PdbName = CodeView + PdbOffset;
if (PdbName[PdbNameSize - 1] != 0) { if (PdbName[PdbNameSize - 1] != 0) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
*PdbPath = PdbName; *PdbPath = PdbName;

View File

@ -381,7 +381,7 @@ PeCoffGetFirstCertificate (
if (WinCertificate->dwLength < sizeof (WIN_CERTIFICATE) if (WinCertificate->dwLength < sizeof (WIN_CERTIFICATE)
|| WinCertificate->dwLength > Context->SecDirSize) { || WinCertificate->dwLength > Context->SecDirSize) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the certificate size is sufficiently aligned, if the policy demands // 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 ((PcdGet32 (PcdImageLoaderAlignmentPolicy) & PCD_ALIGNMENT_POLICY_CERTIFICATE_SIZES) == 0) {
if (!IS_ALIGNED (WinCertificate->dwLength, IMAGE_CERTIFICATE_ALIGN)) { if (!IS_ALIGNED (WinCertificate->dwLength, IMAGE_CERTIFICATE_ALIGN)) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
} }
@ -446,7 +446,7 @@ PeCoffGetNextCertificate (
// //
if (Context->SecDirSize - CertOffset < sizeof (WIN_CERTIFICATE)) { if (Context->SecDirSize - CertOffset < sizeof (WIN_CERTIFICATE)) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the certificate has a well-formed size. // Verify the certificate has a well-formed size.
@ -456,7 +456,7 @@ PeCoffGetNextCertificate (
); );
if (WinCertificate->dwLength < sizeof (WIN_CERTIFICATE)) { if (WinCertificate->dwLength < sizeof (WIN_CERTIFICATE)) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the certificate size is sufficiently aligned, if the policy demands // 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 ((PcdGet32 (PcdImageLoaderAlignmentPolicy) & PCD_ALIGNMENT_POLICY_CERTIFICATE_SIZES) == 0) {
if (!IS_ALIGNED (WinCertificate->dwLength, IMAGE_CERTIFICATE_ALIGN)) { if (!IS_ALIGNED (WinCertificate->dwLength, IMAGE_CERTIFICATE_ALIGN)) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
} }
// //
@ -478,7 +478,7 @@ PeCoffGetNextCertificate (
); );
if (Overflow || CertEnd > Context->SecDirSize) { if (Overflow || CertEnd > Context->SecDirSize) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
*Certificate = WinCertificate; *Certificate = WinCertificate;

View File

@ -97,7 +97,7 @@ PeCoffGetHiiDataRva (
// //
if (!IS_ALIGNED (ResDirTable->VirtualAddress, ALIGNOF (EFI_IMAGE_RESOURCE_DIRECTORY))) { if (!IS_ALIGNED (ResDirTable->VirtualAddress, ALIGNOF (EFI_IMAGE_RESOURCE_DIRECTORY))) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// FIXME: Verify against first Image section / Headers due to XIP TE. // FIXME: Verify against first Image section / Headers due to XIP TE.
// //
@ -110,7 +110,7 @@ PeCoffGetHiiDataRva (
); );
if (Overflow || TopOffset > Context->SizeOfImage) { if (Overflow || TopOffset > Context->SizeOfImage) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
ResourceDir = (CONST EFI_IMAGE_RESOURCE_DIRECTORY *) (CONST VOID *) ( ResourceDir = (CONST EFI_IMAGE_RESOURCE_DIRECTORY *) (CONST VOID *) (
@ -127,7 +127,7 @@ PeCoffGetHiiDataRva (
((UINT32) ResourceDir->NumberOfNamedEntries + ResourceDir->NumberOfIdEntries); ((UINT32) ResourceDir->NumberOfNamedEntries + ResourceDir->NumberOfIdEntries);
if (TopOffset > ResDirTable->Size) { if (TopOffset > ResDirTable->Size) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Try to locate the "HII" Resource entry. // Try to locate the "HII" Resource entry.
@ -151,7 +151,7 @@ PeCoffGetHiiDataRva (
); );
if (Overflow || TopOffset > ResDirTable->Size) { if (Overflow || TopOffset > ResDirTable->Size) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Resource Directory String offset is sufficiently aligned. // Verify the Resource Directory String offset is sufficiently aligned.
@ -159,7 +159,7 @@ PeCoffGetHiiDataRva (
Offset = ResDirTable->VirtualAddress + ResourceDirEntry->u1.s.NameOffset; Offset = ResDirTable->VirtualAddress + ResourceDirEntry->u1.s.NameOffset;
if (!IS_ALIGNED (Offset, ALIGNOF (EFI_IMAGE_RESOURCE_DIRECTORY_STRING))) { if (!IS_ALIGNED (Offset, ALIGNOF (EFI_IMAGE_RESOURCE_DIRECTORY_STRING))) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
ResourceDirString = (CONST EFI_IMAGE_RESOURCE_DIRECTORY_STRING *) (CONST VOID *) ( ResourceDirString = (CONST EFI_IMAGE_RESOURCE_DIRECTORY_STRING *) (CONST VOID *) (
@ -176,7 +176,7 @@ PeCoffGetHiiDataRva (
); );
if (Overflow || TopOffset > ResDirTable->Size) { if (Overflow || TopOffset > ResDirTable->Size) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the type name matches "HII". // 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)) { if (ResourceDirEntry->u2.s.OffsetToDirectory > ResDirTable->Size - sizeof (EFI_IMAGE_RESOURCE_DIRECTORY) + sizeof (*ResourceDir->Entries)) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the next Relocation Directory offset is sufficiently aligned. // Verify the next Relocation Directory offset is sufficiently aligned.
@ -219,7 +219,7 @@ PeCoffGetHiiDataRva (
Offset = ResDirTable->VirtualAddress + ResourceDirEntry->u2.s.OffsetToDirectory; Offset = ResDirTable->VirtualAddress + ResourceDirEntry->u2.s.OffsetToDirectory;
if (!IS_ALIGNED (Offset, ALIGNOF (EFI_IMAGE_RESOURCE_DIRECTORY))) { if (!IS_ALIGNED (Offset, ALIGNOF (EFI_IMAGE_RESOURCE_DIRECTORY))) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Resource Directory has at least one entry. // Verify the Resource Directory has at least one entry.
@ -229,7 +229,7 @@ PeCoffGetHiiDataRva (
); );
if ((UINT32) ResourceDir->NumberOfIdEntries + ResourceDir->NumberOfNamedEntries == 0) { if ((UINT32) ResourceDir->NumberOfIdEntries + ResourceDir->NumberOfNamedEntries == 0) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Always take the first entry for simplicity. // Always take the first entry for simplicity.
@ -241,7 +241,7 @@ PeCoffGetHiiDataRva (
// //
if (ResourceDirEntry->u2.s.DataIsDirectory != 0) { if (ResourceDirEntry->u2.s.DataIsDirectory != 0) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Resource Directory Table fits at least the Resource Directory. // 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)) { if (ResourceDirEntry->u2.OffsetToData > ResDirTable->Size - sizeof (EFI_IMAGE_RESOURCE_DATA_ENTRY)) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Relocation Directory Entry offset is sufficiently aligned. // Verify the Relocation Directory Entry offset is sufficiently aligned.
@ -260,7 +260,7 @@ PeCoffGetHiiDataRva (
Offset = ResDirTable->VirtualAddress + ResourceDirEntry->u2.OffsetToData; Offset = ResDirTable->VirtualAddress + ResourceDirEntry->u2.OffsetToData;
if (!IS_ALIGNED (Offset, ALIGNOF (EFI_IMAGE_RESOURCE_DATA_ENTRY))) { if (!IS_ALIGNED (Offset, ALIGNOF (EFI_IMAGE_RESOURCE_DATA_ENTRY))) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
ResourceDataEntry = (CONST EFI_IMAGE_RESOURCE_DATA_ENTRY *) (CONST VOID *) ( ResourceDataEntry = (CONST EFI_IMAGE_RESOURCE_DATA_ENTRY *) (CONST VOID *) (
@ -276,7 +276,7 @@ PeCoffGetHiiDataRva (
); );
if (Overflow || HiiRvaEnd > Context->SizeOfImage) { if (Overflow || HiiRvaEnd > Context->SizeOfImage) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
*HiiRva = ResourceDataEntry->OffsetToData; *HiiRva = ResourceDataEntry->OffsetToData;

View File

@ -70,7 +70,7 @@ InternalVerifySections (
// Images without Sections have no usable data, disallow them. // Images without Sections have no usable data, disallow them.
// //
if (Context->NumberOfSections == 0) { if (Context->NumberOfSections == 0) {
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
Sections = (CONST EFI_IMAGE_SECTION_HEADER *) (CONST VOID *) ( Sections = (CONST EFI_IMAGE_SECTION_HEADER *) (CONST VOID *) (
@ -89,7 +89,7 @@ InternalVerifySections (
if (!PcdGetBool (PcdImageLoaderProhibitTe)) { if (!PcdGetBool (PcdImageLoaderProhibitTe)) {
if (Context->ImageType == PeCoffLoaderTypeTe) { if (Context->ImageType == PeCoffLoaderTypeTe) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
} else { } else {
ASSERT (Context->ImageType != PeCoffLoaderTypeTe); ASSERT (Context->ImageType != PeCoffLoaderTypeTe);
@ -109,7 +109,7 @@ InternalVerifySections (
); );
if (Overflow) { if (Overflow) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
} else { } else {
NextSectRva = Context->SizeOfHeaders; NextSectRva = Context->SizeOfHeaders;
@ -128,7 +128,7 @@ InternalVerifySections (
if (PcdGetBool (PcdImageLoaderWXorX) && !PcdGetBool (PcdImageLoaderRemoveXForWX)) { 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)) { 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 (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
} }
// //
@ -140,12 +140,12 @@ InternalVerifySections (
if ((PcdGet32 (PcdImageLoaderAlignmentPolicy) & PCD_ALIGNMENT_POLICY_CONTIGUOUS_SECTIONS) == 0) { if ((PcdGet32 (PcdImageLoaderAlignmentPolicy) & PCD_ALIGNMENT_POLICY_CONTIGUOUS_SECTIONS) == 0) {
if (Sections[SectionIndex].VirtualAddress != NextSectRva) { if (Sections[SectionIndex].VirtualAddress != NextSectRva) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
} else { } else {
if (Sections[SectionIndex].VirtualAddress < NextSectRva) { if (Sections[SectionIndex].VirtualAddress < NextSectRva) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// If the Image section address is not aligned by the Image section // If the Image section address is not aligned by the Image section
@ -176,7 +176,7 @@ InternalVerifySections (
if (!PcdGetBool (PcdImageLoaderProhibitTe)) { if (!PcdGetBool (PcdImageLoaderProhibitTe)) {
if (Context->TeStrippedOffset > Sections[SectionIndex].PointerToRawData) { if (Context->TeStrippedOffset > Sections[SectionIndex].PointerToRawData) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
} else { } else {
ASSERT (Context->TeStrippedOffset == 0); ASSERT (Context->TeStrippedOffset == 0);
@ -189,7 +189,7 @@ InternalVerifySections (
); );
if (Overflow) { if (Overflow) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
if (!PcdGetBool (PcdImageLoaderProhibitTe)) { if (!PcdGetBool (PcdImageLoaderProhibitTe)) {
@ -201,7 +201,7 @@ InternalVerifySections (
if (EffectiveSectRawEnd > FileSize) { if (EffectiveSectRawEnd > FileSize) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
} }
// //
@ -214,7 +214,7 @@ InternalVerifySections (
); );
if (Overflow) { if (Overflow) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// VirtualSize does not need to be aligned, so align the result if needed. // VirtualSize does not need to be aligned, so align the result if needed.
@ -227,7 +227,7 @@ InternalVerifySections (
); );
if (Overflow) { if (Overflow) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
} }
} }
@ -311,14 +311,14 @@ InternalValidateRelocInfo (
// //
if (sizeof (EFI_IMAGE_BASE_RELOCATION_BLOCK) > Context->RelocDirSize) { if (sizeof (EFI_IMAGE_BASE_RELOCATION_BLOCK) > Context->RelocDirSize) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Relocation Directory does not overlap with the Image Headers. // Verify the Relocation Directory does not overlap with the Image Headers.
// //
if (StartAddress > Context->RelocDirRva) { if (StartAddress > Context->RelocDirRva) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Relocation Directory is contained in the Image memory space. // Verify the Relocation Directory is contained in the Image memory space.
@ -330,14 +330,14 @@ InternalValidateRelocInfo (
); );
if (Overflow || SectRvaEnd > Context->SizeOfImage) { if (Overflow || SectRvaEnd > Context->SizeOfImage) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Relocation Directory start is sufficiently aligned. // Verify the Relocation Directory start is sufficiently aligned.
// //
if (!IS_ALIGNED (Context->RelocDirRva, ALIGNOF (EFI_IMAGE_BASE_RELOCATION_BLOCK))) { if (!IS_ALIGNED (Context->RelocDirRva, ALIGNOF (EFI_IMAGE_BASE_RELOCATION_BLOCK))) {
DEBUG_RAISE (); 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? // FIXME: Only with force-aligned sections? What to do with XIP?
if (!IS_ALIGNED (Context->ImageBase, (UINT64) Context->SectionAlignment)) { if (!IS_ALIGNED (Context->ImageBase, (UINT64) Context->SectionAlignment)) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
return RETURN_SUCCESS; return RETURN_SUCCESS;
@ -401,7 +401,7 @@ InternalInitializeTe (
); );
if (Overflow) { if (Overflow) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
STATIC_ASSERT ( STATIC_ASSERT (
@ -420,7 +420,7 @@ InternalInitializeTe (
// //
if (Context->SizeOfHeaders - Context->TeStrippedOffset > FileSize) { if (Context->SizeOfHeaders - Context->TeStrippedOffset > FileSize) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
STATIC_ASSERT ( STATIC_ASSERT (
@ -456,7 +456,7 @@ InternalInitializeTe (
// //
if (TeHdr->AddressOfEntryPoint >= Context->SizeOfImage) { if (TeHdr->AddressOfEntryPoint >= Context->SizeOfImage) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
Context->Machine = TeHdr->Machine; Context->Machine = TeHdr->Machine;
@ -542,7 +542,7 @@ InternalInitializePe (
// //
if (sizeof (*Pe32) > FileSize - Context->ExeHdrOffset) { if (sizeof (*Pe32) > FileSize - Context->ExeHdrOffset) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// The PE32 header offset is always sufficiently aligned. // The PE32 header offset is always sufficiently aligned.
@ -580,7 +580,7 @@ InternalInitializePe (
// //
if (sizeof (*Pe32Plus) > FileSize - Context->ExeHdrOffset) { if (sizeof (*Pe32Plus) > FileSize - Context->ExeHdrOffset) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the PE32+ header offset is sufficiently aligned. // Verify the PE32+ header offset is sufficiently aligned.
@ -588,7 +588,7 @@ InternalInitializePe (
if (!PcdGetBool (PcdImageLoaderAllowMisalignedOffset) if (!PcdGetBool (PcdImageLoaderAllowMisalignedOffset)
&& !IS_ALIGNED (Context->ExeHdrOffset, ALIGNOF (EFI_IMAGE_NT_HEADERS64))) { && !IS_ALIGNED (Context->ExeHdrOffset, ALIGNOF (EFI_IMAGE_NT_HEADERS64))) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Populate the common data with information from the Optional Header. // Populate the common data with information from the Optional Header.
@ -625,14 +625,14 @@ InternalInitializePe (
// //
if (NumberOfRvaAndSizes > EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES) { if (NumberOfRvaAndSizes > EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Image alignment is a power of 2. // Verify the Image alignment is a power of 2.
// //
if (!IS_POW2 (Context->SectionAlignment)) { if (!IS_POW2 (Context->SectionAlignment)) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
STATIC_ASSERT ( STATIC_ASSERT (
@ -653,7 +653,7 @@ InternalInitializePe (
); );
if (Overflow) { if (Overflow) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Section Headers offset is sufficiently aligned. // Verify the Section Headers offset is sufficiently aligned.
@ -661,7 +661,7 @@ InternalInitializePe (
if (!PcdGetBool (PcdImageLoaderAllowMisalignedOffset) if (!PcdGetBool (PcdImageLoaderAllowMisalignedOffset)
&& !IS_ALIGNED (Context->SectionsOffset, ALIGNOF (EFI_IMAGE_SECTION_HEADER))) { && !IS_ALIGNED (Context->SectionsOffset, ALIGNOF (EFI_IMAGE_SECTION_HEADER))) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// This arithmetic cannot overflow because all values are sufficiently // This arithmetic cannot overflow because all values are sufficiently
@ -686,7 +686,7 @@ InternalInitializePe (
); );
if (Overflow) { if (Overflow) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Image Header sizes are sane. SizeOfHeaders contains all header // Verify the Image Header sizes are sane. SizeOfHeaders contains all header
@ -694,19 +694,19 @@ InternalInitializePe (
// //
if (MinSizeOfOptionalHeader > PeCommon->FileHeader.SizeOfOptionalHeader) { if (MinSizeOfOptionalHeader > PeCommon->FileHeader.SizeOfOptionalHeader) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
if (MinSizeOfHeaders > Context->SizeOfHeaders) { if (MinSizeOfHeaders > Context->SizeOfHeaders) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Image Headers are in bounds of the file buffer. // Verify the Image Headers are in bounds of the file buffer.
// //
if (Context->SizeOfHeaders > FileSize) { if (Context->SizeOfHeaders > FileSize) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Populate the Image context with information from the Common Header. // Populate the Image context with information from the Common Header.
@ -724,7 +724,7 @@ InternalInitializePe (
if (Context->RelocsStripped && Context->RelocDirSize != 0) { if (Context->RelocsStripped && Context->RelocDirSize != 0) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
} else { } else {
ASSERT (Context->RelocDirRva == 0); ASSERT (Context->RelocDirRva == 0);
@ -744,14 +744,14 @@ InternalInitializePe (
); );
if (Overflow || SecDirEnd > FileSize) { if (Overflow || SecDirEnd > FileSize) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Security Directory is sufficiently aligned. // Verify the Security Directory is sufficiently aligned.
// //
if (!IS_ALIGNED (Context->SecDirOffset, IMAGE_CERTIFICATE_ALIGN)) { if (!IS_ALIGNED (Context->SecDirOffset, IMAGE_CERTIFICATE_ALIGN)) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Security Directory size is sufficiently aligned, and that if // Verify the Security Directory size is sufficiently aligned, and that if
@ -761,7 +761,7 @@ InternalInitializePe (
&& (!IS_ALIGNED (Context->SecDirSize, IMAGE_CERTIFICATE_ALIGN) && (!IS_ALIGNED (Context->SecDirSize, IMAGE_CERTIFICATE_ALIGN)
|| Context->SecDirSize < sizeof (WIN_CERTIFICATE))) { || Context->SecDirSize < sizeof (WIN_CERTIFICATE))) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
} else { } else {
// //
@ -789,7 +789,7 @@ InternalInitializePe (
// //
if (Context->AddressOfEntryPoint >= Context->SizeOfImage) { if (Context->AddressOfEntryPoint >= Context->SizeOfImage) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the basic Relocation information is well-formed. // Verify the basic Relocation information is well-formed.
@ -836,7 +836,7 @@ PeCoffInitializeContext (
if (sizeof (EFI_IMAGE_DOS_HEADER) > DosHdr->e_lfanew if (sizeof (EFI_IMAGE_DOS_HEADER) > DosHdr->e_lfanew
|| DosHdr->e_lfanew > FileSize) { || DosHdr->e_lfanew > FileSize) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
Context->ExeHdrOffset = DosHdr->e_lfanew; Context->ExeHdrOffset = DosHdr->e_lfanew;
@ -863,7 +863,6 @@ PeCoffInitializeContext (
// Verify the file buffer can hold a PE Common Header. // Verify the file buffer can hold a PE Common Header.
// //
if (FileSize - Context->ExeHdrOffset < sizeof (EFI_IMAGE_NT_HEADERS_COMMON_HDR) + sizeof (UINT16)) { if (FileSize - Context->ExeHdrOffset < sizeof (EFI_IMAGE_NT_HEADERS_COMMON_HDR) + sizeof (UINT16)) {
DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_UNSUPPORTED;
} }
// //
@ -871,7 +870,6 @@ PeCoffInitializeContext (
// //
if (!PcdGetBool (PcdImageLoaderAllowMisalignedOffset) if (!PcdGetBool (PcdImageLoaderAllowMisalignedOffset)
&& !IS_ALIGNED (Context->ExeHdrOffset, ALIGNOF (EFI_IMAGE_NT_HEADERS_COMMON_HDR))) { && !IS_ALIGNED (Context->ExeHdrOffset, ALIGNOF (EFI_IMAGE_NT_HEADERS_COMMON_HDR))) {
DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_UNSUPPORTED;
} }
@ -883,7 +881,6 @@ PeCoffInitializeContext (
// Verify the Image Executable Header has a PE signature. // Verify the Image Executable Header has a PE signature.
// //
if (*(CONST UINT32 *) (CONST VOID *) ((CONST CHAR8 *) FileBuffer + Context->ExeHdrOffset) != EFI_IMAGE_NT_SIGNATURE) { if (*(CONST UINT32 *) (CONST VOID *) ((CONST CHAR8 *) FileBuffer + Context->ExeHdrOffset) != EFI_IMAGE_NT_SIGNATURE) {
DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_UNSUPPORTED;
} }
// //
@ -891,7 +888,6 @@ PeCoffInitializeContext (
// //
Status = InternalInitializePe (Context, FileSize); Status = InternalInitializePe (Context, FileSize);
if (Status != RETURN_SUCCESS) { if (Status != RETURN_SUCCESS) {
DEBUG_RAISE ();
return Status; return Status;
} }

View File

@ -160,7 +160,7 @@ PeCoffLoadImageInplaceNoBase (
if (Sections[SectionIndex].PointerToRawData != Sections[SectionIndex].VirtualAddress if (Sections[SectionIndex].PointerToRawData != Sections[SectionIndex].VirtualAddress
|| Sections[SectionIndex].SizeOfRawData != AlignedSize) { || Sections[SectionIndex].SizeOfRawData != AlignedSize) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
} }

View File

@ -269,7 +269,7 @@ InternalApplyRelocation (
); );
if (Overflow) { if (Overflow) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
Overflow = BaseOverflowSubU32 ( Overflow = BaseOverflowSubU32 (
@ -279,7 +279,7 @@ InternalApplyRelocation (
); );
if (Overflow) { if (Overflow) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
Fixup = (CHAR8 *) Context->ImageBuffer + RelocTargetRva; Fixup = (CHAR8 *) Context->ImageBuffer + RelocTargetRva;
@ -303,7 +303,7 @@ InternalApplyRelocation (
// //
if (sizeof (UINT32) > RemRelocTargetSize) { if (sizeof (UINT32) > RemRelocTargetSize) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Image Base Relocation does not target the Image Relocation // Verify the Image Base Relocation does not target the Image Relocation
@ -312,7 +312,7 @@ InternalApplyRelocation (
if (RelocTargetRva + sizeof (UINT32) > Context->RelocDirRva if (RelocTargetRva + sizeof (UINT32) > Context->RelocDirRva
&& Context->RelocDirRva + Context->RelocDirSize > RelocTargetRva) { && Context->RelocDirRva + Context->RelocDirSize > RelocTargetRva) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Relocate the target instruction. // Relocate the target instruction.
@ -336,7 +336,7 @@ InternalApplyRelocation (
// //
if (sizeof (UINT64) > RemRelocTargetSize) { if (sizeof (UINT64) > RemRelocTargetSize) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Image Base Relocation does not target the Image Relocation // Verify the Image Base Relocation does not target the Image Relocation
@ -345,7 +345,7 @@ InternalApplyRelocation (
if (RelocTargetRva + sizeof (UINT64) > Context->RelocDirRva if (RelocTargetRva + sizeof (UINT64) > Context->RelocDirRva
&& Context->RelocDirRva + Context->RelocDirSize > RelocTargetRva) { && Context->RelocDirRva + Context->RelocDirSize > RelocTargetRva) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Relocate target the instruction. // Relocate target the instruction.
@ -368,14 +368,14 @@ InternalApplyRelocation (
// //
if ((PcdGet32 (PcdImageLoaderRelocTypePolicy) & PCD_RELOC_TYPE_POLICY_ARM) == 0) { if ((PcdGet32 (PcdImageLoaderRelocTypePolicy) & PCD_RELOC_TYPE_POLICY_ARM) == 0) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Base Relocation target is in bounds of the Image buffer. // Verify the Base Relocation target is in bounds of the Image buffer.
// //
if (sizeof (UINT64) > RemRelocTargetSize) { if (sizeof (UINT64) > RemRelocTargetSize) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Base Relocation target is sufficiently aligned. // Verify the Base Relocation target is sufficiently aligned.
@ -383,7 +383,7 @@ InternalApplyRelocation (
// //
if (!IS_ALIGNED (RelocTargetRva, ALIGNOF (UINT32))) { if (!IS_ALIGNED (RelocTargetRva, ALIGNOF (UINT32))) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Base Relocation does not target the Relocation Directory. // Verify the Base Relocation does not target the Relocation Directory.
@ -391,7 +391,7 @@ InternalApplyRelocation (
if (RelocTargetRva + sizeof (UINT64) > Context->RelocDirRva if (RelocTargetRva + sizeof (UINT64) > Context->RelocDirRva
&& Context->RelocDirRva + Context->RelocDirSize > RelocTargetRva) { && Context->RelocDirRva + Context->RelocDirSize > RelocTargetRva) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Relocate the target instruction. // Relocate the target instruction.
@ -493,7 +493,7 @@ PeCoffRelocateImage (
); );
if (Overflow) { if (Overflow) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
} }
// //
@ -513,7 +513,7 @@ PeCoffRelocateImage (
); );
if (Overflow) { if (Overflow) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Verify the Base Relocation Block is in bounds of the Relocation // Verify the Base Relocation Block is in bounds of the Relocation
@ -521,7 +521,7 @@ PeCoffRelocateImage (
// //
if (SizeOfRelocs > RelocBlockOffsetMax - RelocBlockOffset) { if (SizeOfRelocs > RelocBlockOffsetMax - RelocBlockOffset) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Advance to the next Base Relocation Block offset based on the alignment // 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))) { if (!IS_ALIGNED (RelocBlockSize, ALIGNOF (EFI_IMAGE_BASE_RELOCATION_BLOCK))) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
} else { } else {
// //
@ -603,7 +603,7 @@ PeCoffRelocateImage (
// //
if (RelocBlockOffset != TopOfRelocDir) { if (RelocBlockOffset != TopOfRelocDir) {
DEBUG_RAISE (); DEBUG_RAISE ();
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
// //
// Initialise the remaining uninitialised portion of the Image runtime // Initialise the remaining uninitialised portion of the Image runtime
@ -674,7 +674,7 @@ InternalApplyRelocationRuntime (
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
Fixup32 += (UINT32) Adjust; Fixup32 += (UINT32) Adjust;
@ -692,7 +692,7 @@ InternalApplyRelocationRuntime (
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
Fixup64 += Adjust; Fixup64 += Adjust;
@ -712,7 +712,7 @@ InternalApplyRelocationRuntime (
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
return RETURN_UNSUPPORTED; return RETURN_VOLUME_CORRUPTED;
} }
ThumbMovwMovtImmediateFixup (Fixup, Adjust); ThumbMovwMovtImmediateFixup (Fixup, Adjust);