linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [linux-next:master 4605/11713] kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified bound depends on the length of the source argument
@ 2022-03-09 15:48 kernel test robot
  2022-03-10 15:12 ` Tom Zanussi
  0 siblings, 1 reply; 7+ messages in thread
From: kernel test robot @ 2022-03-09 15:48 UTC (permalink / raw)
  To: Tom Zanussi
  Cc: kbuild-all, Linux Memory Management List, Steven Rostedt (Google)

Hi Tom,

FYI, the error/warning still remains.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   4e7a74a6856f8613dab9794da4b5cfb8fd54fb8c
commit: 27c888da9867725784bad3d6455d6e53b425fa2b [4605/11713] tracing: Remove size restriction on synthetic event cmd error logging
config: powerpc64-buildonly-randconfig-r006-20220309 (https://download.01.org/0day-ci/archive/20220309/202203092349.i2I1pdlw-lkp@intel.com/config)
compiler: powerpc64-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=27c888da9867725784bad3d6455d6e53b425fa2b
        git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
        git fetch --no-tags linux-next master
        git checkout 27c888da9867725784bad3d6455d6e53b425fa2b
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=powerpc SHELL=/bin/bash kernel/trace/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   kernel/trace/trace_events_synth.c: In function 'last_cmd_set':
>> kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-truncation]
      65 |         strncpy(last_cmd, str, strlen(str) + 1);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/trace/trace_events_synth.c:65:32: note: length computed here
      65 |         strncpy(last_cmd, str, strlen(str) + 1);
         |                                ^~~~~~~~~~~


vim +/strncpy +65 kernel/trace/trace_events_synth.c

    54	
    55	static void last_cmd_set(const char *str)
    56	{
    57		if (!str)
    58			return;
    59	
    60		kfree(last_cmd);
    61		last_cmd = kzalloc(strlen(str) + 1, GFP_KERNEL);
    62		if (!last_cmd)
    63			return;
    64	
  > 65		strncpy(last_cmd, str, strlen(str) + 1);
    66	}
    67	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org


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

* Re: [linux-next:master 4605/11713] kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified bound depends on the length of the source argument
  2022-03-09 15:48 [linux-next:master 4605/11713] kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified bound depends on the length of the source argument kernel test robot
@ 2022-03-10 15:12 ` Tom Zanussi
  2022-03-10 15:49   ` Steven Rostedt
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Zanussi @ 2022-03-10 15:12 UTC (permalink / raw)
  To: kernel test robot
  Cc: kbuild-all, Linux Memory Management List, Steven Rostedt (Google)

On Wed, 2022-03-09 at 23:48 +0800, kernel test robot wrote:
> Hi Tom,
> 
> FYI, the error/warning still remains.
> 
> 

Thanks, the patch below fixes it.  I'll submit to lkml, but not sure
whether to submit the fix or resubmit the original patch...

Tom


[PATCH] tracing: Fix strncpy warning in trace_events_synth.c

0-day reported the strncpy error below:

../kernel/trace/trace_events_synth.c: In function 'last_cmd_set':
../kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified bound depends on the length o\
f the source argument [-Wstringop-truncation]
   65 |         strncpy(last_cmd, str, strlen(str) + 1);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../kernel/trace/trace_events_synth.c:65:32: note: length computed here
   65 |         strncpy(last_cmd, str, strlen(str) + 1);
      |                                ^~~~~~~~~~~

There's no reason to use strncpy here, since the buffer being copied
to was just allocated as strlen(str) + 1, and therefore the strcpy()
of str will exactly fit, including the null terminator.

Fixes: 27c888da9867 ("tracing: Remove size restriction on synthetic event cmd error logging")

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Tom Zanussi <zanussi@kernel.org>
---
 kernel/trace/trace_events_synth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
index fdd79e07e2fc..a133396ee29d 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -62,7 +62,7 @@ static void last_cmd_set(const char *str)
 	if (!last_cmd)
 		return;
 
-	strncpy(last_cmd, str, strlen(str) + 1);
+	strcpy(last_cmd, str);
 }
 
 static void synth_err(u8 err_type, u16 err_pos)
-- 
2.17.1




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

* Re: [linux-next:master 4605/11713] kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified bound depends on the length of the source argument
  2022-03-10 15:12 ` Tom Zanussi
@ 2022-03-10 15:49   ` Steven Rostedt
  2022-03-10 16:08     ` Tom Zanussi
  0 siblings, 1 reply; 7+ messages in thread
From: Steven Rostedt @ 2022-03-10 15:49 UTC (permalink / raw)
  To: Tom Zanussi; +Cc: kernel test robot, kbuild-all, Linux Memory Management List

On Thu, 10 Mar 2022 09:12:39 -0600
Tom Zanussi <zanussi@kernel.org> wrote:

> On Wed, 2022-03-09 at 23:48 +0800, kernel test robot wrote:
> > Hi Tom,
> > 
> > FYI, the error/warning still remains.
> > 
> >   
> 
> Thanks, the patch below fixes it.  I'll submit to lkml, but not sure
> whether to submit the fix or resubmit the original patch...

