From patchwork Tue Jul 2 10:34:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168310 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4072966ilk; Tue, 2 Jul 2019 03:36:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwv/A/XTPUJVdb/J3jIwwMetc/KuVbVgPPo8/d+2QnIaCgFZoxluDxqCEUesY5+dvdSzeQ2 X-Received: by 2002:a17:902:848b:: with SMTP id c11mr34280162plo.217.1562063760195; Tue, 02 Jul 2019 03:36:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063760; cv=none; d=google.com; s=arc-20160816; b=OMcyrpaT0IycOLutZ8/UJ8jWcfkdyqoKUs7wjhMn0mP3XPtexqC7VvM8qHcpUK+Qcj GkJK1+zUBV6zk54/wsT/0pfUuo5xYr2rldOqyaVw5N55jyA34C41raeksczby/q7fP/x bHdgJNEgSarcyLW1YYqHI6KeGsfVOEEk00GH/Rrbmky9YuFY3R7L2E5fi9ZHkNxHVVFu TTpadCSWI+CXOyzGsiHvX4R0lL5q9N1QE+EtaobzpQwvSVMdC+rsd55om33QP5ybh5i7 sjgeS9WB0+TfyWDA0x2FeXZsY2SYRB27YUrILW4VB1pu1Hd3UW7HJqNfsddqhCCyVkPB unrg== 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=oEKxu+SRBR2p4slj10y4/Ir+izytEa7NCXuzbUYce7M=; b=EC6Y5cfkoS5dBcfGfiSl36iLMN2Fo0FsqbzXFZ+8HaXagQZKNx5G/TFqQWXPI3Y68q DVoKtwRhpVPAFlZi+ENecwMr4YYffE9HHGc9PgLu3KfpiG8kfrc3t22n9vzl6K1gWaiL VCr/1973yMoU6ibTVO8uOZBNaNXAxIRjw1zmD4ILoXeYvibEnrg2hhzlnTOCYiNRZHW2 2wZAdywoCrTu9nbaMNnRN5aHsaBJxO9ONl9ZHE8Dkhtf5hzofE0lkMMmvepz7qWsrfPf H3HXwJOKKfx2ArQyeFQkZ0G55HT1eA18oQ8OFwWWFJGInLe+vYHHOl3Uv+TfvALlJw8F 4sig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wEvS8Xbw; 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 d13si12177814pgl.545.2019.07.02.03.35.59; Tue, 02 Jul 2019 03:36:00 -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=wEvS8Xbw; 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 S1727342AbfGBKf6 (ORCPT + 30 others); Tue, 2 Jul 2019 06:35:58 -0400 Received: from mail-ot1-f68.google.com ([209.85.210.68]:40818 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKf6 (ORCPT ); Tue, 2 Jul 2019 06:35:58 -0400 Received: by mail-ot1-f68.google.com with SMTP id e8so16625411otl.7 for ; Tue, 02 Jul 2019 03:35:57 -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=oEKxu+SRBR2p4slj10y4/Ir+izytEa7NCXuzbUYce7M=; b=wEvS8XbwFUFKdw+GxKZqyPYxrcjlJT6R7i4Djuo1pSo+8XRmo7dDVof0wJA6PCR3vd qFIwAcP7pDtAB8QbnK8W71bnfDTiUGrGvzNBaQ0BVXdhbpi92FhKXZpRzcCfxHl/1lrQ 0cnaFXJ4pGbGcg1Yj4KSf+weubc02b4z+z7aH8vZoygulTfyy1oCju1llcUE2/B5TAxO CBNT+MRWqFb+e57BQqcIPMsbBIg6p2JsXmSoO7EAI5kgLk7RIPuGCzZnvROcdx4biUl9 MWos28VX/AKKwLxXLoiRvshrmKgM0HO7EpW4LV9lPKGSBYUH2dyccIMucEgvK6w26lQT 61Og== 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=oEKxu+SRBR2p4slj10y4/Ir+izytEa7NCXuzbUYce7M=; b=GNqSNC1cwK/wKR72ZXJa37YlDHM02vLqOc2GqTno5QLw/LTCeMya2fg0OtkpO7kyA/ YarGl+G5JazzwEjeTmKBhDnWvWSc73fanQxrKNsUmM7MacSc8mkDbnuoiXiKhNDhkopZ 4DrrX3757WLYRdDlRAk0IJ0Dav9bt68C1vysk8fLImkSflS7N0Qyc4JKIzhCE59scFbi FOERrfenHSsZsVxZgSCNPfICC0wXeam9DUuHwFJzfXjFPY2jM3fNSOY/AB2aC2sivFlD sAtplDg6kgxjknvouajcS9zxOTQj4EB9mQmjB2maTh3aBPG2m6QrHvmMG+ZCxkhiImja EaXg== X-Gm-Message-State: APjAAAVvvBf26lcFuV+0K+bIXJDCiCK8umFmdJm+b/LT860dczjMeVf+ v7RM1cIBRg2ZSFqsfsvRNIVLjw== X-Received: by 2002:a9d:664c:: with SMTP id q12mr21775879otm.175.1562063757276; Tue, 02 Jul 2019 03:35:57 -0700 (PDT) Received: from localhost.localdomain (li964-79.members.linode.com. [45.33.10.79]) by smtp.gmail.com with ESMTPSA id 61sm5139805otx.8.2019.07.02.03.35.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:35:56 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , Andi Kleen , "David S. Miller" , Davidlohr Bueso , Rasmus Villemoes , Jin Yao , Song Liu , Adrian Hunter , Alexios Zavras , Thomas Gleixner , Changbin Du , Eric Saint-Etienne , Konstantin Khlebnikov , Thomas Richter , Alexey Budankov , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v1 09/11] perf intel-bts: Smatch: Fix potential NULL pointer dereference Date: Tue, 2 Jul 2019 18:34:18 +0800 Message-Id: <20190702103420.27540-10-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190702103420.27540-1-leo.yan@linaro.org> References: <20190702103420.27540-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 } To dismiss the potential NULL pointer dereference, this patch validates the pointer 'session->itrace_synth_opts' before access its elements. 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 e32dbffebb2f..332e647fecaa 100644 --- a/tools/perf/util/intel-bts.c +++ b/tools/perf/util/intel-bts.c @@ -893,11 +893,10 @@ int intel_bts_process_auxtrace_info(union perf_event *event, if (session->itrace_synth_opts && session->itrace_synth_opts->set) { bts->synth_opts = *session->itrace_synth_opts; - } else { + } else if (session->itrace_synth_opts) { 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; }