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 |