linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] init: Carefuly handle loglevel option passed to kernel cmdline.
@ 2011-09-20 13:45 Alexander Sverdlin
  2011-09-20 14:56 ` Linus Torvalds
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Sverdlin @ 2011-09-20 13:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: torvalds

From: Alexander Sverdlin <alexander.sverdlin@sysgo.com>

Carefuly handle loglevel option passed to kernel cmdline.

When malformed loglevel value (for example "${abc}") passed to kernel
cmdline, the loglevel itself is being set to 0. This suppresses all
following messages, including all the errors and crashes caused by
other malformed cmdline options. This could make debugging process
quite tricky. Provided modifications leaves previous value of loglevel
if the new value is incorrect and report error code in this case.

Signed-off-by: Alexander Sverdlin <alexander.sverdlin@sysgo.com>
---
--- linux.old/init/main.c	2011-09-20 15:23:05.038279428 +0200
+++ linux/init/main.c	2011-09-20 15:23:44.064930478 +0200
@@ -209,7 +209,18 @@ early_param("quiet", quiet_kernel);
 
 static int __init loglevel(char *str)
 {
-	get_option(&str, &console_loglevel);
+	int tmp_loglevel;
+
+	/*
+	 * Only update loglevel value when correct setting was passed,
+	 * to prevent blind crashes (when loglevel being set to 0) that
+	 * are quite hard to debug
+	 */
+	if (get_option(&str, &tmp_loglevel))
+		console_loglevel = tmp_loglevel;
+	else
+		return EINVAL;
+
 	return 0;
 }
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] init: Carefuly handle loglevel option passed to kernel cmdline.
  2011-09-20 13:45 Alexander Sverdlin
@ 2011-09-20 14:56 ` Linus Torvalds
  0 siblings, 0 replies; 3+ messages in thread
From: Linus Torvalds @ 2011-09-20 14:56 UTC (permalink / raw)
  To: Alexander Sverdlin; +Cc: linux-kernel

On Tue, Sep 20, 2011 at 6:45 AM, Alexander Sverdlin <asv@sysgo.com> wrote:
>
> Carefuly handle loglevel option passed to kernel cmdline.

Ugh. I dislike how you misuse the error numbers - it *happens* to
work, but we return negative error numbers, not positive ones in the
kernel.

Also, doing an if/else when one arm does a return just looks overly complicated.

Does this (whitespace-damaged) patch work for you?

                 Linus

---
 init/main.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/init/main.c b/init/main.c
index 9c51ee7adf3d..5827722ec491 100644
--- a/init/main.c
+++ b/init/main.c
@@ -209,7 +209,11 @@ early_param("quiet", quiet_kernel);

 static int __init loglevel(char *str)
 {
-       get_option(&str, &console_loglevel);
+       int loglevel;
+
+       if (!get_option(&str, &loglevel))
+               return -EINVAL;
+       console_loglevel = loglevel;
        return 0;
 }

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] init: Carefuly handle loglevel option passed to kernel cmdline
@ 2011-09-21  7:51 Alexander Sverdlin
  0 siblings, 0 replies; 3+ messages in thread
From: Alexander Sverdlin @ 2011-09-21  7:51 UTC (permalink / raw)
  To: torvalds; +Cc: linux-kernel

From: Alexander Sverdlin <alexander.sverdlin@sysgo.com>

Carefuly handle loglevel option passed to kernel cmdline.

When malformed loglevel value (for example "${abc}") passed to kernel
cmdline, the loglevel itself is being set to 0. This suppresses all
following messages, including all the errors and crashes caused by
other malformed cmdline options. This could make debugging process
quite tricky. Provided modifications leaves previous value of loglevel
if the new value is incorrect and report error code in this case.

Signed-off-by: Alexander Sverdlin <alexander.sverdlin@sysgo.com>
---
--- linux.old/init/main.c	2011-09-20 15:23:05.038279428 +0200
+++ linux/init/main.c	2011-09-21 09:39:24.266516051 +0200
@@ -209,8 +209,19 @@ early_param("quiet", quiet_kernel);
 
 static int __init loglevel(char *str)
 {
-	get_option(&str, &console_loglevel);
-	return 0;
+	int tmp_loglevel;
+
+	/*
+	 * Only update loglevel value when correct setting was passed,
+	 * to prevent blind crashes (when loglevel being set to 0) that
+	 * are quite hard to debug
+	 */
+	if (get_option(&str, &tmp_loglevel)) {
+		console_loglevel = tmp_loglevel;
+		return 0;
+	}
+
+	return -EINVAL;
 }
 
 early_param("loglevel", loglevel);




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-09-21  7:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-21  7:51 [PATCH] init: Carefuly handle loglevel option passed to kernel cmdline Alexander Sverdlin
  -- strict thread matches above, loose matches on Subject: below --
2011-09-20 13:45 Alexander Sverdlin
2011-09-20 14:56 ` Linus Torvalds

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).