From patchwork Mon Jul 8 14:39:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168656 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp7252485ilk; Mon, 8 Jul 2019 07:40:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzyFf6YEwQkXj83haG79g3OPHeMoz0EZwmO+V0oval+eS39IeJ0NKiEENZqiJOrB8oB8xvF X-Received: by 2002:a17:902:b20d:: with SMTP id t13mr24165697plr.229.1562596807424; Mon, 08 Jul 2019 07:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562596807; cv=none; d=google.com; s=arc-20160816; b=tlsePDE7AoKYpcjRzNSXBXufSF0gDa+xZ2i3OzTHXvT9vYhrpqj+A2ijg9N8MZN0sy ma+ISxzJVO18Nam0Rv2u23O/I1YSP7hWi9OuLGeIANQdTLzUWHH3khtg6ZjjfW0P91Tt vuxQAgfabiCImJWDWd/dSbOz0MfZAwkiXtgZZO8meqgmoEI35Z/zq83uYhfmsM8hgzR4 vNEhInecYLyZ8xXk60uBD2hLzE3RdZjxMTwXt5McNSD3X8CpYv8PcsRY27SdnUxwcMcA nU+6C21TLjAzVuq4s/Dr9IuKBU7aFSdgkoIgb9uW0o6XTswwFJ64uLvu5I3Tl72XETkN i0HQ== 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=J3hRcly8D1YDeUmF8zVR4I01GOuIVsuQo8ZUqHIaHHQ=; b=p9b5Hm1lmajmAQjk4Y6qtF0BfbS8moegLOkDmG+l81JqjB/QpNeoQOE0DoHaFSrG4m QEu97n6o9X0Rf28O0pG+Z4RUcpg5d62p2FPlGKRgjhz687uE2NOjCL1xGcb0Sv4m976v YYOl12pSdDJDlXvdaD0Zp/vCVrRTLe+YXBey15cFFmFZr2NP4V0JlejHOOFRDcVKXZfq yeatzb7ItDvdst8TUni6Euqyv91eaZRkOSVUvTWRH6u8ePSDUw/znDPdrP4D9Rkn8hbJ KeWsQYDwHscqREeCKYV95U0/+IlLPcQjvnUkM1xuJ2ZAFOadDjILemS32igbkO/6TwcJ ptBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uTgiMsbv; 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 x2si19007704pgr.428.2019.07.08.07.40.07; Mon, 08 Jul 2019 07:40:07 -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=uTgiMsbv; 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 S1731852AbfGHOkF (ORCPT + 30 others); Mon, 8 Jul 2019 10:40:05 -0400 Received: from mail-ot1-f65.google.com ([209.85.210.65]:37278 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728823AbfGHOkF (ORCPT ); Mon, 8 Jul 2019 10:40:05 -0400 Received: by mail-ot1-f65.google.com with SMTP id s20so16435584otp.4 for ; Mon, 08 Jul 2019 07:40:04 -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=J3hRcly8D1YDeUmF8zVR4I01GOuIVsuQo8ZUqHIaHHQ=; b=uTgiMsbv1bumv5PNRDGIEcP1Ibp2JR5Gcza9xMsyQlRcIKKkKbvfvcdP7m410I2uFc LupcPK6OC5otRQMJHpKkH/gooaNP4QcYchJO/hOweKClf+7XfLXizmgb4hcfb5GxK31s NbbSUzR2DUUNw6NAPEzKac3VqfWAoCVv5XevizEt07CSfrE/8RMP5Lp0np7dCxR7SA3+ RQbUaSrt9nOlyBz9d0G/xnpN0CcjeL6cQKAe1Pat9UQ2zAVN8k0eXmW3COs5r0m3GDnK mYz6R+pc5NesN39Q1byVWIY71GZUpg4FQRyVJgb3F8sm1l4Rj6+rZgD6GfOzALYGvWkl FUvQ== 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=J3hRcly8D1YDeUmF8zVR4I01GOuIVsuQo8ZUqHIaHHQ=; b=losF331uQHk51t/xXsRQGDVeHl63zD6SF+32K75c4dN86UwrpGetBHtKrURyeiCcmt Nsmpzo78e4+uKYhspQM1xy9MkDDCY0KXQQeooYR8guVzPiD++uNrRQodeUIybmB0HF5W iJa97SiBwUpTlOxuLEJ/AWxz5fcESUPQM6/wcJ0K7JBajOUkNBYUB6pdtB6Yp+3X6jKr 8tjdYHgpHCOI7K8BOZogNqYmApzbznyMecV5+yL5xiRdtkhMxjlKOtzmxayg/S4ag4le Y480mYwnMLeit/dwJ+/8gcvg6mRvbd7XrjEoQMcUvNOVbMluwBY7AZMqjA55aK4+qDfh 7kng== X-Gm-Message-State: APjAAAW20ueNOAbPfp0yNVrk034QkbWyhtBOTGxDygsevr3xfxQGlkR+ BHT67YHn+ZavAKGNa0IFHuM06g== X-Received: by 2002:a05:6830:1617:: with SMTP id g23mr15083924otr.117.1562596804495; Mon, 08 Jul 2019 07:40:04 -0700 (PDT) Received: from localhost.localdomain (li964-79.members.linode.com. [45.33.10.79]) by smtp.gmail.com with ESMTPSA id x5sm6386021otb.6.2019.07.08.07.39.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jul 2019 07:40:03 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , Adrian Hunter , Andi Kleen , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v2 1/4] perf hists: Smatch: Fix potential NULL pointer dereference Date: Mon, 8 Jul 2019 22:39:34 +0800 Message-Id: <20190708143937.7722-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190708143937.7722-1-leo.yan@linaro.org> References: <20190708143937.7722-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 Acked-by: Jiri Olsa --- tools/perf/ui/browsers/hists.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 85581cfb9112..a94eb0755e8b 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -639,7 +639,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) @@ -2821,7 +2825,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]; @@ -3087,7 +3091,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; @@ -3271,7 +3277,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 &&