cmdline-cookie.patch (2441B)
1 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig 2 index 393eb2133243..f61bfbaa4001 100644 3 --- a/arch/mips/Kconfig 4 +++ b/arch/mips/Kconfig 5 @@ -3157,6 +3157,24 @@ choice 6 if you don't intend to always append a DTB. 7 endchoice 8 9 +config MIPS_BOOTLOADER_CMDLINE_REQUIRE_COOKIE 10 + bool "Ignore bootloader command-line unless cookie present" 11 + default n 12 + 13 +config MIPS_BOOTLOADER_CMDLINE_COOKIE 14 + string "Bootloader kernel argument cookie string" 15 + depends on MIPS_BOOTLOADER_CMDLINE_REQUIRE_COOKIE 16 + help 17 + Use bootloader command line if and only if it contains 18 + this string. Some bootloaders allow setting the command line 19 + for interactive boots but provide an incorrect (and 20 + unchangeable) default when booting unattended. 21 + 22 + This option can be combined with e.g. MIPS_CMDLINE_DTB_EXTEND 23 + or MIPS_CMDLINE_BUILTIN_EXTEND: it doesn't affect 24 + where else your command line comes from, just whether 25 + the bootloader-provided command line is used as part of it. 26 + 27 choice 28 prompt "Kernel command line type" if !CMDLINE_OVERRIDE 29 default MIPS_CMDLINE_FROM_DTB if USE_OF && !ATH79 && !MACH_INGENIC && \ 30 diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c 31 index ef73ba1e0ec1..52a836c43630 100644 32 --- a/arch/mips/kernel/setup.c 33 +++ b/arch/mips/kernel/setup.c 34 @@ -72,6 +72,12 @@ static const char builtin_cmdline[] __initconst = CONFIG_CMDLINE; 35 static const char builtin_cmdline[] __initconst = ""; 36 #endif 37 38 +#ifdef CONFIG_MIPS_BOOTLOADER_CMDLINE_REQUIRE_COOKIE 39 +static const char cmdline_cookie[] __initconst = CONFIG_MIPS_BOOTLOADER_CMDLINE_COOKIE; 40 +#else 41 +static const char cmdline_cookie[] __initconst = NULL; 42 +#endif 43 + 44 /* 45 * mips_io_port_base is the begin of the address space to which x86 style 46 * I/O ports are mapped. 47 @@ -558,6 +564,16 @@ static void __init bootcmdline_init(void) 48 return; 49 } 50 51 + /* If CMDLINE_REQUIRE_COOKIE is set to a string, we require that 52 + * string to be present in the bootloader command line, otherwise 53 + * we ignore it. This is to accommodate bootloaders that allow 54 + * the command line to be specified for interactive boots but 55 + * hardcode an incorrect command line for unattended boots */ 56 +#ifdef CONFIG_MIPS_BOOTLOADER_CMDLINE_REQUIRE_COOKIE 57 + if(strstr(arcs_cmdline, cmdline_cookie) == NULL) { 58 + arcs_cmdline[0] = '\0'; 59 + } 60 +#endif 61 /* 62 * If the user specified a built-in command line & 63 * MIPS_CMDLINE_BUILTIN_EXTEND, then the built-in command line is