Skip to content

Commit f61872b

Browse files
committed
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: 7495e09 ("bootconfig: Only load bootconfig if "bootconfig" is on the kernel cmdline") Fixes: 1319916 ("bootconfig: init: Allow admin to use bootconfig for init command line") Reported-by: Kees Cook <[email protected]> Reviewed-by: Kees Cook <[email protected]> Acked-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 10f129c commit f61872b

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

init/main.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ static char *extra_command_line;
142142
/* Extra init arguments */
143143
static char *extra_init_args;
144144

145+
#ifdef CONFIG_BOOT_CONFIG
146+
/* Is bootconfig on command line? */
147+
static bool bootconfig_found;
148+
static bool initargs_found;
149+
#else
150+
# define bootconfig_found false
151+
# define initargs_found false
152+
#endif
153+
145154
static char *execute_command;
146155
static char *ramdisk_execute_command;
147156

@@ -336,17 +345,30 @@ u32 boot_config_checksum(unsigned char *p, u32 size)
336345
return ret;
337346
}
338347

348+
static int __init bootconfig_params(char *param, char *val,
349+
const char *unused, void *arg)
350+
{
351+
if (strcmp(param, "bootconfig") == 0) {
352+
bootconfig_found = true;
353+
} else if (strcmp(param, "--") == 0) {
354+
initargs_found = true;
355+
}
356+
return 0;
357+
}
358+
339359
static void __init setup_boot_config(const char *cmdline)
340360
{
361+
static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata;
341362
u32 size, csum;
342363
char *data, *copy;
343-
const char *p;
344364
u32 *hdr;
345365
int ret;
346366

347-
p = strstr(cmdline, "bootconfig");
348-
if (!p || (p != cmdline && !isspace(*(p-1))) ||
349-
(p[10] && !isspace(p[10])))
367+
strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
368+
parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL,
369+
bootconfig_params);
370+
371+
if (!bootconfig_found)
350372
return;
351373

352374
if (!initrd_end)
@@ -563,11 +585,12 @@ static void __init setup_command_line(char *command_line)
563585
* to init.
564586
*/
565587
len = strlen(saved_command_line);
566-
if (!strstr(boot_command_line, " -- ")) {
588+
if (initargs_found) {
589+
saved_command_line[len++] = ' ';
590+
} else {
567591
strcpy(saved_command_line + len, " -- ");
568592
len += 4;
569-
} else
570-
saved_command_line[len++] = ' ';
593+
}
571594

572595
strcpy(saved_command_line + len, extra_init_args);
573596
}

0 commit comments

Comments
 (0)