From patchwork Tue Jul 2 10:34:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168306 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4072679ilk; Tue, 2 Jul 2019 03:35:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqzcuXgfeL23xPMwlRS18rfwwHEXBfW9D0mfR7oKjErTr7iujW5rJb44tskfoOydDHT4eQQ3 X-Received: by 2002:a17:902:7041:: with SMTP id h1mr34451453plt.133.1562063745290; Tue, 02 Jul 2019 03:35:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063745; cv=none; d=google.com; s=arc-20160816; b=0/QM3dEy2KTxMmCStpok8WZqkYTcnhN7F48jgt7mU1FVlEVqZNCJjEPyoRaFK4XpNS JToR74PHidme73K15ZznsuZwPstuWj1N4S4c2LLa2Z+kWfKNzPcHvkORYMiUDJlpjbNI kSLKeSvtrxjCOyXxL1PuE4XoTWMnZ+hPhnr/EMF7OuRNAi5Me0t9lHU1vm7VuXwMi00L FWAQc57HdsAloR51fmy70T1zCdiWT1hHHSWtUxhOMdsDET0kilw+K0RavZb9tKR5AIkI 0+QnrfKoHl4j2zwnZTtHijl7dKSH1AzcILsHcF/yFlKwHBtcb49hRMpyZ/PC0Szl4cM4 AE+g== 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=pR8OnU6ONKK8WXaF3q0PWRqZRj/gofETqCh57U/9pps=; b=lXLo6WGPInZwJPsfPsp90l/IB2GAd+bOp+6b6ipkYY3p7UFlzxcBXPYRBEOEDqXMSz ig5OIEOPmrWhrrulJqlurvkuZG/7JNppgZx4puu+GmbcvYkb4pU4P/5PE5688WO0uQGc zs4VNq0qS5u1RIVQUkIZg473Nw3vrOLJHm/OlAJFdqbEwTj69M7FnVf5EL9JWgGbeifa bBHxZOBKeoV+hdkFhIASpi/i9WmPO4lTB2mpkXsf/YmkBZ5zM26ZLlHScjnWI25Zv/dc IKpphcVk8CVJHK5DpjeVMroS5q72ijbbrcDFJ/eY78R3eXS8j7PLeODou0BOn79GpXRy LCyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gqUYj3Rg; 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 j23si12421035pll.214.2019.07.02.03.35.45; Tue, 02 Jul 2019 03:35:45 -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=gqUYj3Rg; 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 S1727294AbfGBKff (ORCPT + 30 others); Tue, 2 Jul 2019 06:35:35 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:43245 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKfe (ORCPT ); Tue, 2 Jul 2019 06:35:34 -0400 Received: by mail-ot1-f66.google.com with SMTP id q10so6705019otk.10 for ; Tue, 02 Jul 2019 03:35:34 -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=pR8OnU6ONKK8WXaF3q0PWRqZRj/gofETqCh57U/9pps=; b=gqUYj3RgcmbrGaA8NafweIqkT9dOdE8BbJZXI+ANioWM70cMuoNl7wgH8y7qyORqBP MrOo4umrodn+Q4qIgwxpFIBLrCit6U2wXsumMe5NX/NcBUN98yGQQgw5PDFKzGdWeAif T0HaRSKYOBlDUWYerXzXCwcJBErDmF66NK3NbzTASZBFJfCZTf681g3c3MMx3MB6Sj2z aiyeEui7Vl/tIxL9w8C53Q0o0E1fB5HdJ/7bmX1l7kvUuRXM4DO2+jhbXtB8R9UU3z2S 68owNLcHSQeyp9OTm7P/ivHJg0HXEtVBw1yBkFt+UMw4KPPPxrzs/dm6pvWXMIepPWjA dwgA== 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=pR8OnU6ONKK8WXaF3q0PWRqZRj/gofETqCh57U/9pps=; b=ROuWLk4Fou3bNl6rXd9PTI5WRz7RznvmkLgjkuCKz5zPXsMCAwaJgiml1u7xTqT+bV 1jPl9uqyh7Ta9ZB5MH1BBks81MBr2FIsZw75/P2BveWkhhy3+pSCMNbvYt4DKPhYo835 F6nKTPFrI6O+Uzq52YHLXygxWM4TTo6aoBMjVig0j/WKBtFDH2jekiQnYbpKHsxsFXfC BSeP3Wk8ETany5ko73OUDEK9/SoSfjfqC+//B3oEX/FieTa+3vJeN0xwbb5Aak9GENGn Gh2sVo9oDG5LlqkP6wDi0djJKJLGF0oj/HNNymuUcbmUu1df/dVAlWupvNs9fdgIaoyW 7sww== X-Gm-Message-State: APjAAAWD1Fnw7bbhdubHAcSmso7FMB+7U03vn1zTXWCMH+bITfIPqsWo KipJo2pfp+xzBuCWg/ccZl1/lg== X-Received: by 2002:a05:6830:14c:: with SMTP id j12mr22891677otp.181.1562063733986; Tue, 02 Jul 2019 03:35:33 -0700 (PDT) Received: from localhost.localdomain (li964-79.members.linode.com. [45.33.10.79]) by smtp.gmail.com with ESMTPSA id 61sm5139805otx.8.2019.07.02.03.35.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:35:33 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , Andi Kleen , "David S. Miller" , Davidlohr Bueso , Rasmus Villemoes , Jin Yao , Song Liu , Adrian Hunter , Alexios Zavras , Thomas Gleixner , Changbin Du , Eric Saint-Etienne , Konstantin Khlebnikov , Thomas Richter , Alexey Budankov , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v1 06/11] perf hists: Smatch: Fix potential NULL pointer dereference Date: Tue, 2 Jul 2019 18:34:15 +0800 Message-Id: <20190702103420.27540-7-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190702103420.27540-1-leo.yan@linaro.org> References: <20190702103420.27540-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/ui/browsers/hists.c:641 hist_browser__run() error: we previously assumed 'hbt' could be null (see line 625) tools/perf/ui/browsers/hists.c:3088 perf_evsel__hists_browse() error: we previously assumed 'browser->he_selection' could be null (see line 2902) tools/perf/ui/browsers/hists.c:3272 perf_evsel_menu__run() error: we previously assumed 'hbt' could be null (see line 3260) This patch firstly validating the pointers before access them, so can fix potential NULL pointer dereference. Signed-off-by: Leo Yan --- tools/perf/ui/browsers/hists.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 3421ecbdd3f0..2ba33040ddd8 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -638,7 +638,9 @@ int hist_browser__run(struct hist_browser *browser, const char *help, switch (key) { case K_TIMER: { u64 nr_entries; - hbt->timer(hbt->arg); + + if (hbt) + hbt->timer(hbt->arg); if (hist_browser__has_filter(browser) || symbol_conf.report_hierarchy) @@ -2819,7 +2821,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, { struct hists *hists = evsel__hists(evsel); struct hist_browser *browser = perf_evsel_browser__new(evsel, hbt, env, annotation_opts); - struct branch_info *bi; + struct branch_info *bi = NULL; #define MAX_OPTIONS 16 char *options[MAX_OPTIONS]; struct popup_action actions[MAX_OPTIONS]; @@ -3085,7 +3087,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, goto skip_annotation; if (sort__mode == SORT_MODE__BRANCH) { - bi = browser->he_selection->branch_info; + + if (browser->he_selection) + bi = browser->he_selection->branch_info; if (bi == NULL) goto skip_annotation; @@ -3269,7 +3273,8 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu, switch (key) { case K_TIMER: - hbt->timer(hbt->arg); + if (hbt) + hbt->timer(hbt->arg); if (!menu->lost_events_warned && menu->lost_events &&