efi_loader: check memory type in AllocatePages()
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Mon, 22 Apr 2019 22:30:53 +0000 (00:30 +0200)
committerHeinrich Schuchardt <xypron.glpk@gmx.de>
Mon, 22 Apr 2019 22:37:28 +0000 (00:37 +0200)
The UEFI specification prescribes that AllocatePages() checks the memory
type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
include/efi.h
lib/efi_loader/efi_memory.c

index 3c9d20f8c0b6b518e4bb3ab20e0871729e59b280..5f415a99cc9002413ce10f821c273b35e4186c04 100644 (file)
@@ -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() */
index 46681dc2082b120edd4f4c160eac3cb25f323f54..987cc6dc5f61aaaec7fea74c8e87ecbd0c927a90 100644 (file)
@@ -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;