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 X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BACEAC06510 for ; Tue, 2 Jul 2019 11:07:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9843820836 for ; Tue, 2 Jul 2019 11:07:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726544AbfGBLHs (ORCPT ); Tue, 2 Jul 2019 07:07:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57818 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725774AbfGBLHs (ORCPT ); Tue, 2 Jul 2019 07:07:48 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E79EA120D7; Tue, 2 Jul 2019 11:07:38 +0000 (UTC) Received: from krava (unknown [10.43.17.81]) by smtp.corp.redhat.com (Postfix) with SMTP id 2AB116F921; Tue, 2 Jul 2019 11:07:29 +0000 (UTC) Date: Tue, 2 Jul 2019 13:07:28 +0200 From: Jiri Olsa To: Leo Yan Cc: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , 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 Subject: Re: [PATCH v1 06/11] perf hists: Smatch: Fix potential NULL pointer dereference Message-ID: <20190702110728.GA15322@krava> References: <20190702103420.27540-1-leo.yan@linaro.org> <20190702103420.27540-7-leo.yan@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190702103420.27540-7-leo.yan@linaro.org> User-Agent: Mutt/1.12.0 (2019-05-25) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 02 Jul 2019 11:07:48 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 02, 2019 at 06:34:15PM +0800, Leo Yan wrote: > 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(-) > > 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: { not sure this can really happen, perhaps WARN_ON_ONCE(!hbt) would be good in here jirka > u64 nr_entries; > - hbt->timer(hbt->arg); > + > + if (hbt) > + hbt->timer(hbt->arg); > > if (hist_browser__has_filter(browser) || > symbol_conf.report_hierarchy) SNIP