bootconfig: Use parse_args() to find bootconfig and '--'

The current implementation does a naive search of "bootconfig" on the kernel
command line. But this could find "bootconfig" that is part of another
option in quotes (although highly unlikely). But it also needs to find '--'
on the kernel command line to know if it should append a '--' or not when a
bootconfig in the initrd file has an "init" section. The check uses the
naive strstr() to find to see if it exists. But this can return a false
positive if it exists in an option and then the "init" section in the initrd
will not be appended properly.

Using parse_args() to find both of these will solve both of these problems.

Link: https://lore.kernel.org/r/202002070954.C18E7F58B@keescook

Fixes: 7495e092 ("bootconfig: Only load bootconfig if "bootconfig" is on the kernel cmdline")
Fixes: 13199162 ("bootconfig: init: Allow admin to use bootconfig for init command line")
Reported-by: default avatarKees Cook <keescook@chromium.org>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 10f129cb
...@@ -142,6 +142,15 @@ static char *extra_command_line; ...@@ -142,6 +142,15 @@ static char *extra_command_line;
/* Extra init arguments */ /* Extra init arguments */
static char *extra_init_args; static char *extra_init_args;
#ifdef CONFIG_BOOT_CONFIG
/* Is bootconfig on command line? */
static bool bootconfig_found;
static bool initargs_found;
#else
# define bootconfig_found false
# define initargs_found false
#endif
static char *execute_command; static char *execute_command;
static char *ramdisk_execute_command; static char *ramdisk_execute_command;
...@@ -336,17 +345,30 @@ u32 boot_config_checksum(unsigned char *p, u32 size) ...@@ -336,17 +345,30 @@ u32 boot_config_checksum(unsigned char *p, u32 size)
return ret; return ret;
} }
static int __init bootconfig_params(char *param, char *val,
const char *unused, void *arg)
{
if (strcmp(param, "bootconfig") == 0) {
bootconfig_found = true;
} else if (strcmp(param, "--") == 0) {
initargs_found = true;
}
return 0;
}
static void __init setup_boot_config(const char *cmdline) static void __init setup_boot_config(const char *cmdline)
{ {
static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata;
u32 size, csum; u32 size, csum;
char *data, *copy; char *data, *copy;
const char *p;
u32 *hdr; u32 *hdr;
int ret; int ret;
p = strstr(cmdline, "bootconfig"); strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
if (!p || (p != cmdline && !isspace(*(p-1))) || parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL,
(p[10] && !isspace(p[10]))) bootconfig_params);
if (!bootconfig_found)
return; return;
if (!initrd_end) if (!initrd_end)
...@@ -563,11 +585,12 @@ static void __init setup_command_line(char *command_line) ...@@ -563,11 +585,12 @@ static void __init setup_command_line(char *command_line)
* to init. * to init.
*/ */
len = strlen(saved_command_line); len = strlen(saved_command_line);
if (!strstr(boot_command_line, " -- ")) { if (initargs_found) {
saved_command_line[len++] = ' ';
} else {
strcpy(saved_command_line + len, " -- "); strcpy(saved_command_line + len, " -- ");
len += 4; len += 4;
} else }
saved_command_line[len++] = ' ';
strcpy(saved_command_line + len, extra_init_args); strcpy(saved_command_line + len, extra_init_args);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment