diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c index ef026ee329..b173de6048 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c @@ -1213,55 +1213,6 @@ EfiBootManagerFreeLoadOptions ( return EFI_SUCCESS; } -/** - Return whether the PE header of the load option is valid or not. - - @param[in] Type The load option type. - It's used to check whether the load option is valid. - When it's LoadOptionTypeMax, the routine only guarantees - the load option is a valid PE image but doesn't guarantee - the PE's subsystem type is valid. - @param[in] FileBuffer The PE file buffer of the load option. - @param[in] FileSize The size of the load option file. - - @retval TRUE The PE header of the load option is valid. - @retval FALSE The PE header of the load option is not valid. -**/ -BOOLEAN -BmIsLoadOptionPeHeaderValid ( - IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type, - IN VOID *FileBuffer, - IN UINTN FileSize - ) -{ - EFI_STATUS Status; - UEFI_IMAGE_LOADER_IMAGE_CONTEXT ImageContext; - UINT16 Subsystem; - - if ((FileBuffer == NULL) || (FileSize == 0)) { - return FALSE; - } - - Status = UefiImageInitializeContext (&ImageContext, FileBuffer, (UINT32) FileSize); - if (EFI_ERROR (Status)) { - return FALSE; - } - - Subsystem = UefiImageGetSubsystem (&ImageContext); - - if ((Type == LoadOptionTypeMax) || - (Type == LoadOptionTypeDriver && Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER) || - (Type == LoadOptionTypeDriver && Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) || - (Type == LoadOptionTypeSysPrep && Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) || - (Type == LoadOptionTypeBoot && Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) || - (Type == LoadOptionTypePlatformRecovery && Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) - ) { - return TRUE; - } - - return FALSE; -} - /** Return the next matched load option buffer. The routine keeps calling BmGetNextLoadOptionDevicePath() until a valid @@ -1295,7 +1246,6 @@ BmGetNextLoadOptionBuffer ( EFI_DEVICE_PATH_PROTOCOL *CurFullPath; UINTN LocalFileSize; UINT32 AuthenticationStatus; - EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath; LocalFileSize = 0; FileBuffer = NULL; @@ -1315,22 +1265,6 @@ BmGetNextLoadOptionBuffer ( } FileBuffer = GetFileBufferByFilePath (TRUE, CurFullPath, &LocalFileSize, &AuthenticationStatus); - if ((FileBuffer != NULL) && !BmIsLoadOptionPeHeaderValid (Type, FileBuffer, LocalFileSize)) { - // - // Free the RAM disk file system if the load option is invalid. - // - RamDiskDevicePath = BmGetRamDiskDevicePath (FilePath); - if (RamDiskDevicePath != NULL) { - BmDestroyRamDisk (RamDiskDevicePath); - FreePool (RamDiskDevicePath); - } - - // - // Free the invalid load option buffer. - // - FreePool (FileBuffer); - FileBuffer = NULL; - } } while (FileBuffer == NULL); if (FileBuffer == NULL) { @@ -1372,6 +1306,7 @@ EfiBootManagerProcessLoadOption ( EFI_LOADED_IMAGE_PROTOCOL *ImageInfo; VOID *FileBuffer; UINTN FileSize; + EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath; if ((UINT32)LoadOption->OptionType >= LoadOptionTypeMax) { return EFI_INVALID_PARAMETER; @@ -1438,6 +1373,15 @@ EfiBootManagerProcessLoadOption ( if (Status == EFI_SECURITY_VIOLATION) { gBS->UnloadImage (ImageHandle); } + + // + // Free the RAM disk file system if the load option is invalid. + // + RamDiskDevicePath = BmGetRamDiskDevicePath (LoadOption->FilePath); + if (RamDiskDevicePath != NULL) { + BmDestroyRamDisk (RamDiskDevicePath); + FreePool (RamDiskDevicePath); + } } else { Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&ImageInfo); ASSERT_EFI_ERROR (Status); diff --git a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h b/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h index 8ebe0241c2..4bb01664e1 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h +++ b/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h @@ -68,7 +68,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include -#include #if !defined (EFI_REMOVABLE_MEDIA_FILE_NAME) #if defined (MDE_CPU_EBC) diff --git a/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf b/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf index 302927615d..6a32f5128d 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf +++ b/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf @@ -62,7 +62,6 @@ HiiLib SortLib VariablePolicyHelperLib - UefiImageLib [Guids] ## SOMETIMES_CONSUMES ## SystemTable (The identifier of memory type information type in system table)