Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755238AbeAHDN3 (ORCPT + 1 other); Sun, 7 Jan 2018 22:13:29 -0500 Received: from mga04.intel.com ([192.55.52.120]:59021 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755158AbeAHDN0 (ORCPT ); Sun, 7 Jan 2018 22:13:26 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,329,1511856000"; d="scan'208";a="17464639" Date: Mon, 8 Jan 2018 11:05:12 +0800 From: "Du, Changbin" To: jolsa@redhat.com Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, alexander.shishkin@linux.intel.com, jolsa@redhat.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, changbin.du@intel.com Subject: Re: [PATCH] perf ftrace: Fix the buffer size in __write_tracing_file Message-ID: <20180108030512.begv5uoo66kh5biu@intel.com> References: <1514280416-29659-1-git-send-email-changbin.du@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1514280416-29659-1-git-send-email-changbin.du@intel.com> User-Agent: NeoMutt/20171027-42-ad8712 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Hi Olsa, What about this fix now? Thanks! On Tue, Dec 26, 2017 at 05:26:56PM +0800, changbin.du@intel.com wrote: > From: Changbin Du > > The terminal character '\0' should take into account as size of the string > buffer. Without this fix, the '--graph-funcs', '--nograph-funcs' and > '--trace-funcs' options didn't work as expected when the doesn't > exist. > > I didn't dive into kernel ftrace fops, but strace shows that if usersapce > writes a non-terminated string, the kernel side will return success but > no filter applied. After this fix in userspace, the kernel will return an > error. > > $ sudo ./perf ftrace -a --graph-depth 1 --graph-funcs abcdefg > 0) 0.140 us | rcu_all_qs(); > 3) 0.304 us | mutex_unlock(); > 0) 0.153 us | find_vma(); > 3) 0.088 us | __fsnotify_parent(); > 0) 6.145 us | handle_mm_fault(); > 3) 0.089 us | fsnotify(); > 3) 0.161 us | __sb_end_write(); > 3) 0.710 us | SyS_close(); > 3) 7.848 us | exit_to_usermode_loop(); > > On above example, I specified function filter 'abcdefg' but all functions > are enabled. > > Signed-off-by: Changbin Du > --- > tools/perf/builtin-ftrace.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c > index 25a42ac..2604a64 100644 > --- a/tools/perf/builtin-ftrace.c > +++ b/tools/perf/builtin-ftrace.c > @@ -69,7 +69,7 @@ static int __write_tracing_file(const char *name, const char *val, bool append) > { > char *file; > int fd, ret = -1; > - ssize_t size = strlen(val); > + ssize_t size = strlen(val) + 1; > int flags = O_WRONLY; > char errbuf[512]; > > -- > 2.7.4 > -- Thanks, Changbin Du