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 && From patchwork Mon Jul 8 14:39:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168657 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp7252738ilk; Mon, 8 Jul 2019 07:40:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwlsM6vh3H6CA7ltgDGIEwnnbzPagmIWvL+T1vHiw2SnCFr6FXTfEHeD4wJu7+EyJgxGHfC X-Received: by 2002:a17:902:54f:: with SMTP id 73mr24862688plf.246.1562596820773; Mon, 08 Jul 2019 07:40:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562596820; cv=none; d=google.com; s=arc-20160816; b=VmknWRqu4bkZffjufakWczau/YKp8INqrWtkOH6hpG5IytYHM1NjJX2vJizKA9wJ/o iY/xMCEavfUJXHfOv9P5X8x6LI1yvaWrjDcPRAtnOS8Lts3kBMj3+ykd2uazrmOdONnd t47ZbM8UtT3YZPtzT81icUAgW7YZpKSu1RSI1hZblpnBSBeGXjZswavJfr+BnUD3m8vt rtDOGFCo92EEWypJPrwJnxDwhel4euireEnfFu16uggHLNhl2D6yiUO23YaYD0Z4yGXU MdN7cLyiS4Ny6GpSAwrRUEzk/sDjJlLU3ZZ/4u4D3YKnsU4zRKR2unLuauigh+QIZYHH 80Rg== 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=iIj/D2uFckhktV/1D81+BNHiSe7rGxGISfmtPBSrlSM=; b=Mp3bprZztTUZUBl0i3zSzf65nT4tIGjod+DWWfaTRAvitZ3ZZ7/kk+6MXH7CEf7RQs 2dTWdmQW+ZcKRpsGxHwC4IpPe7NaVV2WWVjy2dhcjA9MYuyMRNVBsiNCO1AUF6QeQwir I6OzpLe/7UlLyyh1xsw037Y8m/XEySYQpelpPfsxVdkJ0Ze7AHKTsojpVVDaprd1BkxF TKqF5ZIsaIZ1alS4PxnlQ3IUw6xxSOmxzbH0dSPa1LiTuWE7wjX/PHH9ob8x89S38+1a EuLOyHDz6NkYlA46YJrzGWIDOcfFliPeGDFFox+2Ampdc48+GBsK6gRASnAMD8Lxt79g TJ4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C+MArnBQ; 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 v20si17867293plo.384.2019.07.08.07.40.20; Mon, 08 Jul 2019 07:40:20 -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=C+MArnBQ; 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 S1731870AbfGHOkN (ORCPT + 30 others); Mon, 8 Jul 2019 10:40:13 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:44786 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731855AbfGHOkM (ORCPT ); Mon, 8 Jul 2019 10:40:12 -0400 Received: by mail-ot1-f67.google.com with SMTP id b7so16389189otl.11 for ; Mon, 08 Jul 2019 07:40:12 -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=iIj/D2uFckhktV/1D81+BNHiSe7rGxGISfmtPBSrlSM=; b=C+MArnBQMr2fem13xnS9J64lNmtz6x3eb264CDVGZm7lK3pxHAy8901qu3ZTI2HIS6 7K9WLnI/UgnLLE1IK0Nh+pHlhLXmB4gPUEqugQmc+xsgLxMQ0G8jeB+9KL1O/cfTMvXt erNEljQYc3VzgMUZRXI+YJ1J59KILFnMJ3P2X1PNJo3Nx/w2yYFWGaccpDUTST0tS3yU mXnMUWw1nnC/DFX/QkIj/wO9Sc2SGyy6oYCYidmXzXXV4Z+KDev9igsREiqaE5fOpfx0 DwfbUepPKKEmN0tnUtPOleWgPURufqT8O7xB3E3KtQGRrDjQ3fFnI4EDjpeLJ4WO90dI zo/w== 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=iIj/D2uFckhktV/1D81+BNHiSe7rGxGISfmtPBSrlSM=; b=gImuxAI2nWfuOeI/xrbI1rUMW62d/XccnHwFQ2InuipXa7oWNtxKf2MfHltfsc6AC1 4+XcTGCN5F2nlAhK2tpipW0KxdNtRdMS99G3gUTtMhW91HCYYxTDc4cgMyrNh+98igML PzBFxr1UfmWNcxj1D+0cvAQRTszbs1RDABuAyY4vE1kubnaT4iWlAU0WknpJQa3lfBdh S6IknQtdx1aruXEjk1jSIhC3s5H/52thoGSBY944yuMkjUdLTit94iFAmhuvctsDeSJl uSLXdqCZq8sLRnFwSrpJtB55xCJJSvf5qf2LWDuWkwINTu8D37Jub/ZGB1L8664Td09D QuUA== X-Gm-Message-State: APjAAAWb50aED54qRL2jhNt8JlHPyIJnpGYoJ5YVBNROrnXQ14GySw+w riK8lzBJ40ES5cvoVFrkxIB8xw== X-Received: by 2002:a05:6830:18a:: with SMTP id q10mr15142642ota.114.1562596812197; Mon, 08 Jul 2019 07:40:12 -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.40.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jul 2019 07:40:11 -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 2/4] perf intel-bts: Smatch: Fix potential NULL pointer dereference Date: Mon, 8 Jul 2019 22:39:35 +0800 Message-Id: <20190708143937.7722-3-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/util/intel-bts.c:898 intel_bts_process_auxtrace_info() error: we previously assumed 'session->itrace_synth_opts' could be null (see line 894) tools/perf/util/intel-bts.c:899 intel_bts_process_auxtrace_info() warn: variable dereferenced before check 'session->itrace_synth_opts' (see line 898) tools/perf/util/intel-bts.c 894 if (session->itrace_synth_opts && session->itrace_synth_opts->set) { 895 bts->synth_opts = *session->itrace_synth_opts; 896 } else { 897 itrace_synth_opts__set_default(&bts->synth_opts, 898 session->itrace_synth_opts->default_no_sample); ^^^^^^^^^^^^^^^^^^^^^^^^^^ 899 if (session->itrace_synth_opts) ^^^^^^^^^^^^^^^^^^^^^^^^^^ 900 bts->synth_opts.thread_stack = 901 session->itrace_synth_opts->thread_stack; 902 } 'session->itrace_synth_opts' is impossible to be a NULL pointer in intel_bts_process_auxtrace_info(), thus this patch removes the NULL test for 'session->itrace_synth_opts'. Signed-off-by: Leo Yan --- tools/perf/util/intel-bts.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c index 5a21bcdb8ef7..5560e95afdda 100644 --- a/tools/perf/util/intel-bts.c +++ b/tools/perf/util/intel-bts.c @@ -891,13 +891,12 @@ int intel_bts_process_auxtrace_info(union perf_event *event, if (dump_trace) return 0; - if (session->itrace_synth_opts && session->itrace_synth_opts->set) { + if (session->itrace_synth_opts->set) { bts->synth_opts = *session->itrace_synth_opts; } else { itrace_synth_opts__set_default(&bts->synth_opts, session->itrace_synth_opts->default_no_sample); - if (session->itrace_synth_opts) - bts->synth_opts.thread_stack = + bts->synth_opts.thread_stack = session->itrace_synth_opts->thread_stack; } From patchwork Mon Jul 8 14:39:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168658 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp7252794ilk; Mon, 8 Jul 2019 07:40:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxh89xqE5TjWYfAQ78L0A3I+YqcsumilY5oTqFnWlRvbbhSJdM3xiBA0kLoPO9SuTNFHBr6 X-Received: by 2002:a65:610a:: with SMTP id z10mr24460041pgu.178.1562596824013; Mon, 08 Jul 2019 07:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562596824; cv=none; d=google.com; s=arc-20160816; b=NYm/D05tB4zTI/ufKsSTdoHDVyBL0eiOnOfQ+jwxhmW6e8BBv43o3LeixfSzWsla6+ V0Oaik4wlnjYLsQatqGHb2Eo9uD4Z3q/Anm+bj5lxp0d+dL/j1h2k/Ns/FXQCLw1rVoN CK/V9l4EUQ+ub09mD0qdASh+KbRXSLgkmIQrL+ylaQoqd7JrClzM2ucs9y96bCXZKexy QdLcplqi+O7ZP9ayuxiKqJliWO0Ry2HJYlJaDUNn3CRVGfcznNINvgornYq5DNzGeF/d f5KbTabIEgTL+Hfa8hwJPXHNOA5MckNCcbipknzuWZU/CYISET0FFxBm+FZrRjvB25OF su4A== 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=P0UfYuSIVn3ZdoCHgmfMQcQ4Bx5Zeyc6tJ2jWiXjhtc=; b=UKy3a/us/m967iMTdLI8Hh70Cw0gbBeCW/gPQIDAcHaxqm9kL/ed7YEEBqElasU2KF 5TewWSEAAcCKg5dd5oUPW7kjwvtQxDqR/HWxUeEvUbUQmRhs3+IeE7B+K4bX2cj3FsiL Evd4BfKMyDomWIJBGhxQJ1rsseBJk68g9BTHFwMoOozfvN+sXryJ7mCxQcQMCd2avh7j zymCwds70X/hbjKufesXDoIWTrBGVsED7SfyiUj2DmlFq4Ir2/Z++P98oxq3nJ9k7t/o met46WlsN7p1Dbnfd76Qs2Zl58PwBf8X9PQ/wDciUnAk4tpriWGPFBX7nH3rdJMX0Y6F 8y6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MQqQMln6; 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 v20si17867293plo.384.2019.07.08.07.40.23; Mon, 08 Jul 2019 07:40:24 -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=MQqQMln6; 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 S1731894AbfGHOkW (ORCPT + 30 others); Mon, 8 Jul 2019 10:40:22 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:36237 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728823AbfGHOkU (ORCPT ); Mon, 8 Jul 2019 10:40:20 -0400 Received: by mail-ot1-f66.google.com with SMTP id r6so16441546oti.3 for ; Mon, 08 Jul 2019 07:40:20 -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=P0UfYuSIVn3ZdoCHgmfMQcQ4Bx5Zeyc6tJ2jWiXjhtc=; b=MQqQMln6WxFnwJIxVdQq725CZ83Q5i8yiXXUbwPqunDJgW98k01CN/JD82UlujQDg/ xvc5BqdXrI7B2KwEaXdC6hl4VQKtrnKVZNmiYbAWtYG0kDWAgtu+3JxUWrfZzNAoOIhL iLWZiyTa8qIrbYcNkUidLc/TpnZMFhl7DFZ/eiwZ9LXKbHVhU8HFHrRgacH66/AzYTtM G3oDjb17sTWOV7mptFn+ZvPtuFddiAyZ6dtWk/RlotyddhooGD197KRCHZPP/pf9M1yb RNLqLQ18cPnZqslKQNDY6jmTbFexEJZ2Ywgxy6iQSeP4Ys2LGPb6I8y91dmORZAsw9jG c13A== 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=P0UfYuSIVn3ZdoCHgmfMQcQ4Bx5Zeyc6tJ2jWiXjhtc=; b=c+SXYoSFmoCPO4hypwQntJtHPEDTHpMQ2WclkshZYZMy5IoRR8Y9ulaqFd3eaEuiOR 1bMRtD+EIrWAqkF0Ghx0sT07/5YveqtJzWDrTLc773OD6T7d7mg+lvwgT0uTqgf29dVz cu5wmwqOQCmTunUJpIqmdnMz1O4FHFiYtDlfyhOqWVTXhjtjK0eCXYCsqLCA+if2llfe hEaZi2dlliMyOPBuXTZC/qg/5t6tADHUN8jFL46R4rvS0NazcvN65TQLunFP/ZtNl+3x T2/NkUzEiHfgsUDFhno05QICa8oylYtEnuHJ1ovD4cafEAtYIQ2BjvTHGqdhG7sLQczr hCaA== X-Gm-Message-State: APjAAAVOr9pSOY4CSaAB19mmi1jvDJihTEhLuTT2WhDQtjg0wzN1mhpE mmtNbYxhR21V3XeeDhwQd+JlvHisph/jqA== X-Received: by 2002:a9d:5f1a:: with SMTP id f26mr15287602oti.91.1562596819691; Mon, 08 Jul 2019 07:40:19 -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.40.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jul 2019 07:40:19 -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 3/4] perf intel-pt: Smatch: Fix potential NULL pointer dereference Date: Mon, 8 Jul 2019 22:39:36 +0800 Message-Id: <20190708143937.7722-4-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/util/intel-pt.c:3200 intel_pt_process_auxtrace_info() error: we previously assumed 'session->itrace_synth_opts' could be null (see line 3196) tools/perf/util/intel-pt.c:3206 intel_pt_process_auxtrace_info() warn: variable dereferenced before check 'session->itrace_synth_opts' (see line 3200) tools/perf/util/intel-pt.c 3196 if (session->itrace_synth_opts && session->itrace_synth_opts->set) { 3197 pt->synth_opts = *session->itrace_synth_opts; 3198 } else { 3199 itrace_synth_opts__set_default(&pt->synth_opts, 3200 session->itrace_synth_opts->default_no_sample); ^^^^^^^^^^^^^^^^^^^^^^^^^^ 3201 if (!session->itrace_synth_opts->default_no_sample && 3202 !session->itrace_synth_opts->inject) { 3203 pt->synth_opts.branches = false; 3204 pt->synth_opts.callchain = true; 3205 } 3206 if (session->itrace_synth_opts) ^^^^^^^^^^^^^^^^^^^^^^^^^^ 3207 pt->synth_opts.thread_stack = 3208 session->itrace_synth_opts->thread_stack; 3209 } 'session->itrace_synth_opts' is impossible to be a NULL pointer in intel_pt_process_auxtrace_info(), thus this patch removes the NULL test for 'session->itrace_synth_opts'. Signed-off-by: Leo Yan --- tools/perf/util/intel-pt.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) -- 2.17.1 Acked-by: Adrian Hunter diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index c76a96f777fb..df061599fef4 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -3210,7 +3210,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event, goto err_delete_thread; } - if (session->itrace_synth_opts && session->itrace_synth_opts->set) { + if (session->itrace_synth_opts->set) { pt->synth_opts = *session->itrace_synth_opts; } else { itrace_synth_opts__set_default(&pt->synth_opts, @@ -3220,8 +3220,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event, pt->synth_opts.branches = false; pt->synth_opts.callchain = true; } - if (session->itrace_synth_opts) - pt->synth_opts.thread_stack = + pt->synth_opts.thread_stack = session->itrace_synth_opts->thread_stack; } @@ -3241,11 +3240,9 @@ int intel_pt_process_auxtrace_info(union perf_event *event, pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio / 1000; } - if (session->itrace_synth_opts) { - err = intel_pt_setup_time_ranges(pt, session->itrace_synth_opts); - if (err) - goto err_delete_thread; - } + err = intel_pt_setup_time_ranges(pt, session->itrace_synth_opts); + if (err) + goto err_delete_thread; if (pt->synth_opts.calls) pt->branches_filter |= PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC | From patchwork Mon Jul 8 14:39:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168659 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp7252915ilk; Mon, 8 Jul 2019 07:40:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqwOgXIN9HAuS86aHAGi9VLC113e6KRrKP0RILxrvl/yELR60apiIenOIs+i6f2qiQUfeLht X-Received: by 2002:a63:6ec1:: with SMTP id j184mr24562023pgc.225.1562596830386; Mon, 08 Jul 2019 07:40:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562596830; cv=none; d=google.com; s=arc-20160816; b=gK+/l7h74LyD8bTSUubkeXy9O/xcQU1XFDee9OlEt7Di9/cFwOrpTtXA5ttwoNbOtD UOkohUlBLcOAn7T1kCao1gAXTh/NVevX/bKQIrdwLri1EvUyl/BcOkdPbiHb3d1slyTh G1wuy6qwfr4R6sXWmz7aQWoVKC4vBWcE93IKx8j9Bq5RPb15iK6NYpHTm27UFYO89Rmt ++uhO2XEdAYtSCRVAn03/OMyktnDuVCSFFEV+wJlZ9ZGdKjPnnrFiQkgGyV8/I+KVH23 eC0ymGcHAQfK/5BXd7nhHgnSJw5/2mXccySALfh/fKeOTj6JleYGvKxbiUxGMqMUppHY B7hw== 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=CCSoHq1Uo4IBnCwfeuA+GvIGXoY8z0TTGOk4Tw+sVOA=; b=meV2Gs3SPGKokkjU06DcZvv1YJgLstSmwElaTXUPyht/JtresNn0fRu5cH8I7ccF0g aD3wGP392nP9CQaKLUtnr99mO1Np1WdyrzPYmhRLIPXxl4/x4OzhVUsw8WffEP79msnt ZsLrOymbmRKHlXSEl9Ci1WDv21EwrC7HmUG8dgryFJEP6hwYF6IlgAkgkbps2706X6tA 8OrgI1kr69TbZYK9ZQxyPNbDEzIY5KIl4jEr1BaA4NUo23HQrQdbagRaIjNd60KD7qTA W2nHsFU8VICi1s4GhI/R3233bMp2jZCi98NaFVg6poGuJqQM/az6G6srdc/tiOAQ7Nmv HOlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rMnUN1r+; 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 v20si17867293plo.384.2019.07.08.07.40.29; Mon, 08 Jul 2019 07:40:30 -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=rMnUN1r+; 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 S1731905AbfGHOk2 (ORCPT + 30 others); Mon, 8 Jul 2019 10:40:28 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:34422 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728823AbfGHOk2 (ORCPT ); Mon, 8 Jul 2019 10:40:28 -0400 Received: by mail-ot1-f67.google.com with SMTP id n5so16460014otk.1 for ; Mon, 08 Jul 2019 07:40:28 -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=CCSoHq1Uo4IBnCwfeuA+GvIGXoY8z0TTGOk4Tw+sVOA=; b=rMnUN1r+KicSBHv/XyAGYU6dbXI3N+TcAG/o+Ydxv13ZCBB0c/O2uu9G4vqrLCytct AEKFHYY+SHopfy3uStEBvIMEspHQMmadm9wEmnta9CgMRDdfOnpwGL+PB2/POmpXHUru /MlsSUF/JzCed/TIDJCNcEyJODeNFhMRwfZWmGaKDJfrVJgMDTYz0U8MLjvjQGJDDUsK kaqgF3izPU2FROV8J+mfY6t97vifqIqb/sJvvFV9+XMLcxYIMSnX9vQhtJdxdxWjDUXJ NPnoBwSTkxC7AmqTwW6gwUncSzbtlw0O7Aaaj9ZmAZA8Uczsbth2wNfWlo5oh6QrJWYq iW9A== 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=CCSoHq1Uo4IBnCwfeuA+GvIGXoY8z0TTGOk4Tw+sVOA=; b=LNVA0AWcXVtfDLeuaNa5L3BYhQTotr7tXnEpmplGOzV9E3ClU/L6B0ymwqQ140UNyf QkTjJNAW3K5zC4AiG0TQRKiPsGWDf2quYRf32RKQyQeCFU5WOjiAmNu5ZI2T/loHhvR9 wfiQLN/awEMPf/UNeNgul2KOJSSNvJSH1USQNmGZJ6DfbV881ZczHG59TWsUDkuGNmRe VK56D6+UiJq/zeGLCTPMhdPeGUU/nbMbvvHA4pBa/VrOHLYV82m1+L6XAR/TM9QHEz2c gpw1QXQqhqbF7j8TprJJMF7BGgu6zavxgM887SqvHuJpBECyU55qM/dY+ST7b8kj2FYI fWcA== X-Gm-Message-State: APjAAAXOaNqjbz3utsklwBCVmXDqBq1DU9G3bsF5TpcSb5r33cVXzRh7 /rGkHMmB6DUDca1KViS2cI2C7w== X-Received: by 2002:a9d:4b88:: with SMTP id k8mr9349423otf.285.1562596827664; Mon, 08 Jul 2019 07:40:27 -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.40.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jul 2019 07:40:26 -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 4/4] perf cs-etm: Smatch: Fix potential NULL pointer dereference Date: Mon, 8 Jul 2019 22:39:37 +0800 Message-Id: <20190708143937.7722-5-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/util/cs-etm.c:2545 cs_etm__process_auxtrace_info() error: we previously assumed 'session->itrace_synth_opts' could be null (see line 2541) tools/perf/util/cs-etm.c 2541 if (session->itrace_synth_opts && session->itrace_synth_opts->set) { 2542 etm->synth_opts = *session->itrace_synth_opts; 2543 } else { 2544 itrace_synth_opts__set_default(&etm->synth_opts, 2545 session->itrace_synth_opts->default_no_sample); ^^^^^^^^^^^^^^^^^^^^^^^^^^ 2546 etm->synth_opts.callchain = false; 2547 } 'session->itrace_synth_opts' is impossible to be a NULL pointer in cs_etm__process_auxtrace_info(), thus this patch removes the NULL test for 'session->itrace_synth_opts'. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.1 Reviewed-by: Mathieu Poirier diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index ad43a6e31827..ab578a06a790 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2537,7 +2537,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event, return 0; } - if (session->itrace_synth_opts && session->itrace_synth_opts->set) { + if (session->itrace_synth_opts->set) { etm->synth_opts = *session->itrace_synth_opts; } else { itrace_synth_opts__set_default(&etm->synth_opts,