printk: drop redundant devkmsg_log_str memsets
PATCH 1/1 printk: drop redundant devkmsg_log_str memsets
We copy in null terminated strings "on" and "off", no need to zero out devkmsg_log_str in control_devkmsg().
--- kernel/printk/printk.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
kernel/printk/printk.c +4 -7
@@ -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. */ /*
Signature · 1 line
2.16.0
Quoted 20 lines · On Fri, 19 Jan 2018 13:39:01 +0900 Sergey Senozhatsky…
We copy in null terminated strings "on" and "off", no need to zero out
devkmsg_log_strincontrol_devkmsg().Signed-off-by Sergey Senozhatsky <[email protected]>--- kernel/printk/printk.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)kernel/printk/printk.c +0
-4@@ -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 ) {
kernel/printk/printk.c static int __init control_devkmsg(char *str) · line 145
Quoted 10 lines
kernel/printk/printk.c +4
-3-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
-- Steve
Quoted 11 lines · Steven Rostedt
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.| 00000003Reviewed-by Steven Rostedt (VMware) <[email protected]>
thanks.
-ss
Quoted 4 lines · Sergey Senozhatsky
We copy in null terminated strings "on" and "off", no need to zero out
devkmsg_log_strincontrol_devkmsg().Signed-off-by Sergey Senozhatsky <[email protected]>
Great catch!
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
Quoted 4 lines · Petr Mladek
Quoted 3 lines · Sergey Senozhatsky
We copy in null terminated strings "on" and "off", no need to zero out
devkmsg_log_strincontrol_devkmsg().
Quoted 8 lines
Quoted 1 line
Signed-off-by Sergey Senozhatsky <[email protected]>Great catch!
Reviewed-by Petr Mladek <[email protected]>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