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 28986C433F5 for ; Thu, 10 Mar 2022 16:45:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 783C28D0002; Thu, 10 Mar 2022 11:45:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 70BD58D0001; Thu, 10 Mar 2022 11:45:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5ACE78D0002; Thu, 10 Mar 2022 11:45:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 48BCD8D0001 for ; Thu, 10 Mar 2022 11:45:15 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1348E2163A for ; Thu, 10 Mar 2022 16:45:15 +0000 (UTC) X-FDA: 79229051790.05.10EF0D0 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf23.hostedemail.com (Postfix) with ESMTP id 5E7D2140020 for ; Thu, 10 Mar 2022 16:45:14 +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 0F86AB82670; Thu, 10 Mar 2022 16:45:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54FAEC340E8; Thu, 10 Mar 2022 16:45:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646930711; bh=xO4m75V402aIyiHep8f3Lakqkf0SttalFcS/mDAJ1Mc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=a9mKnkeMCmQaRib3eC+ohUOAw6dF8i3COUsCTqpogdg3V56moJH0Mo7nDkXVU5Fgj VYMo0HPvLNgdEUwkkO50LG7V5t2mxVTRiTV3lXR49m7CHfE9LVDbSH890jEIjN7F/t W4Xx8eBcMGiW57p95ybwrz3LgziLYMFxxgIUOMPx22/4AaXIwUCOu05+iVvNWzUVqL rnLYC48mohSxHOWDeOkwp9IM+2kgN6ZitcCwQKZOJALwoB1HJDNphKZi6zF5jwlqjc Sx3QJDFTX4Nq21TmXGkSbM4wjOmcCwAAFjzQsZLybfR87NkK8DnFImnghriNIdHuQx 7qMlyv+5sQ2uw== Message-ID: 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 From: Tom Zanussi To: Steven Rostedt Cc: kernel test robot , kbuild-all@lists.01.org, Linux Memory Management List Date: Thu, 10 Mar 2022 10:45:09 -0600 In-Reply-To: <20220310112641.2b42fd54@gandalf.local.home> References: <202203092349.i2I1pdlw-lkp@intel.com> <93bb0a79331882df8ce2bf704b3d4ac28c8cbc3d.camel@kernel.org> <20220310104951.60d0adb6@gandalf.local.home> <93ac51c2b0aa9d5a3777bce935990d7b9da176f4.camel@kernel.org> <20220310112641.2b42fd54@gandalf.local.home> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5E7D2140020 X-Stat-Signature: hrwhr63swaxp4cbxwe3rx6jw6kt93ptt Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=a9mKnkeM; spf=pass (imf23.hostedemail.com: domain of zanussi@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=zanussi@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-HE-Tag: 1646930714-904973 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, 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: ../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) -- 2.17.1