linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] printk: drop redundant devkmsg_log_str memsets
@ 2018-01-19  4:39 Sergey Senozhatsky
  2018-01-19 14:17 ` Steven Rostedt
  2018-01-22  9:54 ` Petr Mladek
  0 siblings, 2 replies; 5+ messages in thread
From: Sergey Senozhatsky @ 2018-01-19  4:39 UTC (permalink / raw)
  To: Petr Mladek, Steven Rostedt; +Cc: linux-kernel, Sergey Senozhatsky

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. */
 
 	/*
-- 
2.16.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] printk: drop redundant devkmsg_log_str memsets
  2018-01-19  4:39 [PATCH] printk: drop redundant devkmsg_log_str memsets Sergey Senozhatsky
@ 2018-01-19 14:17 ` Steven Rostedt
  2018-01-20  6:05   ` Sergey Senozhatsky
  2018-01-22  9:54 ` Petr Mladek
  1 sibling, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2018-01-19 14:17 UTC (permalink / raw)
  To: Sergey Senozhatsky; +Cc: Petr Mladek, linux-kernel, Sergey Senozhatsky

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] printk: drop redundant devkmsg_log_str memsets
  2018-01-19 14:17 ` Steven Rostedt
@ 2018-01-20  6:05   ` Sergey Senozhatsky
  0 siblings, 0 replies; 5+ messages in thread
From: Sergey Senozhatsky @ 2018-01-20  6:05 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Sergey Senozhatsky, Petr Mladek, linux-kernel, Sergey Senozhatsky

On (01/19/18 09:17), Steven Rostedt wrote:
> 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>

thanks.

	-ss

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] printk: drop redundant devkmsg_log_str memsets
  2018-01-19  4:39 [PATCH] printk: drop redundant devkmsg_log_str memsets Sergey Senozhatsky
  2018-01-19 14:17 ` Steven Rostedt
@ 2018-01-22  9:54 ` Petr Mladek
  2018-01-22  9:59   ` Sergey Senozhatsky
  1 sibling, 1 reply; 5+ messages in thread
From: Petr Mladek @ 2018-01-22  9:54 UTC (permalink / raw)
  To: Sergey Senozhatsky; +Cc: Steven Rostedt, linux-kernel, Sergey Senozhatsky

On Fri 2018-01-19 13:39:01, Sergey Senozhatsky 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>

Great catch!

Reviewed-by: Petr Mladek <pmladek@suse.com>

I have pushed this into for-4.16 branch in printk.git, see
https://git.kernel.org/pub/scm/linux/kernel/git/pmladek/printk.git/commit/?h=for-4.16&id=6fd78a1a99c9580da49ee8f951fdce9846256375

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] printk: drop redundant devkmsg_log_str memsets
  2018-01-22  9:54 ` Petr Mladek
@ 2018-01-22  9:59   ` Sergey Senozhatsky
  0 siblings, 0 replies; 5+ messages in thread
From: Sergey Senozhatsky @ 2018-01-22  9:59 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Sergey Senozhatsky, Steven Rostedt, linux-kernel,
	Sergey Senozhatsky

On (01/22/18 10:54), Petr Mladek wrote:
> On Fri 2018-01-19 13:39:01, Sergey Senozhatsky 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>
> 
> Great catch!
> 
> Reviewed-by: Petr Mladek <pmladek@suse.com>
> 
> I have pushed this into for-4.16 branch in printk.git, see
> https://git.kernel.org/pub/scm/linux/kernel/git/pmladek/printk.git/commit/?h=for-4.16&id=6fd78a1a99c9580da49ee8f951fdce9846256375

Thanks.

	-ss

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-01-22  9:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-19  4:39 [PATCH] printk: drop redundant devkmsg_log_str memsets Sergey Senozhatsky
2018-01-19 14:17 ` Steven Rostedt
2018-01-20  6:05   ` Sergey Senozhatsky
2018-01-22  9:54 ` Petr Mladek
2018-01-22  9:59   ` Sergey Senozhatsky

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).