Browse Source

efi_loader: check memory type in AllocatePages()

The UEFI specification prescribes that AllocatePages() checks the memory
type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Heinrich Schuchardt 5 years ago
parent
commit
f12bcc9149
2 changed files with 8 additions and 0 deletions
  1. 4 0
      include/efi.h
  2. 4 0
      lib/efi_loader/efi_memory.c

+ 4 - 0
include/efi.h

@@ -168,6 +168,10 @@ enum efi_mem_type {
 	 * part of the processor.
 	 */
 	EFI_PAL_CODE,
+	/*
+	 * Non-volatile memory.
+	 */
+	EFI_PERSISTENT_MEMORY_TYPE,
 
 	EFI_MAX_MEMORY_TYPE,
 	EFI_TABLE_END,	/* For efi_build_mem_table() */

+ 4 - 0
lib/efi_loader/efi_memory.c

@@ -376,6 +376,10 @@ efi_status_t efi_allocate_pages(int type, int memory_type,
 	efi_status_t r = EFI_SUCCESS;
 	uint64_t addr;
 
+	/* Check import parameters */
+	if (memory_type >= EFI_PERSISTENT_MEMORY_TYPE &&
+	    memory_type <= 0x6FFFFFFF)
+		return EFI_INVALID_PARAMETER;
 	if (!memory)
 		return EFI_INVALID_PARAMETER;