diff options
| author | Borislav Petkov <bp@suse.de> | 2018-10-30 18:07:17 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-10-31 11:54:14 -0400 |
| commit | b49dec1cf8ff1e0b204dd2c30b95a92d75591146 (patch) | |
| tree | 37133aa2c8be76f3c2ca6552689cfe7f47b64f3e | |
| parent | 95c4fb78fb23081472465ca20d5d31c4b780ed82 (diff) | |
kernel/panic.c: filter out a potential trailing newline
If a call to panic() terminates the string with a \n , the result puts the
closing brace ']---' on a newline because panic() itself adds \n too.
Now, if one goes and removes the newline chars from all panic()
invocations - and the stats right now look like this:
~300 calls with a \n
~500 calls without a \n
one is destined to a neverending game of whack-a-mole because the usual
thing to do is add a newline at the end of a string a function is supposed
to print.
Therefore, simply zap any \n at the end of the panic string to avoid
touching so many places in the kernel.
Link: http://lkml.kernel.org/r/20181009205019.2786-1-bp@alien8.de
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Acked-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
| -rw-r--r-- | kernel/panic.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/kernel/panic.c b/kernel/panic.c index 837a94b7024d..f6d549a29a5c 100644 --- a/kernel/panic.c +++ b/kernel/panic.c | |||
| @@ -136,7 +136,7 @@ void panic(const char *fmt, ...) | |||
| 136 | { | 136 | { |
| 137 | static char buf[1024]; | 137 | static char buf[1024]; |
| 138 | va_list args; | 138 | va_list args; |
| 139 | long i, i_next = 0; | 139 | long i, i_next = 0, len; |
| 140 | int state = 0; | 140 | int state = 0; |
| 141 | int old_cpu, this_cpu; | 141 | int old_cpu, this_cpu; |
| 142 | bool _crash_kexec_post_notifiers = crash_kexec_post_notifiers; | 142 | bool _crash_kexec_post_notifiers = crash_kexec_post_notifiers; |
| @@ -173,8 +173,12 @@ void panic(const char *fmt, ...) | |||
| 173 | console_verbose(); | 173 | console_verbose(); |
| 174 | bust_spinlocks(1); | 174 | bust_spinlocks(1); |
| 175 | va_start(args, fmt); | 175 | va_start(args, fmt); |
| 176 | vsnprintf(buf, sizeof(buf), fmt, args); | 176 | len = vscnprintf(buf, sizeof(buf), fmt, args); |
| 177 | va_end(args); | 177 | va_end(args); |
| 178 | |||
| 179 | if (len && buf[len - 1] == '\n') | ||
| 180 | buf[len - 1] = '\0'; | ||
| 181 | |||
| 178 | pr_emerg("Kernel panic - not syncing: %s\n", buf); | 182 | pr_emerg("Kernel panic - not syncing: %s\n", buf); |
| 179 | #ifdef CONFIG_DEBUG_BUGVERBOSE | 183 | #ifdef CONFIG_DEBUG_BUGVERBOSE |
| 180 | /* | 184 | /* |
