Patch "efi/libstub: Allocate headspace in efi_get_memory_map()" has been added to the 4.7-stable tree
Subsystems (3)
This is a note to let you know that I've just added the patch titled
efi/libstub: Allocate headspace in efi_get_memory_map()
to the 4.7-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
efi-libstub-allocate-headspace-in-efi_get_memory_map.patch
and it can be found in the queue-4.7 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
dadb57abc37499f565b23933dbf49b435c3ba8afMon Sep 17 00:00:00 2001
From: Jeffrey Hugo <[email protected]>
Date: Mon, 29 Aug 2016 14:38:51 -0600
Subject: efi/libstub: Allocate headspace in efi_get_memory_map()
From: Jeffrey Hugo <[email protected]>
commit dadb57abc37499f565b23933dbf49b435c3ba8af upstream.
efi_get_memory_map() allocates a buffer to store the memory map that it retrieves. This buffer may need to be reused by the client after ExitBootServices() is called, at which point allocations are not longer permitted. To support this usecase, provide the allocated buffer size back to the client, and allocate some additional headroom to account for any reasonable growth in the map that is likely to happen between the call to efi_get_memory_map() and the client reusing the buffer.
--- arch/x86/boot/compressed/eboot.c | 18 +++- drivers/firmware/efi/libstub/efi-stub-helper.c | 96 +++++++++++++++++-------- drivers/firmware/efi/libstub/fdt.c | 17 +++- drivers/firmware/efi/libstub/random.c | 12 ++- include/linux/efi.h | 15 ++- 5 files changed, 110 insertions(+), 48 deletions(-)
arch/x86/boot/compressed/eboot.c +12 -6
@@ -1010,7 +1010,7 @@ static efi_status_t exit_boot(struct boo void *handle, bool is64) {struct efi_info *efi = &boot_params->efi_info; -unsigned long map_sz, key, desc_size; +unsigned long map_sz, key, desc_size, buff_size;efi_memory_desc_t *mem_map;struct setup_data *e820ext;const char *signature;
@@ -1021,14 +1021,20 @@ static efi_status_t exit_boot(struct boobool called_exit = false;u8 nr_entries;int i; +struct efi_boot_memmap map; - nr_desc =0 ; - e820ext =NULL ; - e820ext_size =0 ; + nr_desc =0 ; + e820ext =NULL ; + e820ext_size =0 ; + map.map = &mem_map; + map.map_size = &map_sz; + map.desc_size = &desc_size; + map.desc_ver = &desc_version; + map.key_ptr = &key; + map.buff_size = &buff_size; get_map: - status =efi_get_memory_map (sys_table, &mem_map, &map_sz, &desc_size, - &desc_version, &key); + status =efi_get_memory_map (sys_table, &map);if (status !=EFI_SUCCESS )return status;
drivers/firmware/efi/libstub/efi-stub-helper.c +66 -30
163 lines not on this page · raw message
drivers/firmware/efi/libstub/fdt.c +12 -5
@@ -175,13 +175,21 @@ efi_status_t allocate_new_fdt_and_exit_b unsigned long fdt_addr, unsigned long fdt_size) { -unsigned long map_size, desc_size; +unsigned long map_size, desc_size, buff_size;u32 desc_ver;unsigned long mmap_key;efi_memory_desc_t *memory_map, *runtime_map;unsigned long new_fdt_size;efi_status_t status;int runtime_entry_count =0 ; +struct efi_boot_memmap map; + + map.map = &runtime_map; + map.map_size = &map_size; + map.desc_size = &desc_size; + map.desc_ver = &desc_ver; + map.key_ptr = &mmap_key; + map.buff_size = &buff_size;/* * Get a copy of the current memory map that we will use to prepare
@@ -189,8 +197,7 @@ efi_status_t allocate_new_fdt_and_exit_b* subsequent allocations adding entries, since they could not affect * the number of EFI_MEMORY_RUNTIME regions. */ - status =efi_get_memory_map (sys_table, &runtime_map, &map_size, - &desc_size, &desc_ver, &mmap_key); + status =efi_get_memory_map (sys_table, &map);if (status !=EFI_SUCCESS ) {pr_efi_err (sys_table,"Unable to retrieve UEFI memory map.\n" );return status;
@@ -199,6 +206,7 @@ efi_status_t allocate_new_fdt_and_exit_bpr_efi (sys_table,"Exiting boot services and installing virtual address map...\n" ); + map.map = &memory_map;/* * Estimate size of new FDT, and allocate memory for it. We * will allocate a bigger buffer if this ends up being too
@@ -218,8 +226,7 @@ efi_status_t allocate_new_fdt_and_exit_b* we can get the memory map key needed for * exit_boot_services(). */ - status =efi_get_memory_map (sys_table, &memory_map, &map_size, - &desc_size, &desc_ver, &mmap_key); + status =efi_get_memory_map (sys_table, &map);if (status !=EFI_SUCCESS ) goto fail_free_new_fdt;
drivers/firmware/efi/libstub/random.c +10 -2
@@ -73,12 +73,20 @@ efi_status_t efi_random_alloc(efi_system unsigned long random_seed) {unsigned long map_size, desc_size, total_slots =0 , target_slot; +unsigned long buff_size;efi_status_t status;efi_memory_desc_t *memory_map;int map_offset; +struct efi_boot_memmap map; - status =efi_get_memory_map (sys_table_arg, &memory_map, &map_size, - &desc_size,NULL ,NULL ); + map.map = &memory_map; + map.map_size = &map_size; + map.desc_size = &desc_size; + map.desc_ver =NULL ; + map.key_ptr =NULL ; + map.buff_size = &buff_size; + + status =efi_get_memory_map (sys_table_arg, &map);if (status !=EFI_SUCCESS )return status;
include/linux/efi.h +10 -5
@@ -118,6 +118,15 @@ typedef struct {u32 imagesize; } efi_capsule_header_t; +struct efi_boot_memmap { +efi_memory_desc_t **map; +unsigned long *map_size; +unsigned long *desc_size; +u32 *desc_ver; +unsigned long *key_ptr; +unsigned long *buff_size; +}; +/* * EFI capsule flags */
@@ -1430,11 +1439,7 @@ char *efi_convert_cmdline(efi_system_tab efi_loaded_image_t *image, int *cmd_line_len);efi_status_t efi_get_memory_map (efi_system_table_t *sys_table_arg, -efi_memory_desc_t **map, -unsigned long *map_size, -unsigned long *desc_size, -u32 *desc_ver, -unsigned long *key_ptr); +struct efi_boot_memmap *map); efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg, unsigned long size, unsigned long align,
Patches currently in stable-queue which might be from [email protected] are
queue-4.7/efi-libstub-allocate-headspace-in-efi_get_memory_map.patch queue-4.7/x86-efi-use-efi_exit_boot_services.patch queue-4.7/efi-libstub-introduce-exitbootservices-helper.patch queue-4.7/efi-libstub-use-efi_exit_boot_services-in-fdt.patch