From patchwork Mon Jun 17 09:11:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 166979 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2605388ilk; Mon, 17 Jun 2019 02:12:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwYEXYlR27o08DF8+aYK+Ym11Y0V0yHQzLCrMQGO+6OL0IWcKfby7mEiRIBtoJGCUnDICrN X-Received: by 2002:a17:902:7083:: with SMTP id z3mr42287794plk.205.1560762728894; Mon, 17 Jun 2019 02:12:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560762728; cv=none; d=google.com; s=arc-20160816; b=RJnl1xseD8vCaPao4GLW3UugWNrrixLtwjaPCH6GbUw5sbatWVZ0vb34kR8t+LOKS3 wjwjzxYotXV6RREZtqEec0MSF7gw5+Vn1PeXHfm7o55hh21eLkZZ+c6VuDhpw475FXoR 9LIirAIKZdal1IIiy4WCuPf9ytOIkETjUBfiS+b1mJvPDof/nyTCLO3FAyWoTCbzYbXu uaUh/SK4vKSOfQwlIqnkRqZp4hi5OEpeBt58EkaiJPOcaLc8dMzX8l3WflK25AWiQVbK XC1OyysH8srYbCVcDa11NqvMrG/zqa8DVvGrz6+UdR7thZee+8fWFnDN5gbsCbWw+IoD 9b8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=oZAaOCoJj5x4sDBNqZQb5CRUWvcKQL64QGOvdU8EjU4=; b=Fe0VUSofqwKXEqxwzAYR7LXNaycwNXm9UYNRw/5TWKrepcnIEiWr0fbfcng48dPMXo uiu+sQ4HpXjWZIQF3uS385Rv16PbMP3kWsXefCJr244awTyS0MEraMw1e30JxM2SfiaU GrsnYFrqcmRbo78lHGKX7U02r2L3wTLD6NZmD8wTxZnFRX2XfIofTfyzQwgEQL/gULhZ fphh3a9per07ZzNqqdyhEqryWN/1ynIkP541EtdVRU+SEEVwJ4bjB4BhoJHga+aPUZI9 2w4R/kWCeNeoklyJMSR0V6DsrpdqVqvvin9sJC0QYymr18FOWj1l06XTXiFQkRS7sov+ TSfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="QR/zCNgV"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i1si10671181pgn.193.2019.06.17.02.12.08; Mon, 17 Jun 2019 02:12:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="QR/zCNgV"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728043AbfFQJMH (ORCPT + 26 others); Mon, 17 Jun 2019 05:12:07 -0400 Received: from mail-oi1-f194.google.com ([209.85.167.194]:36092 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727952AbfFQJMG (ORCPT ); Mon, 17 Jun 2019 05:12:06 -0400 Received: by mail-oi1-f194.google.com with SMTP id w7so6492707oic.3 for ; Mon, 17 Jun 2019 02:12:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=oZAaOCoJj5x4sDBNqZQb5CRUWvcKQL64QGOvdU8EjU4=; b=QR/zCNgVHHN5LeDILxIyEF49A0+54vewuBaVy2cgPGVk8oEINFWT7v77TpCagykcA9 sZtuMn2DGpqTyvZ4T46gz41Zqq9tSi0sR0XX/jm0xoLs6BlL8yS83yr5bwTUP/ZhXFFe APrXumCbSdT91yp1/Be6n4CnzCRDmCo5Mn6FSe/9mZb91Xur++zomVFwRzDqewFAqKxj YPyNnS2f6z5mV+A7dVWTEMCm82AJiM/GK0uCt8RMX6ekyDVhr+OB78o/BwVy7y656DY/ YYI/DJvQ5lf4RZfQnDL+tbi3h+tvy+3/pY9ZEhcuHpoJzG0vTEumIjPZbIPMzjPBpn3B 88iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oZAaOCoJj5x4sDBNqZQb5CRUWvcKQL64QGOvdU8EjU4=; b=r+/DNTsYm1qBPf3kJIL9KWjuLPDHVBuxfVns3KqtmhBmUlhF4O93xeq/ylt7Y7fw0n 95m97Xf7xB36dRrNaJWvA2DPKuQKmV2XnZ+mDcNr1xTwHyCKNwYqG5rMkbnRvFXodatw U1ZyMaCBRZMnwnkXGsAX9XFgzBjWhnPVuFxsf+Qi/O5mwKMaKrA3IiJI5/SStFmHyg1q D1nArwwsugaL/hWEqNrbw3xs413nTl8BRTERsU5yCD7wYjPofYxxzlxMmZnfYCCG1F0Z +JnFQXCXsZlio//HfqaVA8yqURI9Vtq/TBkSiYb1FhlWmZ3zqzVTQNwACyVfCAtBgGNC +GpQ== X-Gm-Message-State: APjAAAXtqQABI2UBwnd0Y/2KMJQfOUZQZJf3XiAE86Ke7XzxM4MaAawM EHsLoLtI5VT95zhPxRwR0RTclw== X-Received: by 2002:aca:aa95:: with SMTP id t143mr10189295oie.22.1560762725883; Mon, 17 Jun 2019 02:12:05 -0700 (PDT) Received: from localhost.localdomain (li964-79.members.linode.com. [45.33.10.79]) by smtp.gmail.com with ESMTPSA id l145sm4418324oib.6.2019.06.17.02.12.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jun 2019 02:12:05 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Leo Yan Subject: [PATCH 1/2] perf trace: Use pr_debug() instead of fprintf() for logging Date: Mon, 17 Jun 2019 17:11:39 +0800 Message-Id: <20190617091140.24372-1-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the function trace__syscall_info(), it explicitly checks verbose level and print out log with fprintf(). Actually, we can use pr_debug() to do the same thing for debug logging. This patch uses pr_debug() instead of fprintf() for debug logging; it includes a minor fixing for 'space before tab in indent', which dismisses git warning when apply it. Signed-off-by: Leo Yan --- tools/perf/builtin-trace.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) -- 2.17.1 diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index bd1f00e7a2eb..5cd74651db4c 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1760,12 +1760,11 @@ static struct syscall *trace__syscall_info(struct trace *trace, * grep "NR -1 " /t/trace_pipe * * After generating some load on the machine. - */ - if (verbose > 1) { - static u64 n; - fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n", - id, perf_evsel__name(evsel), ++n); - } + */ + static u64 n; + + pr_debug("Invalid syscall %d id, skipping (%s, %" PRIu64 ")\n", + id, perf_evsel__name(evsel), ++n); return NULL; } @@ -1779,12 +1778,10 @@ static struct syscall *trace__syscall_info(struct trace *trace, return &trace->syscalls.table[id]; out_cant_read: - if (verbose > 0) { - fprintf(trace->output, "Problems reading syscall %d", id); - if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL) - fprintf(trace->output, "(%s)", trace->syscalls.table[id].name); - fputs(" information\n", trace->output); - } + pr_debug("Problems reading syscall %d", id); + if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL) + pr_debug("(%s)", trace->syscalls.table[id].name); + pr_debug(" information\n"); return NULL; } From patchwork Mon Jun 17 09:11:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 166980 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2605503ilk; Mon, 17 Jun 2019 02:12:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqxiCfpSElid3JuzT3BHzBXeYWxtSRWSooUJgq873s1K0HxqnCEwas85cweX4cwnJA63Useg X-Received: by 2002:a63:2b92:: with SMTP id r140mr48822069pgr.363.1560762736208; Mon, 17 Jun 2019 02:12:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560762736; cv=none; d=google.com; s=arc-20160816; b=iQfH7DwAlPrBC34BWY9blUCzqSmEK+u3TXpxeGWJOHIEGN9mJ1aqiLTO6YAT82QKsN HyPbLI1b8KVdMXWToGYAHrqfAZxvTsxO8XRdupIt2C8PLs5gYZ5A2lNSdXte2m6G7rBi BeDHaF6Ba7wJJXQ4HzNYVJJIENvp41f6elNBnBjf3mNNxu8kZFzC7kklcv9mOlgc7V9E +bgBR8nD47MDhC9Obw3sLiDdQELi+HBatfiuM0qFlXADulNj3+z0MWLBfMb8VZranLg+ OqLdhLffjCtfHaAcgOMTusYGaWK92osXtskjGyyFWLmr4+gWJw4hLKvsOYl6Q3fhddaQ +MXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=XkQKkEqj0Dk+yMwwMUT9kq+YcOABBfUMfQA+OLQkIhs=; b=I4xgCO7ZXOpY3v4UJxpqGElmujHwP16DERq4UPSWuFc2eebXStibdqrXnnGpCe0chH TJNDS2tE4OH5sH3Nqu8SHeGCddTRPugv78Pz4Ys70jscWQwqLC/BGRfmZwS7feMilCJG 8a52RzU7hgTD2ldNOD+HqTAaCon46PCOEOUht+XZk8r7pi1LM7CuinyJR6ulLUdiUZgm MItbt2CXRjvBKIlhRWDQiGqBHhrmXQE8CP0dwQVixmoWmstsTxFYEsMSQ/oT/KMXchVV I9HtmY4HcfB2nlxDZmJbg7z6Bft5AUi/MFNhixh6HY9MOtwVVZA5JJv+BzULNeyADsAN Mzow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A97y2r8a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d191si10009852pgc.460.2019.06.17.02.12.15; Mon, 17 Jun 2019 02:12:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A97y2r8a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728070AbfFQJMN (ORCPT + 26 others); Mon, 17 Jun 2019 05:12:13 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:46014 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726753AbfFQJMM (ORCPT ); Mon, 17 Jun 2019 05:12:12 -0400 Received: by mail-ot1-f66.google.com with SMTP id x21so8543789otq.12 for ; Mon, 17 Jun 2019 02:12:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XkQKkEqj0Dk+yMwwMUT9kq+YcOABBfUMfQA+OLQkIhs=; b=A97y2r8a4SElnnqWxEgYt9hqzUlV/cOq2E2WwDSEdCBsMl4m9cFtY2fwwCpdvcakGW awt+SV7bLv8nxXRVmEnrNMG5nFwayb31HFNIpLayWLPTVlHkQNzKb7SuHGb/q/kFN1iG KVV5NavH8nIx9y83mXraGlVjJ8aelPhg8mONarGKKwUmLvP7zgFt9KexSKptxXiLGBtB AghmJ9J5muwb89JeCF2VbT9c8bxFbPOzohfyudUTv0h+bt9tmpFijVpS7R1W1toW/CwL o9HaBfx9fAnEFi8vjuByIGu5qiqhE5bzRO7ym7pfTmOyYah4LXxvPFkfhV2bB4XvMmBB qZjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XkQKkEqj0Dk+yMwwMUT9kq+YcOABBfUMfQA+OLQkIhs=; b=Zv17fUOqDrR5uXhzs1TPTcIAeuc4glU91hCBkm94dS70PmgChUkz60VvuLMTqZhpJS +XprgPQkPfszf8lmenkzYwIjGJf7Hy1+SRp9GGo9JrNZWj8cXD4aUmVUdnh69Roz4qtd 8U8MRVyTk1NgzSc01EhKuPwpDfN9T3girYQZPTudILsyNC1hzsxWjvzsS5mknLGeuhlL B1dwmWH9xZsCLTTg35iQKyg+mA4nGn6D5sBRwCDo4gbPvf1uh9uuwGVwRC62ZiVyw0HO CeWiju+B997MWnyLIBGneD/03rbsMrCq3o1Xeosam3hVRDCvsFOaxwVQ4N03GCd93aen 2g3Q== X-Gm-Message-State: APjAAAXTtiimRw6sN647JorYjGNJsvsmx6oozGmplZgzj+Qc8eQ4fID4 l3Jj2gUjSISUGrViQGgu9WRVGA== X-Received: by 2002:a9d:4b88:: with SMTP id k8mr61017358otf.285.1560762731712; Mon, 17 Jun 2019 02:12:11 -0700 (PDT) Received: from localhost.localdomain (li964-79.members.linode.com. [45.33.10.79]) by smtp.gmail.com with ESMTPSA id l145sm4418324oib.6.2019.06.17.02.12.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jun 2019 02:12:11 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Leo Yan Subject: [PATCH 2/2] perf trace: Handle NULL pointer dereference in trace__syscall_info() Date: Mon, 17 Jun 2019 17:11:40 +0800 Message-Id: <20190617091140.24372-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190617091140.24372-1-leo.yan@linaro.org> References: <20190617091140.24372-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org trace__init_bpf_map_syscall_args() invokes trace__syscall_info() to retrieve system calls information, it always passes NULL for 'evsel' argument; when id is an invalid value then the logging will try to output event name, this triggers NULL pointer dereference. This patch directly uses string "unknown" for event name when 'evsel' is NULL pointer. Signed-off-by: Leo Yan --- tools/perf/builtin-trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.1 diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 5cd74651db4c..49dfb2fd393b 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1764,7 +1764,7 @@ static struct syscall *trace__syscall_info(struct trace *trace, static u64 n; pr_debug("Invalid syscall %d id, skipping (%s, %" PRIu64 ")\n", - id, perf_evsel__name(evsel), ++n); + id, evsel ? perf_evsel__name(evsel) : "unknown", ++n); return NULL; }