From: Shuah Khan <shuahkh@osg.samsung.com>
To: Andy Lutomirski <luto@amacapital.net>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org
Cc: Randy Dunlap <rdunlap@infradead.org>,
Shuah Khan <shuah.kh@samsung.com>,
Rusty Russell <rusty@rustcorp.com.au>,
Shuah Khan <shuahkh@osg.samsung.com>
Subject: Re: [PATCH v2] init: Add strictinit to disable init= fallbacks
Date: Fri, 26 Sep 2014 12:40:51 -0600 [thread overview]
Message-ID: <5425B333.4090109@osg.samsung.com> (raw)
In-Reply-To: <f93b6d019337edb73c13d80f8c2495d238922538.1411754556.git.luto@amacapital.net>
On 09/26/2014 12:04 PM, Andy Lutomirski wrote:
> 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 probably makes sense. 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 new option called strictinit. If init= and strictinit
> are both set, and the init= binary is not executable, then the
> kernel will panic immediately. If strictinit is set but init= is
> not set, then strictinit will have no effect, because the only real
> alternative would be to panic regardless of the contents of the root
> fs.
>
> Signed-off-by: Andy Lutomirski <luto@amacapital.net>
> ---
>
> Now cc-ing Rusty (who probably cares more about startup options than
> anyone else) and Shuah (who might want to use this at some point).
>
> Changes from v1:
> - Add missing "if" to the docs (Randy Dunlap)
>
> Documentation/kernel-parameters.txt | 8 ++++++++
> init/main.c | 10 ++++++++++
> 2 files changed, 18 insertions(+)
>
> diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
> index 10d51c2f10d7..3dc921714002 100644
> --- a/Documentation/kernel-parameters.txt
> +++ b/Documentation/kernel-parameters.txt
> @@ -3236,6 +3236,14 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
> stifb= [HW]
> Format: bpp:<bpp1>[:<bpp2>[:<bpp3>...]]
>
> + strictinit [KNL,BOOT]
> + Normally, if the kernel can't find the init binary
> + specified by rdinit= and/or init=, then it will
> + try several fallbacks. If strictinit is set
> + and the value specified by init= does not work,
> + then the kernel will panic instead.
> + This has no effect if init= is not specified.
> +
> sunrpc.min_resvport=
> sunrpc.max_resvport=
> [NFS,SUNRPC]
> diff --git a/init/main.c b/init/main.c
> index bb1aed928f21..4fd80dcef9d0 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -131,6 +131,7 @@ static char *initcall_command_line;
>
> static char *execute_command;
> static char *ramdisk_execute_command;
> +static bool strictinit;
>
> /*
> * Used to generate warnings if static_key manipulation functions are used
> @@ -347,6 +348,13 @@ static int __init rdinit_setup(char *str)
> }
> __setup("rdinit=", rdinit_setup);
>
> +static int __init strictinit_setup(char *str)
> +{
> + strictinit = true;
> + return 1;
> +}
> +__setup("strictinit", strictinit_setup);
> +
> #ifndef CONFIG_SMP
> static const unsigned int setup_max_cpus = NR_CPUS;
> #ifdef CONFIG_X86_LOCAL_APIC
> @@ -962,6 +970,8 @@ static int __ref kernel_init(void *unused)
> return 0;
> pr_err("Failed to execute %s (error %d). Attempting defaults...\n",
> execute_command, ret);
> + if (strictinit)
> + panic("Requested init failed and strictinit was set.");
It would make sense to not print Attempting defaults for strictinit
case. I would recommend making it an else case and changing the
strictinit message to or something along the lines:
panic("Failed to execute %s (error %d). Not attempting defaults in
strictinit mode...\n", execute_command, ret);
-- Shuah
--
Shuah Khan
Sr. Linux Kernel Developer
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978
prev parent reply other threads:[~2014-09-26 18:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-26 18:04 [PATCH v2] init: Add strictinit to disable init= fallbacks Andy Lutomirski
2014-09-26 18:40 ` Shuah Khan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5425B333.4090109@osg.samsung.com \
--to=shuahkh@osg.samsung.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=rdunlap@infradead.org \
--cc=rusty@rustcorp.com.au \
--cc=shuah.kh@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox