Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4131498ybi; Mon, 29 Jul 2019 19:57:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxWRhDChc62t3pa4i0cg7H9beA5Rrpn79eca/D71H21vW7G8XXm+ozbpE1hH5e6XDp2P4i X-Received: by 2002:a17:90a:33c4:: with SMTP id n62mr118007636pjb.28.1564455455403; Mon, 29 Jul 2019 19:57:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564455455; cv=none; d=google.com; s=arc-20160816; b=DCRmvpCzo7J+yvVVoUm5OnmuJ1wjAnb75ch56028SQuKbgF6BTsndHbnVLh66BdyRn HjaBU5E1af9e6nVAK70kx+EZMkZzE4aHfQvf9gmKl2qZedpT5XRAZGfscH8RUrzJxKr6 HJmrb5RDjRg3OfmFCK1GY6x3vRmtRavlf6Btjw3zMqGqdsB0f2q0F9V/ALbGpXPNZq8/ Vd2/W11KnjBpoN4/ppROuSDZVvp/IEO+M14lSaHQciLzLp3pGMtrebPeq1gAvc70n2ej sWYxVGsaTxPTWi0vl9XzxyX/HCgxwDGAfPf9SOz/M9YYygID5jg3d2BQdiq6aIIo8lqj ZR8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=emOUUKaCGeTaIq6AdxvaTA0NHtyL3SZc2xkDpp+2Mkg=; b=nJZrNzk5pOnl7oFjiiosmYiTm/Ec4IzHog7VYGm4wYKfBz+ZRLVUQSC3rRp07I9vo6 Tbw14Mr3eDqh+mFXZoqiGqiPVw1nSoXUERwabS9qtkaKoF9/KgF3L0SapuFPUVbdpaM2 laaUNlj6ssm2IlJf0GUi4Q3ImCuFsHbK88M/SQCVCFbHHwAAJei8QVHAzFJ2HiymEG5Y C5W1cW82P7MOb0ZQoNwCuJbR3RRe7iMthQq9wrqm4KZO8FP0ioHfuqiAhBU/mzpiYlVc XBvdTbnSg5GeY++pC7TfSxo5uktKna/oRtJ08QvP49yzPVSoiPp+BmrTQee5twfP4hju KajA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=niOPKhOD; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t63si27297505pfb.5.2019.07.29.19.57.09; Mon, 29 Jul 2019 19:57:35 -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=@kernel.org header.s=default header.b=niOPKhOD; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390742AbfG2Tv2 (ORCPT + 99 others); Mon, 29 Jul 2019 15:51:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:42810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390323AbfG2TvZ (ORCPT ); Mon, 29 Jul 2019 15:51:25 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ABAD5204EC; Mon, 29 Jul 2019 19:51:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429884; bh=W4f+4kcCzQ7z4a9XB5Ogvkgum4ZPKLa+1Xmiyn6CcVs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=niOPKhOD9czv3UF15ApKXKN7sQF7SabC46WtX0geTxaxP9QOYO9UbkJP9Ui+1Xybm YCthOE5oAPfTdWS+ngYOLcygh0x2wPyk44TLQo3b57psAZudp1MypR820dh8ZcsA1N dEFmd4ByPe9EK4hgadCvGUfT6O+cRr94fEdB+uJ8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leo Yan , Jiri Olsa , Adrian Hunter , Alexander Shishkin , Andi Kleen , Mathieu Poirier , Namhyung Kim , Suzuki Poulouse , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.2 127/215] perf hists browser: Fix potential NULL pointer dereference found by the smatch tool Date: Mon, 29 Jul 2019 21:22:03 +0200 Message-Id: <20190729190801.372399577@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit ceb75476db1617a88cc29b09839acacb69aa076e ] 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 Acked-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: Mathieu Poirier Cc: Namhyung Kim Cc: Suzuki Poulouse Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190708143937.7722-2-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/ui/browsers/hists.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 3421ecbdd3f0..c1dd9b54dc6e 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -638,7 +638,11 @@ int hist_browser__run(struct hist_browser *browser, const char *help, switch (key) { case K_TIMER: { u64 nr_entries; - hbt->timer(hbt->arg); + + WARN_ON_ONCE(!hbt); + + if (hbt) + hbt->timer(hbt->arg); if (hist_browser__has_filter(browser) || symbol_conf.report_hierarchy) @@ -2819,7 +2823,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 +3089,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 +3275,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 && -- 2.20.1