I don't rebase my linux-next branch unless there's a really go reason to do
so. But I also have this patch going through my testing:

  https://lore.kernel.org/all/20220308110736.479e3cc9@gandalf.local.home/

Which I believe fixes the issue.

But we can use this patch too, but I do get nervous about plain strcat().

-- Steve


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

* Re: [linux-next:master 4605/11713] kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified bound depends on the length of the source argument
  2022-03-10 15:49   ` Steven Rostedt
@ 2022-03-10 16:08     ` Tom Zanussi
  2022-03-10 16:26       ` Steven Rostedt
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Zanussi @ 2022-03-10 16:08 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: kernel test robot, kbuild-all, Linux Memory Management List

Hi Steve,

On Thu, 2022-03-10 at 10:49 -0500, Steven Rostedt wrote:
> On Thu, 10 Mar 2022 09:12:39 -0600
> Tom Zanussi <zanussi@kernel.org> wrote:
> 
> > On Wed, 2022-03-09 at 23:48 +0800, kernel test robot wrote:
> > > Hi Tom,
> > > 
> > > FYI, the error/warning still remains.
> > > 
> > >   
> > 
> > Thanks, the patch below fixes it.  I'll submit to lkml, but not
> > sure
> > whether to submit the fix or resubmit the original patch...
> 
> I don't rebase my linux-next branch unless there's a really go reason
> to do
> so. But I also have this patch going through my testing:
> 
>   
> https://lore.kernel.org/all/20220308110736.479e3cc9@gandalf.local.home/
> 
> Which I believe fixes the issue.
> 
> But we can use this patch too, but I do get nervous about plain
> strcat().
> 

This patch is for the last_cmd_set() in trace_events_synth.c, yours is
for trace_events_hist.c, which also has last_cmd_set().

The one in trace_events_synth.c is much simpler, so it seemed to me
that strcpy() would be ok there.

Tom


> -- Steve



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

* Re: [linux-next:master 4605/11713] kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified bound depends on the length of the source argument
  2022-03-10 16:08     ` Tom Zanussi
@ 2022-03-10 16:26       ` Steven Rostedt
  2022-03-10 16:45         ` Tom Zanussi
  0 siblings, 1 reply; 7+ messages in thread
From: Steven Rostedt @ 2022-03-10 16:26 UTC (permalink / raw)
  To: Tom Zanussi; +Cc: kernel test robot, kbuild-all, Linux Memory Management List

On Thu, 10 Mar 2022 10:08:18 -0600
Tom Zanussi <zanussi@kernel.org> wrote:

> This patch is for the last_cmd_set() in trace_events_synth.c, yours is
> for trace_events_hist.c, which also has last_cmd_set().

Ug, name confusion :-p

> 
> The one in trace_events_synth.c is much simpler, so it seemed to me
> that strcpy() would be ok there.

If you are only copying the string, why not just use kstrdup()?

-- Steve


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

* Re: [linux-next:master 4605/11713] kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified bound depends on the length of the source argument
  2022-03-10 16:26       ` Steven Rostedt
@ 2022-03-10 16:45         ` Tom Zanussi
  2022-03-10 17:07           ` Steven Rostedt
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Zanussi @ 2022-03-10 16:45 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: kernel test robot, kbuild-all, Linux Memory Management List

On Thu, 2022-03-10 at 11:26 -0500, Steven Rostedt wrote:
> On Thu, 10 Mar 2022 10:08:18 -0600
> Tom Zanussi <zanussi@kernel.org> wrote:
> 
> > This patch is for the last_cmd_set() in trace_events_synth.c, yours
> > is
> > for trace_events_hist.c, which also has last_cmd_set().
> 
> Ug, name confusion :-p
> 
> > 
> > The one in trace_events_synth.c is much simpler, so it seemed to me
> > that strcpy() would be ok there.
> 
> If you are only copying the string, why not just use kstrdup()?

Good point, how about this?

From d106b7f636b40ddc08e03397a363fc489681b9e7 Mon Sep 17 00:00:00 2001
Message-Id: <
d106b7f636b40ddc08e03397a363fc489681b9e7.1646930605.git.zanussi@kernel.org
>
From: Tom Zanussi <zanussi@kernel.org>
Date: Thu, 10 Mar 2022 08:59:30 -0600
Subject: [PATCH] tracing: Fix strncpy warning in trace_events_synth.c

0-day reported the strncpy error below:

../kernel/trace/trace_events_synth.c: In function 'last_cmd_set':
../kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified
bound depends on the length o\
f the source argument [-Wstringop-truncation]
   65 |         strncpy(last_cmd, str, strlen(str) + 1);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../kernel/trace/trace_events_synth.c:65:32: note: length computed here
   65 |         strncpy(last_cmd, str, strlen(str) + 1);
      |                                ^~~~~~~~~~~

There's no reason to use strncpy here, in fact there's no reason to do
anything but a simple kstrdup() (note we don't even need to check for
failure since last_cmod is expected to be either the last cmd string
or NULL, and the containing function is a void return).

Fixes: 27c888da9867 ("tracing: Remove size restriction on synthetic
event cmd error logging")

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Tom Zanussi <zanussi@kernel.org>
---
 kernel/trace/trace_events_synth.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/kernel/trace/trace_events_synth.c
b/kernel/trace/trace_events_synth.c
index fdd79e07e2fc..5e8c07aef071 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -58,11 +58,8 @@ static void last_cmd_set(const char *str)
 		return;
 
 	kfree(last_cmd);
-	last_cmd = kzalloc(strlen(str) + 1, GFP_KERNEL);
-	if (!last_cmd)
-		return;
 
-	strncpy(last_cmd, str, strlen(str) + 1);
+	last_cmd = kstrdup(str, GFP_KERNEL);
 }
 
 static void synth_err(u8 err_type, u16 err_pos)
-- 
2.17.1




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

* Re: [linux-next:master 4605/11713] kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified bound depends on the length of the source argument
  2022-03-10 16:45         ` Tom Zanussi
