LKML Archive on
 help / color / Atom feed
From: Borislav Petkov <>
To: LKML <>
Cc: Andrew Morton <>,
	Kees Cook <>,
	"Steven Rostedt (VMware)" <>,
Subject: [RFC PATCH] kernel/panic: Filter out a potential trailing newline
Date: Tue,  9 Oct 2018 22:50:19 +0200
Message-ID: <> (raw)

From: Borislav Petkov <>

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

Now, if one goes and removes the newline chars from all panic()
invocations - and the stats right now look like this:

~300 calls with an \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.

Signed-off-by: Borislav Petkov <>
Cc: Andrew Morton <>
Cc: Kees Cook <>
Cc: "Steven Rostedt (VMware)" <>
 kernel/panic.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/panic.c b/kernel/panic.c
index 8b2e002d52eb..5776d2879650 100644
--- a/kernel/panic.c
+++ b/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, ...)
 	va_start(args, fmt);
-	vsnprintf(buf, sizeof(buf), fmt, args);
+	len = vscnprintf(buf, sizeof(buf), fmt, args);
+	if (len && buf[len - 1] == '\n')
+		buf[len - 1] = '\0';
 	pr_emerg("Kernel panic - not syncing: %s\n", buf);

             reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-09 20:50 Borislav Petkov [this message]
2018-10-09 21:13 ` Kees Cook
2018-10-09 21:23 ` Steven Rostedt
2018-10-10  6:00 ` Ingo Molnar

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LKML Archive on

Archives are clonable:
	git clone --mirror lkml/git/0.git
	git clone --mirror lkml/git/1.git
	git clone --mirror lkml/git/2.git
	git clone --mirror lkml/git/3.git
	git clone --mirror lkml/git/4.git
	git clone --mirror lkml/git/5.git
	git clone --mirror lkml/git/6.git
	git clone --mirror lkml/git/7.git
	git clone --mirror lkml/git/8.git
	git clone --mirror lkml/git/9.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ \
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone