The patch titled Subject: kernel/panic.c: filter out a potential trailing newline has been added to the -mm tree. Its filename is kernel-panic-filter-out-a-potential-trailing-newline.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/kernel-panic-filter-out-a-potential-trailing-newline.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/kernel-panic-filter-out-a-potential-trailing-newline.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Borislav Petkov <bp@xxxxxxx> Subject: 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@xxxxxxxxx Signed-off-by: Borislav Petkov <bp@xxxxxxx> Acked-by: Kees Cook <keescook@xxxxxxxxxxxx> Reviewed-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx> Acked-by: Ingo Molnar <mingo@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- diff -puN kernel/panic.c~kernel-panic-filter-out-a-potential-trailing-newline kernel/panic.c --- a/kernel/panic.c~kernel-panic-filter-out-a-potential-trailing-newline +++ a/kernel/panic.c @@ -136,7 +136,7 @@ void panic(const char *fmt, ...) { static char buf[1024]; va_list args; - long i, i_next = 0; + long i, i_next = 0, len; int state = 0; int old_cpu, this_cpu; bool _crash_kexec_post_notifiers = crash_kexec_post_notifiers; @@ -173,8 +173,12 @@ void panic(const char *fmt, ...) console_verbose(); bust_spinlocks(1); va_start(args, fmt); - vsnprintf(buf, sizeof(buf), fmt, args); + len = vscnprintf(buf, sizeof(buf), fmt, args); va_end(args); + + if (len && buf[len - 1] == '\n') + buf[len - 1] = '\0'; + pr_emerg("Kernel panic - not syncing: %s\n", buf); #ifdef CONFIG_DEBUG_BUGVERBOSE /* _ Patches currently in -mm which might be from bp@xxxxxxx are kernel-panic-filter-out-a-potential-trailing-newline.patch