init: Carefuly handle loglevel option passed to kernel cmdline.
PATCH 1/1 init: Carefuly handle loglevel option passed to kernel cmdline.
From: Alexander Sverdlin <[email protected]>
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.
---
init/main.c +12 -1
@@ -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 ; }
Quoted 2 lines · Alexander Sverdlin
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(-)
init/main.c +5 -1
@@ -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 ; }