linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Borislav Petkov <bp@alien8.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Kees Cook <keescook@chromium.org>,
	"Steven Rostedt (VMware)" <rostedt@goodmis.org>,
	x86@kernel.org
Subject: Re: [RFC PATCH] kernel/panic: Filter out a potential trailing newline
Date: Wed, 10 Oct 2018 08:00:02 +0200	[thread overview]
Message-ID: <20181010060001.GA36987@gmail.com> (raw)
In-Reply-To: <20181009205019.2786-1-bp@alien8.de>


* Borislav Petkov <bp@alien8.de> wrote:

> From: Borislav Petkov <bp@suse.de>
> 
> 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 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 <bp@suse.de>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> Cc: x86@kernel.org
> ---
>  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, ...)
>  	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';

Nice, this patch saves a couple of hundred trivial upstream commits in the next 20 years:

Acked-by: Ingo Molnar <mingo@kernel.org>

Thanks,

	Ingo

      parent reply	other threads:[~2018-10-10  6:00 UTC|newest]

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

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=20181010060001.GA36987@gmail.com \
    --to=mingo@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).