@ 2022-03-10 17:07           ` Steven Rostedt
  0 siblings, 0 replies; 7+ messages in thread
From: Steven Rostedt @ 2022-03-10 17:07 UTC (permalink / raw)
  To: Tom Zanussi; +Cc: kernel test robot, kbuild-all, Linux Memory Management List

On Thu, 10 Mar 2022 10:45:09 -0600
Tom Zanussi <zanussi@kernel.org> wrote:

> On Thu, 2022-03-10 at 11:26 -0500, Steven Rostedt wrote:
> > On Thu, 10 Mar 2022 10:08:18 -0600
> > Tom Zanussi <zanussi@kernel.org> wrote:
> >   
> > > This patch is for the last_cmd_set() in trace_events_synth.c, yours
> > > is
> > > for trace_events_hist.c, which also has last_cmd_set().  
> > 
> > Ug, name confusion :-p
> >   
> > > 
> > > The one in trace_events_synth.c is much simpler, so it seemed to me
> > > that strcpy() would be ok there.  
> > 
> > If you are only copying the string, why not just use kstrdup()?  
> 
> Good point, how about this?
> 
> >From d106b7f636b40ddc08e03397a363fc489681b9e7 Mon Sep 17 00:00:00 2001  
> Message-Id: <
> d106b7f636b40ddc08e03397a363fc489681b9e7.1646930605.git.zanussi@kernel.org
> >  
> From: Tom Zanussi <zanussi@kernel.org>
> Date: Thu, 10 Mar 2022 08:59:30 -0600
> Subject: [PATCH] tracing: Fix strncpy warning in trace_events_synth.c
> 
> 0-day reported the strncpy error below:

Can you send this as a normal patch. My scripts do not pick up patches as
replies (besides patch series) or embedded in other email threads.

-- Steve


> 
> ../kernel/trace/trace_events_synth.c: In function 'last_cmd_set':
> ../kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified
> bound depends on the length o\
> f the source argument [-Wstringop-truncation]
>    65 |         strncpy(last_cmd, str, strlen(str) + 1);
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../kernel/trace/trace_events_synth.c:65:32: note: length computed here
>    65 |         strncpy(last_cmd, str, strlen(str) + 1);
>       |                                ^~~~~~~~~~~
> 
> There's no reason to use strncpy here, in fact there's no reason to do
> anything but a simple kstrdup() (note we don't even need to check for
> failure since last_cmod is expected to be either the last cmd string
> or NULL, and the containing function is a void return).
> 
> Fixes: 27c888da9867 ("tracing: Remove size restriction on synthetic
> event cmd error logging")
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Tom Zanussi <zanussi@kernel.org>
> ---
>  kernel/trace/trace_events_synth.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/kernel/trace/trace_events_synth.c
> b/kernel/trace/trace_events_synth.c
> index fdd79e07e2fc..5e8c07aef071 100644
> --- a/kernel/trace/trace_events_synth.c
> +++ b/kernel/trace/trace_events_synth.c
> @@ -58,11 +58,8 @@ static void last_cmd_set(const char *str)
>  		return;
>  
>  	kfree(last_cmd);
> -	last_cmd = kzalloc(strlen(str) + 1, GFP_KERNEL);
> -	if (!last_cmd)
> -		return;
>  
> -	strncpy(last_cmd, str, strlen(str) + 1);
> +	last_cmd = kstrdup(str, GFP_KERNEL);
>  }
>  
>  static void synth_err(u8 err_type, u16 err_pos)



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

end of thread, other threads:[~2022-03-10 17:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-09 15:48 [linux-next:master 4605/11713] kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified bound depends on the length of the source argument kernel test robot
2022-03-10 15:12 ` Tom Zanussi
2022-03-10 15:49   ` Steven Rostedt
2022-03-10 16:08     ` Tom Zanussi
2022-03-10 16:26       ` Steven Rostedt
2022-03-10 16:45         ` Tom Zanussi
2022-03-10 17:07           ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox