Core/Dxe: Added sanity checks.

This commit is contained in:
Mikhail Krichanov 2025-01-27 19:27:01 +03:00
parent 2cd1b35113
commit 31fef0a12e
6 changed files with 32 additions and 30 deletions

View File

@ -1701,6 +1701,7 @@ CoreStartImage (
if (gRing3Data == NULL) {
Image->Status = InitializeRing3 (ImageHandle, Image);
if (EFI_ERROR (Image->Status)) {
DEBUG ((DEBUG_ERROR, "Core: Failed to initialize User address space - %r.\n", Image->Status));
CpuDeadLoop ();
}
} else {

View File

@ -66,7 +66,7 @@ SysCallBootService (
return Status;
}
VOID
EFI_STATUS
EFIAPI
MakeUserPageTableTemplate (
OUT UINTN *UserPageTableTemplate,
@ -77,9 +77,8 @@ MakeUserPageTableTemplate (
VOID *MemorySizeHob;
MemorySizeHob = GetFirstGuidHob (&gArmVirtSystemMemorySizeGuid);
ASSERT (MemorySizeHob != NULL);
if (MemorySizeHob == NULL) {
return;
return EFI_NOT_FOUND;
}
Descriptor.PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
@ -87,11 +86,11 @@ MakeUserPageTableTemplate (
Descriptor.Length = *(UINT64 *)GET_GUID_HOB_DATA (MemorySizeHob);
Descriptor.Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
ArmMakeUserPageTableTemplate (
&Descriptor,
UserPageTableTemplate,
UserPageTableTemplateSize
);
return ArmMakeUserPageTableTemplate (
&Descriptor,
UserPageTableTemplate,
UserPageTableTemplateSize
);
}
EFI_STATUS
@ -118,7 +117,6 @@ InitializePlatform (
&Physical
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Core: Failed to allocate memory for Ring3 ConfigurationTable.\n"));
return Status;
}

View File

@ -93,7 +93,7 @@ SysCallBootService (
return Status;
}
VOID
EFI_STATUS
EFIAPI
MakeUserPageTableTemplate (
OUT UINTN *UserPageTableTemplate,
@ -104,9 +104,8 @@ MakeUserPageTableTemplate (
VOID *MemorySizeHob;
MemorySizeHob = GetFirstGuidHob (&gArmVirtSystemMemorySizeGuid);
ASSERT (MemorySizeHob != NULL);
if (MemorySizeHob == NULL) {
return;
return EFI_NOT_FOUND;
}
Descriptor.PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
@ -114,11 +113,11 @@ MakeUserPageTableTemplate (
Descriptor.Length = *(UINT64 *)GET_GUID_HOB_DATA (MemorySizeHob);
Descriptor.Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
ArmMakeUserPageTableTemplate (
&Descriptor,
UserPageTableTemplate,
UserPageTableTemplateSize
);
return ArmMakeUserPageTableTemplate (
&Descriptor,
UserPageTableTemplate,
UserPageTableTemplateSize
);
}
EFI_STATUS
@ -143,7 +142,6 @@ InitializePlatform (
&Physical
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Core: Failed to allocate memory for Ring3 ConfigurationTable.\n"));
return Status;
}

View File

@ -12,7 +12,7 @@
extern EXCEPTION_ADDRESSES *mExceptionAddresses;
VOID
EFI_STATUS
EFIAPI
MakeUserPageTableTemplate (
OUT UINTN *UserPageTableTemplate,
@ -45,7 +45,9 @@ MakeUserPageTableTemplate (
TotalPagesNum = NumberOfPdpEntriesNeeded + 1;
PageAddress = (UINTN)AllocatePages (TotalPagesNum);
ASSERT (PageAddress != 0);
if (PageAddress == 0) {
return EFI_OUT_OF_RESOURCES;
}
PageMap = (VOID *)PageAddress;
PageAddress += SIZE_4KB;
@ -87,6 +89,8 @@ MakeUserPageTableTemplate (
*UserPageTableTemplate = (UINTN)PageMap;
*UserPageTableTemplateSize = EFI_PAGES_TO_SIZE (TotalPagesNum);
return EFI_SUCCESS;
}
EFI_STATUS

View File

@ -19,7 +19,7 @@ STATIC UEFI_IMAGE_RECORD *mDxeRing3;
STATIC EFI_PHYSICAL_ADDRESS mCoreStackBase;
STATIC UINT64 mCoreStackSize;
VOID
EFI_STATUS
EFIAPI
MakeUserPageTableTemplate (
OUT UINTN *UserPageTableTemplate,
@ -60,7 +60,6 @@ InitializeRing3 (
&Physical
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Core: Failed to allocate memory for Ring3Data.\n"));
return Status;
}
@ -98,7 +97,6 @@ InitializeRing3 (
&Physical
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Core: Failed to allocate memory for Ring3Interfaces.\n"));
CoreFreePages (
(EFI_PHYSICAL_ADDRESS)(UINTN)gRing3Data,
EFI_SIZE_TO_PAGES (sizeof (RING3_DATA))
@ -150,6 +148,7 @@ InitializeUserPageTable (
IN LOADED_IMAGE_PRIVATE_DATA *Image
)
{
EFI_STATUS Status;
UINTN UserPageTable;
UINTN UserPageTableSize;
UEFI_IMAGE_RECORD_SEGMENT *ImageRecordSegment;
@ -157,10 +156,11 @@ InitializeUserPageTable (
UINT32 Index;
UEFI_IMAGE_RECORD *UserImageRecord;
//
// TODO: Remove ASSERTs, add proper checks and return status.
//
MakeUserPageTableTemplate (&UserPageTable, &UserPageTableSize);
Status = MakeUserPageTableTemplate (&UserPageTable, &UserPageTableSize);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Core: Failed to initialize User page table - %r.\n", Status));
CpuDeadLoop ();
}
//
// Map gRing3Data, gRing3Interfaces, DxeRing3

View File

@ -13,7 +13,7 @@
extern EXCEPTION_ADDRESSES *mExceptionAddresses;
VOID
EFI_STATUS
EFIAPI
MakeUserPageTableTemplate (
OUT UINTN *UserPageTableTemplate,
@ -159,8 +159,7 @@ MakeUserPageTableTemplate (
BigPageAddress = (UINTN)AllocatePages (TotalPagesNum);
if (BigPageAddress == 0) {
DEBUG ((DEBUG_ERROR, "Core: Could not allocate buffer for User page table.\n"));
CpuDeadLoop ();
return EFI_OUT_OF_RESOURCES;
}
//
@ -284,6 +283,8 @@ MakeUserPageTableTemplate (
*UserPageTableTemplate = (UINTN)PageMap;
*UserPageTableTemplateSize = EFI_PAGES_TO_SIZE (TotalPagesNum);
return EFI_SUCCESS;
}
EFI_STATUS