]> xenbits.xensource.com Git - people/aperard/linux.git/commitdiff
efi/libstub: Add limit argument to efi_random_alloc()
authorArd Biesheuvel <ardb+git@google.com>
Mon, 4 Mar 2024 11:19:46 +0000 (12:19 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 6 Mar 2024 14:45:18 +0000 (14:45 +0000)
From: Ard Biesheuvel <ardb@kernel.org>

[ Commit bc5ddceff4c14494d83449ad45c985e6cd353fce upstream ]

x86 will need to limit the kernel memory allocation to the lowest 512
MiB of memory, to match the behavior of the existing bare metal KASLR
physical randomization logic. So in preparation for that, add a limit
parameter to efi_random_alloc() and wire it up.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/20230807162720.545787-22-ardb@kernel.org
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/firmware/efi/libstub/arm64-stub.c
drivers/firmware/efi/libstub/efistub.h
drivers/firmware/efi/libstub/randomalloc.c

index 40275c3131c8e3ef1778acb6e5cd5603b425eb72..16377b4521190434f5dba4c1a5f45716120ceecc 100644 (file)
@@ -181,7 +181,7 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
                 */
                status = efi_random_alloc(*reserve_size, min_kimg_align,
                                          reserve_addr, phys_seed,
-                                         EFI_LOADER_CODE);
+                                         EFI_LOADER_CODE, EFI_ALLOC_LIMIT);
                if (status != EFI_SUCCESS)
                        efi_warn("efi_random_alloc() failed: 0x%lx\n", status);
        } else {
index 6f5a1a16db15b1ea23daace95667aa7f5658e310..8a343ea1231a262193f00dbad53d9a4b7834f8a9 100644 (file)
@@ -905,7 +905,7 @@ efi_status_t efi_get_random_bytes(unsigned long size, u8 *out);
 
 efi_status_t efi_random_alloc(unsigned long size, unsigned long align,
                              unsigned long *addr, unsigned long random_seed,
-                             int memory_type);
+                             int memory_type, unsigned long alloc_limit);
 
 efi_status_t efi_random_get_seed(void);
 
index 1692d19ae80f0065627650344aa6dbae92180928..ed6f6087a9eacebac21d1d596ceaf025519d7816 100644 (file)
@@ -16,7 +16,8 @@
  */
 static unsigned long get_entry_num_slots(efi_memory_desc_t *md,
                                         unsigned long size,
-                                        unsigned long align_shift)
+                                        unsigned long align_shift,
+                                        u64 alloc_limit)
 {
        unsigned long align = 1UL << align_shift;
        u64 first_slot, last_slot, region_end;
@@ -29,7 +30,7 @@ static unsigned long get_entry_num_slots(efi_memory_desc_t *md,
                return 0;
 
        region_end = min(md->phys_addr + md->num_pages * EFI_PAGE_SIZE - 1,
-                        (u64)EFI_ALLOC_LIMIT);
+                        alloc_limit);
        if (region_end < size)
                return 0;
 
@@ -54,7 +55,8 @@ efi_status_t efi_random_alloc(unsigned long size,
                              unsigned long align,
                              unsigned long *addr,
                              unsigned long random_seed,
-                             int memory_type)
+                             int memory_type,
+                             unsigned long alloc_limit)
 {
        unsigned long total_slots = 0, target_slot;
        unsigned long total_mirrored_slots = 0;
@@ -76,7 +78,7 @@ efi_status_t efi_random_alloc(unsigned long size,
                efi_memory_desc_t *md = (void *)map->map + map_offset;
                unsigned long slots;
 
-               slots = get_entry_num_slots(md, size, ilog2(align));
+               slots = get_entry_num_slots(md, size, ilog2(align), alloc_limit);
                MD_NUM_SLOTS(md) = slots;
                total_slots += slots;
                if (md->attribute & EFI_MEMORY_MORE_RELIABLE)