efi/libstub/x86: Permit cmdline data to be allocated above 4 GB
authorArd Biesheuvel <ardb@kernel.org>
Mon, 10 Feb 2020 16:02:40 +0000 (17:02 +0100)
committerArd Biesheuvel <ardb@kernel.org>
Sun, 23 Feb 2020 20:57:15 +0000 (21:57 +0100)
We now support cmdline data that is located in memory that is not
32-bit addressable, so relax the allocation limit on systems where
this feature is enabled.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
arch/x86/include/asm/efi.h
drivers/firmware/efi/libstub/arm-stub.c
drivers/firmware/efi/libstub/efi-stub-helper.c
drivers/firmware/efi/libstub/efistub.h
drivers/firmware/efi/libstub/x86-stub.c

index 86169a24b0d8baa66a05e0466344aa727efac270..85f79accd3f8f9b0af958c567bd991e2cbfa8239 100644 (file)
@@ -34,8 +34,6 @@ static inline bool efi_have_uv1_memmap(void)
 #define EFI32_LOADER_SIGNATURE "EL32"
 #define EFI64_LOADER_SIGNATURE "EL64"
 
-#define MAX_CMDLINE_ADDRESS    UINT_MAX
-
 #define ARCH_EFI_IRQ_FLAGS_MASK        X86_EFLAGS_IF
 
 /*
index e5c56306c64107b4e02db311ec7e8da4e813f4ef..39ce4c459ea7b3154916ec9935cddf3466bb7344 100644 (file)
@@ -169,7 +169,7 @@ efi_status_t efi_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg)
         * protocol. We are going to copy the command line into the
         * device tree, so this can be allocated anywhere.
         */
-       cmdline_ptr = efi_convert_cmdline(image, &cmdline_size);
+       cmdline_ptr = efi_convert_cmdline(image, &cmdline_size, ULONG_MAX);
        if (!cmdline_ptr) {
                pr_efi_err("getting command line via LOADED_IMAGE_PROTOCOL\n");
                status = EFI_OUT_OF_RESOURCES;
index 6db91655c743f060055d84d5f6579c0051eda3ff..92ccd0a51ae69a879e80aebc8594ebadaa2e2583 100644 (file)
@@ -497,17 +497,13 @@ static u8 *efi_utf16_to_utf8(u8 *dst, const u16 *src, int n)
        return dst;
 }
 
-#ifndef MAX_CMDLINE_ADDRESS
-#define MAX_CMDLINE_ADDRESS    ULONG_MAX
-#endif
-
 /*
  * Convert the unicode UEFI command line to ASCII to pass to kernel.
  * Size of memory allocated return in *cmd_line_len.
  * Returns NULL on error.
  */
 char *efi_convert_cmdline(efi_loaded_image_t *image,
-                         int *cmd_line_len)
+                         int *cmd_line_len, unsigned long max_addr)
 {
        const u16 *s2;
        u8 *s1 = NULL;
@@ -535,8 +531,7 @@ char *efi_convert_cmdline(efi_loaded_image_t *image,
 
        options_bytes++;        /* NUL termination */
 
-       status = efi_allocate_pages(options_bytes, &cmdline_addr,
-                               MAX_CMDLINE_ADDRESS);
+       status = efi_allocate_pages(options_bytes, &cmdline_addr, max_addr);
        if (status != EFI_SUCCESS)
                return NULL;
 
index 8bb46c1fd2cde2479759bab79e9113c87bfdfc78..b94c63d17a4f2dce57f6ed0124ed68e647961687 100644 (file)
@@ -578,7 +578,8 @@ void efi_printk(char *str);
 
 void efi_free(unsigned long size, unsigned long addr);
 
-char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len);
+char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len,
+                         unsigned long max_addr);
 
 efi_status_t efi_get_memory_map(struct efi_boot_memmap *map);
 
index 9d60352baa0fa26d287fd639a8ce84bf6f276a3b..f2dbf119837caea4acfb8bef1fa832967753034a 100644 (file)
@@ -405,7 +405,8 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
        hdr->type_of_loader = 0x21;
 
        /* Convert unicode cmdline to ascii */
-       cmdline_ptr = efi_convert_cmdline(image, &options_size);
+       cmdline_ptr = efi_convert_cmdline(image, &options_size,
+                                         above4g ? ULONG_MAX : UINT_MAX);
        if (!cmdline_ptr)
                goto fail;
 
@@ -445,7 +446,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
        /* not reached */
 
 fail2:
-       efi_free(options_size, hdr->cmd_line_ptr);
+       efi_free(options_size, (unsigned long)cmdline_ptr);
 fail:
        efi_free(0x4000, (unsigned long)boot_params);