Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3795236ybi; Mon, 29 Jul 2019 12:46:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAFmyALrgZxJSCK4VSl9caWQdCA5cHSenptbrJawi/LX1DRpLdwQnQxCvGz16xzPbPOWjY X-Received: by 2002:a17:902:9a07:: with SMTP id v7mr4087210plp.245.1564429600518; Mon, 29 Jul 2019 12:46:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429600; cv=none; d=google.com; s=arc-20160816; b=r4OUJAQFSRaRua4Eq0wytxJ/diRHbvhLRnZDvx3khcMJ5AdID8i7UtqPlqoNIj5s3l JOZ/jDENCsmzJ2urT6Etx23HjvF/sZCq3zJh8hhRg0nzr31/TbS2hNKbd5j0UFzp6YBF dXXfhA9ZsdtUCxTkToyoqmsZlkJ9JtaiqcjnzF9riS+hIiEoQaPlrbyfzUn6fcMhpT24 Wam7e33M5KnCUsCBn9vsvB6FVjmyXTwI+cZWGxCTPnhCijNVmz5Ytbl8TnTXOf9v97oK qpsAggd6GdpcHjsjA7CvDbmOSDf4hMKfxBsQe8QxFtq0QW/IUuYZoE/HUX+zGfkW1OIs RXHw== 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=c/pjlD1GorsxEUMa7uX+8FJ5oqlZAg8m2imQlbglNFQ=; b=D6CZGAkaPPSi/N8RnvKra4UfdhEK+/tONHWB7TgtE4EsCxGUiJUQBKmsA5zSOb7TiR gS4a3xjVbkoriD3L5iRUwxV7VGyp4hcPqKoJ5TvdZffE00Q21g1pEg178VkhIWEMJseL +ViqgHfUc4rQmKCd6GJJaaq5BQ22IBunrQjw3kwM2nHqBxuCKjfEOiuTuFDakrSJUuid YTJeHYse2vrQbDuCOX6MfMYu8nCJzkucjYK49IuVPx8nXim7X5TZ7Lnmf88uJbMQz24F ODrf4M/Ebi6hGDPs6xMWYeHwfTYOHrtNeWA2bidBzCBE974wVvDENmbVn5xaBIBMOuDE O0lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jim7EQWM; 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 e5si11392768pgl.536.2019.07.29.12.46.25; Mon, 29 Jul 2019 12:46:40 -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=jim7EQWM; 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 S2389615AbfG2TpR (ORCPT + 99 others); Mon, 29 Jul 2019 15:45:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:33984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389899AbfG2TpM (ORCPT ); Mon, 29 Jul 2019 15:45:12 -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 E3BFC2054F; Mon, 29 Jul 2019 19:45:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429511; bh=NfgZ0V/VlJYE29DGNuK3YYHUhOGyFNa1Qcljxa/Qb0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jim7EQWMNNczEdOma/IHEHiC6u6ZPKLnbj+k/gXsNKHkDi10/4/h5PHIt9z+t5non oHLE9BBRHjfZy1C0eXjrYKQPQWDvAIKSDJbNd1G2Q8HPgaKFZq+jmUkMxvEeLBLoCu TDaVXBGHrCmcIaaObxqBneK/6+jfOhFu3tKZ6cWo= 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 4.19 072/113] perf hists browser: Fix potential NULL pointer dereference found by the smatch tool Date: Mon, 29 Jul 2019 21:22:39 +0200 Message-Id: <20190729190712.702228564@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190655.455345569@linuxfoundation.org> References: <20190729190655.455345569@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 a96f62ca984a..692d2fa31c35 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -633,7 +633,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) @@ -2707,7 +2711,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]; @@ -2973,7 +2977,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; @@ -3144,7 +3150,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