From: Steven Rostedt <rostedt@goodmis.org>
To: Tom Zanussi <zanussi@kernel.org>
Cc: kernel test robot <lkp@intel.com>,
kbuild-all@lists.01.org,
Linux Memory Management List <linux-mm@kvack.org>
Subject: 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
Date: Thu, 10 Mar 2022 12:07:47 -0500 [thread overview]
Message-ID: <20220310120747.7185d84c@gandalf.local.home> (raw)
In-Reply-To: <cda9ea3f11e5981964794eab8700cbe2b8032902.camel@kernel.org>
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)
prev parent reply other threads:[~2022-03-10 17:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-09 15:48 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 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=20220310120747.7185d84c@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=kbuild-all@lists.01.org \
--cc=linux-mm@kvack.org \
--cc=lkp@intel.com \
--cc=zanussi@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