Skip to content

Commit

Permalink
init: allow CONFIG_INIT_FALLBACK=n to disable defaults if init= fails
Browse files Browse the repository at this point in the history
If a user puts init=/whatever on the command line and /whatever can't be
run, then the kernel will try a few default options before giving up.  If
init=/whatever came from a bootloader prompt, then this is unexpected but
probably harmless.  On the other hand, if it comes from a script (e.g.  a
tool like virtme or perhaps a future kselftest script), then the fallbacks
are likely to exist, but they'll do the wrong thing.  For example, they
might unexpectedly invoke systemd.

This adds a config option CONFIG_INIT_FALLBACK.  If unset, then a failure
to run the specified init= process be fatal.

The tentative plan is to remove CONFIG_INIT_FALLBACK for 3.20.

[[email protected]: coding-style fixes]
Signed-off-by: Andy Lutomirski <[email protected]>
Cc: Rob Landley <[email protected]>
Cc: Chuck Ebbert <[email protected]>
Cc: Randy Dunlap <[email protected]>
Cc: Shuah Khan <[email protected]>
Cc: Frank Rowand <[email protected]>
Cc: Josh Triplett <[email protected]>
Acked-by: Rusty Russell <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
amluto authored and torvalds committed Dec 11, 2014
1 parent 52f5592 commit 6ef4536
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
16 changes: 16 additions & 0 deletions init/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,22 @@ source "usr/Kconfig"

endif

config INIT_FALLBACK
bool "Fall back to defaults if init= parameter is bad"
default y
help
If enabled, the kernel will try the default init binaries if an
explicit request from the init= parameter fails.

This can have unexpected effects. For example, booting
with init=/sbin/kiosk_app will run /sbin/init or even /bin/sh
if /sbin/kiosk_app cannot be executed.

The default value of Y is consistent with historical behavior.
Selecting N is likely to be more appropriate for most uses,
especially on kiosks and on kernels that are intended to be
run under the control of a script.

config CC_OPTIMIZE_FOR_SIZE
bool "Optimize for size"
help
Expand Down
7 changes: 6 additions & 1 deletion init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,13 @@ static int __ref kernel_init(void *unused)
ret = run_init_process(execute_command);
if (!ret)
return 0;
#ifndef CONFIG_INIT_FALLBACK
panic("Requested init %s failed (error %d).",
execute_command, ret);
#else
pr_err("Failed to execute %s (error %d). Attempting defaults...\n",
execute_command, ret);
execute_command, ret);
#endif
}
if (!try_to_run_init_process("/sbin/init") ||
!try_to_run_init_process("/etc/init") ||
Expand Down

0 comments on commit 6ef4536

Please sign in to comment.