efi_loader: AllocateAddress requires page address
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sun, 6 Nov 2022 00:52:13 +0000 (01:52 +0100)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sun, 6 Nov 2022 09:50:04 +0000 (10:50 +0100)
AllocatePages() can be called with Type=AllocateAddress. Such a call can
only succeed if *Memory points to the address of an unallocated page range.

A call with *Memory being an address that is not page aligned must not
succeed. The UEFI specification requires returning EFI_OUT_OF_RESOURCES
if the requested pages cannot be allocated.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
lib/efi_loader/efi_memory.c

index e048a54..a17b426 100644 (file)
@@ -483,6 +483,8 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type,
                        return EFI_OUT_OF_RESOURCES;
                break;
        case EFI_ALLOCATE_ADDRESS:
+               if (*memory & EFI_PAGE_MASK)
+                       return EFI_NOT_FOUND;
                /* Exact address, reserve it. The addr is already in *memory. */
                ret = efi_check_allocated(*memory, false);
                if (ret != EFI_SUCCESS)