From: Rusty Russell <rusty@rustcorp.com.au>
To: Linus Torvalds <torvalds@linux-foundation.org>,
Mateusz Guzik <mguzik@redhat.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
LKML <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>, Borislav Petkov <bp@alien8.de>,
Ingo Molnar <mingo@kernel.org>, Mel Gorman <mgorman@suse.de>,
Kay Sievers <kay@vrfy.org>
Subject: Re: [RFC PATCH] cmdline: Hide "debug" from /proc/cmdline
Date: Mon, 07 Apr 2014 14:24:45 +0930 [thread overview]
Message-ID: <87wqf1oi22.fsf@rustcorp.com.au> (raw)
In-Reply-To: <CA+55aFyZSr4G2a1X5+EeSgKGtZvzBfBg0D0L39g-DB9TLi+ZEw@mail.gmail.com>
Linus Torvalds <torvalds@linux-foundation.org> writes:
> On Wed, Apr 2, 2014 at 3:12 PM, Mateusz Guzik <mguzik@redhat.com> wrote:
>>
>> Well, parsing kernel cmdline by systemd is a bad idea
>
> No, we very much expose /proc/cmdline for a reason. System services
> are *supposed* to parse it, because it gives a unified way for people
> to pass in various flags. The kernel doesn't complain about flags it
> doesn't recognize, exactly because the kernel realizes that "hey,
> maybe this flag is for something else".
How's this in future?
Cheers,
Rusty.
Subject: param: hand arguments after -- straight to init
The kernel passes any args it doesn't need through to init, except it
assumes anything containing '.' belongs to the kernel (for a module).
This change means all users can clearly distinguish which arguments
are for init.
For example, the kernel uses debug ("dee-bug") to mean log everything to
the console, where systemd uses the debug from the Scandinavian "day-boog"
meaning "fail to boot". If a future versions uses argv[] instead of
reading /proc/cmdline, this confusion will be avoided.
eg: test 'FOO="this is --foo"' -- 'systemd.debug="true true true"'
Gives:
argv[0] = '/debug-init'
argv[1] = 'test'
argv[2] = 'systemd.debug=true true true'
envp[0] = 'HOME=/'
envp[1] = 'TERM=linux'
envp[2] = 'FOO=this is --foo'
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index 204a67743804..b1990c5524e1 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -321,7 +321,7 @@ extern bool parameq(const char *name1, const char *name2);
extern bool parameqn(const char *name1, const char *name2, size_t n);
/* Called on module insert or kernel boot */
-extern int parse_args(const char *name,
+extern char *parse_args(const char *name,
char *args,
const struct kernel_param *params,
unsigned num,
diff --git a/init/main.c b/init/main.c
index 9c7fd4c9249f..e9d458b5d77b 100644
--- a/init/main.c
+++ b/init/main.c
@@ -252,6 +252,27 @@ static int __init repair_env_string(char *param, char *val, const char *unused)
return 0;
}
+/* Anything after -- gets handed straight to init. */
+static int __init set_init_arg(char *param, char *val, const char *unused)
+{
+ unsigned int i;
+
+ if (panic_later)
+ return 0;
+
+ repair_env_string(param, val, unused);
+
+ for (i = 0; argv_init[i]; i++) {
+ if (i == MAX_INIT_ARGS) {
+ panic_later = "init";
+ panic_param = param;
+ return 0;
+ }
+ }
+ argv_init[i] = param;
+ return 0;
+}
+
/*
* Unknown boot options get handed to init, unless they look like
* unused parameters (modprobe will find them in /proc/cmdline).
@@ -478,7 +499,7 @@ static void __init mm_init(void)
asmlinkage void __init start_kernel(void)
{
- char * command_line;
+ char * command_line, *after_dashes;
extern const struct kernel_param __start___param[], __stop___param[];
/*
@@ -519,9 +540,13 @@ asmlinkage void __init start_kernel(void)
pr_notice("Kernel command line: %s\n", boot_command_line);
parse_early_param();
- parse_args("Booting kernel", static_command_line, __start___param,
- __stop___param - __start___param,
- -1, -1, &unknown_bootoption);
+ after_dashes = parse_args("Booting kernel",
+ static_command_line, __start___param,
+ __stop___param - __start___param,
+ -1, -1, &unknown_bootoption);
+ if (after_dashes)
+ parse_args("Setting init args", after_dashes, NULL, 0, -1, -1,
+ set_init_arg);
jump_label_init();
diff --git a/kernel/module.c b/kernel/module.c
index 29f7790eaa14..600d1fbf1773 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -3193,6 +3193,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
{
struct module *mod;
long err;
+ char *after_dashes;
err = module_sig_check(info);
if (err)
@@ -3277,10 +3278,15 @@ static int load_module(struct load_info *info, const char __user *uargs,
goto ddebug_cleanup;
/* Module is ready to execute: parsing args may do that. */
- err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp,
- -32768, 32767, unknown_module_param_cb);
- if (err < 0)
+ after_dashes = parse_args(mod->name, mod->args, mod->kp, mod->num_kp,
+ -32768, 32767, unknown_module_param_cb);
+ if (IS_ERR(after_dashes)) {
+ err = PTR_ERR(after_dashes);
goto bug_cleanup;
+ } else if (after_dashes) {
+ pr_warn("%s: parameters '%s' after `--' ignored\n",
+ mod->name, after_dashes);
+ }
/* Link in to syfs. */
err = mod_sysfs_setup(mod, info, mod->kp, mod->num_kp);
diff --git a/kernel/params.c b/kernel/params.c
index b00142e7f3ba..1e52ca233fd9 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -177,13 +177,13 @@ static char *next_arg(char *args, char **param, char **val)
}
/* Args looks like "foo=bar,bar2 baz=fuz wiz". */
-int parse_args(const char *doing,
- char *args,
- const struct kernel_param *params,
- unsigned num,
- s16 min_level,
- s16 max_level,
- int (*unknown)(char *param, char *val, const char *doing))
+char *parse_args(const char *doing,
+ char *args,
+ const struct kernel_param *params,
+ unsigned num,
+ s16 min_level,
+ s16 max_level,
+ int (*unknown)(char *param, char *val, const char *doing))
{
char *param, *val;
@@ -198,6 +198,9 @@ int parse_args(const char *doing,
int irq_was_disabled;
args = next_arg(args, ¶m, &val);
+ /* Stop at -- */
+ if (!val && strcmp(param, "--") == 0)
+ return args;
irq_was_disabled = irqs_disabled();
ret = parse_one(param, val, doing, params, num,
min_level, max_level, unknown);
@@ -208,22 +211,22 @@ int parse_args(const char *doing,
switch (ret) {
case -ENOENT:
pr_err("%s: Unknown parameter `%s'\n", doing, param);
- return ret;
+ return ERR_PTR(ret);
case -ENOSPC:
pr_err("%s: `%s' too large for parameter `%s'\n",
doing, val ?: "", param);
- return ret;
+ return ERR_PTR(ret);
case 0:
break;
default:
pr_err("%s: `%s' invalid for parameter `%s'\n",
doing, val ?: "", param);
- return ret;
+ return ERR_PTR(ret);
}
}
/* All parsed OK. */
- return 0;
+ return NULL;
}
/* Lazy bastard, eh? */
next prev parent reply other threads:[~2014-04-07 4:59 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-02 18:42 [RFC PATCH] cmdline: Hide "debug" from /proc/cmdline Steven Rostedt
2014-04-02 18:57 ` Linus Torvalds
2014-04-02 19:04 ` Andrew Morton
2014-04-02 19:05 ` Borislav Petkov
2014-04-02 19:08 ` Randy Dunlap
2014-04-02 19:50 ` Thomas Gleixner
2014-04-02 20:05 ` Richard Weinberger
2014-04-02 20:43 ` Thomas Gleixner
2014-04-02 22:18 ` Greg KH
2014-04-02 19:08 ` Borislav Petkov
2014-04-02 19:33 ` Steven Rostedt
2014-04-02 22:12 ` Mateusz Guzik
2014-04-02 22:30 ` David Daney
2014-04-02 22:37 ` Greg KH
2014-04-02 23:13 ` Linus Torvalds
2014-04-02 23:23 ` Jiri Kosina
2014-04-02 23:28 ` Andrew Morton
2014-04-02 23:42 ` Linus Torvalds
2014-04-02 23:47 ` Jiri Kosina
2014-04-02 23:52 ` Linus Torvalds
2014-04-02 23:57 ` Jiri Kosina
2014-04-03 1:38 ` Steven Rostedt
2014-04-03 1:47 ` Linus Torvalds
2014-04-03 9:03 ` Borislav Petkov
2014-04-03 10:43 ` Joerg Roedel
2014-04-03 17:05 ` Theodore Ts'o
2014-04-03 17:09 ` H. Peter Anvin
2014-04-03 17:18 ` Theodore Ts'o
2014-04-03 19:19 ` H. Peter Anvin
2014-04-04 18:21 ` Andy Lutomirski
2014-04-04 18:32 ` Linus Torvalds
2014-04-04 18:57 ` Andy Lutomirski
2014-04-04 19:09 ` Linus Torvalds
2014-04-04 21:17 ` John Stoffel
2014-04-04 23:17 ` Greg Kroah-Hartman
2014-04-05 14:37 ` John Stoffel
2014-04-05 23:23 ` Theodore Ts'o
2014-04-04 18:42 ` Linus Torvalds
2014-04-04 18:51 ` Andrew Morton
2014-04-04 18:57 ` Linus Torvalds
2014-04-06 20:49 ` David Timothy Strauss
2014-05-06 9:38 ` Felipe Contreras
2014-04-04 19:44 ` Steven Rostedt
2014-04-04 20:17 ` Theodore Ts'o
2014-04-04 22:45 ` Alexei Starovoitov
2014-04-04 22:48 ` Linus Torvalds
2014-04-04 19:00 ` Andy Lutomirski
2014-04-03 11:23 ` Borislav Petkov
2014-04-03 11:38 ` Ingo Molnar
2014-04-15 7:26 ` Borislav Petkov
2014-04-03 10:34 ` Måns Rullgård
2014-04-03 11:03 ` Borislav Petkov
2014-04-06 17:19 ` One Thousand Gnomes
2014-05-06 9:47 ` Felipe Contreras
2014-04-02 23:47 ` Joe Perches
2014-04-02 23:31 ` Linus Torvalds
2014-04-03 11:25 ` Måns Rullgård
2014-04-03 15:17 ` Tim Bird
2014-04-03 18:06 ` Greg Kroah-Hartman
2014-05-06 9:35 ` Felipe Contreras
2014-04-07 4:54 ` Rusty Russell [this message]
2014-05-02 22:34 ` Andrew Morton
2014-05-05 2:17 ` Rusty Russell
2014-05-05 13:15 ` Randy Dunlap
2014-05-06 0:57 ` Rusty Russell
2014-05-19 8:06 ` Diego Viola
2014-05-19 8:11 ` Diego Viola
2014-05-19 14:40 ` Randy Dunlap
2014-05-20 1:26 ` Rusty Russell
2014-05-20 6:26 ` Diego Viola
2014-05-21 1:52 ` Rusty Russell
2014-04-03 0:49 ` Steven Rostedt
-- strict thread matches above, loose matches on Subject: below --
2014-04-23 15:15 Borislav Petkov
2014-04-23 20:44 ` Borislav Petkov
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=87wqf1oi22.fsf@rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=gregkh@linuxfoundation.org \
--cc=hpa@zytor.com \
--cc=kay@vrfy.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mguzik@redhat.com \
--cc=mingo@kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/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