From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10817C433EF for ; Thu, 10 Mar 2022 17:07:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E7898D0002; Thu, 10 Mar 2022 12:07:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 596608D0001; Thu, 10 Mar 2022 12:07:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45DFD8D0002; Thu, 10 Mar 2022 12:07:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id 35FE08D0001 for ; Thu, 10 Mar 2022 12:07:53 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E7E749AC9C for ; Thu, 10 Mar 2022 17:07:52 +0000 (UTC) X-FDA: 79229108784.27.357B70E Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf07.hostedemail.com (Postfix) with ESMTP id 2E78740017 for ; Thu, 10 Mar 2022 17:07:51 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A59DDB826C1; Thu, 10 Mar 2022 17:07:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E250C340E8; Thu, 10 Mar 2022 17:07:48 +0000 (UTC) Date: Thu, 10 Mar 2022 12:07:47 -0500 From: Steven Rostedt To: Tom Zanussi Cc: kernel test robot , kbuild-all@lists.01.org, Linux Memory Management List 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 Message-ID: <20220310120747.7185d84c@gandalf.local.home> In-Reply-To: References: <202203092349.i2I1pdlw-lkp@intel.com> <93bb0a79331882df8ce2bf704b3d4ac28c8cbc3d.camel@kernel.org> <20220310104951.60d0adb6@gandalf.local.home> <93ac51c2b0aa9d5a3777bce935990d7b9da176f4.camel@kernel.org> <20220310112641.2b42fd54@gandalf.local.home> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 2E78740017 X-Stat-Signature: f5o7hxmsfpthf697xebhqdjzsxn71ax4 X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf07.hostedemail.com: domain of "SRS0=xcyr=TV=goodmis.org=rostedt@kernel.org" designates 145.40.68.75 as permitted sender) smtp.mailfrom="SRS0=xcyr=TV=goodmis.org=rostedt@kernel.org" X-Rspamd-Server: rspam03 X-HE-Tag: 1646932071-167934 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, 10 Mar 2022 10:45:09 -0600 Tom Zanussi wrote: > On Thu, 2022-03-10 at 11:26 -0500, Steven Rostedt wrote: > > On Thu, 10 Mar 2022 10:08:18 -0600 > > Tom Zanussi 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 > 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 > Signed-off-by: Tom Zanussi > --- > 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)