]> git.ipfire.org Git - people/arne_f/kernel.git/commitdiff
efi/libstub: Unify command line param parsing
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 4 Apr 2017 16:09:08 +0000 (17:09 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 Jun 2019 10:22:45 +0000 (12:22 +0200)
commit 60f38de7a8d4e816100ceafd1b382df52527bd50 upstream.

Merge the parsing of the command line carried out in arm-stub.c with
the handling in efi_parse_options(). Note that this also fixes the
missing handling of CONFIG_CMDLINE_FORCE=y, in which case the builtin
command line should supersede the one passed by the firmware.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: bhe@redhat.com
Cc: bhsharma@redhat.com
Cc: bp@alien8.de
Cc: eugene@hp.com
Cc: evgeny.kalugin@intel.com
Cc: jhugo@codeaurora.org
Cc: leif.lindholm@linaro.org
Cc: linux-efi@vger.kernel.org
Cc: mark.rutland@arm.com
Cc: roy.franz@cavium.com
Cc: rruigrok@codeaurora.org
Link: http://lkml.kernel.org/r/20170404160910.28115-1-ard.biesheuvel@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
[ardb: fix up merge conflicts with 4.9.180]
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/firmware/efi/libstub/arm-stub.c
drivers/firmware/efi/libstub/arm64-stub.c
drivers/firmware/efi/libstub/efi-stub-helper.c
drivers/firmware/efi/libstub/efistub.h
include/linux/efi.h

index 993aa56755f60afb929f90521485fd5fab335583..726d1467b77821f108a65e304b4f7fff0ba330ba 100644 (file)
@@ -18,7 +18,6 @@
 
 #include "efistub.h"
 
-bool __nokaslr;
 
 static int efi_get_secureboot(efi_system_table_t *sys_table_arg)
 {
@@ -268,18 +267,6 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
                goto fail;
        }
 
-       /* check whether 'nokaslr' was passed on the command line */
-       if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
-               static const u8 default_cmdline[] = CONFIG_CMDLINE;
-               const u8 *str, *cmdline = cmdline_ptr;
-
-               if (IS_ENABLED(CONFIG_CMDLINE_FORCE))
-                       cmdline = default_cmdline;
-               str = strstr(cmdline, "nokaslr");
-               if (str == cmdline || (str > cmdline && *(str - 1) == ' '))
-                       __nokaslr = true;
-       }
-
        si = setup_graphics(sys_table);
 
        status = handle_kernel_image(sys_table, image_addr, &image_size,
@@ -291,9 +278,13 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
                goto fail_free_cmdline;
        }
 
-       status = efi_parse_options(cmdline_ptr);
-       if (status != EFI_SUCCESS)
-               pr_efi_err(sys_table, "Failed to parse EFI cmdline options\n");
+       if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
+           IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
+           cmdline_size == 0)
+               efi_parse_options(CONFIG_CMDLINE);
+
+       if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && cmdline_size > 0)
+               efi_parse_options(cmdline_ptr);
 
        secure_boot = efi_get_secureboot(sys_table);
        if (secure_boot > 0)
index 959d9b8d48454885f2e43c83742f648c13669378..f7a6970e9abc18fed20dfaa089d9c117d1fef893 100644 (file)
@@ -24,8 +24,6 @@
 
 #include "efistub.h"
 
-extern bool __nokaslr;
-
 efi_status_t check_platform_features(efi_system_table_t *sys_table_arg)
 {
        u64 tg;
@@ -60,7 +58,7 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
        u64 phys_seed = 0;
 
        if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
-               if (!__nokaslr) {
+               if (!nokaslr()) {
                        status = efi_get_random_bytes(sys_table_arg,
                                                      sizeof(phys_seed),
                                                      (u8 *)&phys_seed);
index 09d10dcf1fc68038a94666b9ab05a528edfa9366..1c963c4d1bde8aaf5dde2b0a63ef4408f63610fb 100644 (file)
 
 static unsigned long __chunk_size = EFI_READ_CHUNK_SIZE;
 
+static int __section(.data) __nokaslr;
+
+int __pure nokaslr(void)
+{
+       return __nokaslr;
+}
+
 /*
  * Allow the platform to override the allocation granularity: this allows
  * systems that have the capability to run with a larger page size to deal
@@ -351,17 +358,13 @@ void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
  * environments, first in the early boot environment of the EFI boot
  * stub, and subsequently during the kernel boot.
  */
-efi_status_t efi_parse_options(char *cmdline)
+efi_status_t efi_parse_options(char const *cmdline)
 {
        char *str;
 
-       /*
-        * Currently, the only efi= option we look for is 'nochunk', which
-        * is intended to work around known issues on certain x86 UEFI
-        * versions. So ignore for now on other architectures.
-        */
-       if (!IS_ENABLED(CONFIG_X86))
-               return EFI_SUCCESS;
+       str = strstr(cmdline, "nokaslr");
+       if (str == cmdline || (str && str > cmdline && *(str - 1) == ' '))
+               __nokaslr = 1;
 
        /*
         * If no EFI parameters were specified on the cmdline we've got
index fac67992bede5867ff9093f76df69583b1400492..d0e5acab547f5423b52e6e8aae950de68cafa898 100644 (file)
@@ -15,6 +15,8 @@
  */
 #undef __init
 
+extern int __pure nokaslr(void);
+
 void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
 
 efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, void *__image,
index e6711bf9f0d123f7dfaabd074092555b223798b1..02c4f16685b69c01035c6e303475245b71968b49 100644 (file)
@@ -1427,7 +1427,7 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
                                  unsigned long *load_addr,
                                  unsigned long *load_size);
 
-efi_status_t efi_parse_options(char *cmdline);
+efi_status_t efi_parse_options(char const *cmdline);
 
 efi_status_t efi_setup_gop(efi_system_table_t *sys_table_arg,
                           struct screen_info *si, efi_guid_t *proto,