linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: Petr Mladek <pmladek@suse.com>,
	linux-kernel@vger.kernel.org,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: Re: [PATCH] printk: drop redundant devkmsg_log_str memsets
Date: Fri, 19 Jan 2018 09:17:07 -0500	[thread overview]
Message-ID: <20180119091707.0a15a24d@gandalf.local.home> (raw)
In-Reply-To: <20180119043901.1728-1-sergey.senozhatsky@gmail.com>

On Fri, 19 Jan 2018 13:39:01 +0900
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> wrote:

> We copy in null terminated strings "on" and "off", no
> need to zero out devkmsg_log_str in control_devkmsg().
> 
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> ---
>  kernel/printk/printk.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index d70927c384f3..9faddcfd3994 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -136,13 +136,10 @@ static int __init control_devkmsg(char *str)
>  	/*
>  	 * Set sysctl string accordingly:
>  	 */
> -	if (devkmsg_log == DEVKMSG_LOG_MASK_ON) {
> -		memset(devkmsg_log_str, 0, DEVKMSG_STR_MAX_SIZE);
> -		strncpy(devkmsg_log_str, "on", 2);
> -	} else if (devkmsg_log == DEVKMSG_LOG_MASK_OFF) {
> -		memset(devkmsg_log_str, 0, DEVKMSG_STR_MAX_SIZE);
> -		strncpy(devkmsg_log_str, "off", 3);
> -	}
> +	if (devkmsg_log == DEVKMSG_LOG_MASK_ON)
> +		strcpy(devkmsg_log_str, "on");
> +	else if (devkmsg_log == DEVKMSG_LOG_MASK_OFF)
> +		strcpy(devkmsg_log_str, "off");
>  	/* else "ratelimit" which is set by default. */
>  
>  	/*

Yep, and even the sysctl checks for the terminating nul string, so
there's no leaks of any kind.

Tested by adding: printk.devkmsg=on and running:

 $ hexdump -C /proc/sys/kernel/printk_devkmsg
00000000  6f 6e 0a                                          |on.|
00000003


Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve

  reply	other threads:[~2018-01-19 14:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-19  4:39 [PATCH] printk: drop redundant devkmsg_log_str memsets Sergey Senozhatsky
2018-01-19 14:17 ` Steven Rostedt [this message]
2018-01-20  6:05   ` Sergey Senozhatsky
2018-01-22  9:54 ` Petr Mladek
2018-01-22  9:59   ` Sergey Senozhatsky

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=20180119091707.0a15a24d@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmladek@suse.com \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=sergey.senozhatsky@gmail.com \
    /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).