Skip to content

Commit a99cd11

Browse files
init: fix bug where environment vars can't be passed via boot args
Commit 026cee0 had the side-effect of dropping the '=' from the unknown boot arguments that are passed to init as environment variables. This is because parse_args() puts a NUL in the string where the '=' was when it passes the "param" and "val" pointers to the parsing subfunctions. Previously, unknown_bootoption() was the last parse_args() subfunction to run, and it carefully put back the '=' character. Now the ignore_unknown_bootoption() is the last one to run, and it wasn't doing the necessary repair, so the envp params ended up with the embedded NUL and were no longer seen as valid environment variables by init. Tested-by: Woody Suwalski <[email protected]> Acked-by: Pawel Moll <[email protected]> Signed-off-by: Chris Metcalf <[email protected]>
1 parent 66f75a5 commit a99cd11

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

init/main.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,9 @@ static int __init loglevel(char *str)
225225

226226
early_param("loglevel", loglevel);
227227

228-
/*
229-
* Unknown boot options get handed to init, unless they look like
230-
* unused parameters (modprobe will find them in /proc/cmdline).
231-
*/
232-
static int __init unknown_bootoption(char *param, char *val)
228+
/* Change NUL term back to "=", to make "param" the whole string. */
229+
static int __init repair_env_string(char *param, char *val)
233230
{
234-
/* Change NUL term back to "=", to make "param" the whole string. */
235231
if (val) {
236232
/* param=val or param="val"? */
237233
if (val == param+strlen(param)+1)
@@ -243,6 +239,16 @@ static int __init unknown_bootoption(char *param, char *val)
243239
} else
244240
BUG();
245241
}
242+
return 0;
243+
}
244+
245+
/*
246+
* Unknown boot options get handed to init, unless they look like
247+
* unused parameters (modprobe will find them in /proc/cmdline).
248+
*/
249+
static int __init unknown_bootoption(char *param, char *val)
250+
{
251+
repair_env_string(param, val);
246252

247253
/* Handle obsolete-style parameters */
248254
if (obsolete_checksetup(param))
@@ -732,11 +738,6 @@ static char *initcall_level_names[] __initdata = {
732738
"late parameters",
733739
};
734740

735-
static int __init ignore_unknown_bootoption(char *param, char *val)
736-
{
737-
return 0;
738-
}
739-
740741
static void __init do_initcall_level(int level)
741742
{
742743
extern const struct kernel_param __start___param[], __stop___param[];
@@ -747,7 +748,7 @@ static void __init do_initcall_level(int level)
747748
static_command_line, __start___param,
748749
__stop___param - __start___param,
749750
level, level,
750-
ignore_unknown_bootoption);
751+
repair_env_string);
751752

752753
for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
753754
do_one_initcall(*fn);

0 commit comments

Comments
 (0)