Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7161226ybi; Mon, 8 Jul 2019 15:54:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWDv4OeaRaXzCySY8oi9Tzm89c4xC4IRyHnkpsrMmP1WO4fMoiQ9B8/JL1ufRKArOUNFw7 X-Received: by 2002:a63:101b:: with SMTP id f27mr25608295pgl.291.1562626458383; Mon, 08 Jul 2019 15:54:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562626458; cv=none; d=google.com; s=arc-20160816; b=Lv+Fnds9iSmrPxXmnV9OrVKs1YXh0J8ZU776MhY2c7LXG66oMiVDm4/U8hcca0EQ1u THTOanTMAXWj6bfFdLR5OLr4sUwCJs+vydASQYY6H3xxp2sxa7yKeiFeA7t97Lv8+2dF Xfc1tSvcsDxz2XXy2yhUBvGyVE8AUgDsEwPq1F4gahoapdrUT94xd91qNLD8esPVPgkm YDtakIzzSqPTzXrTKucwROYFb/0FYv+t+JGsZAXN0hlUAnOgxFgQ6Sl2YlGt0SY49oeq mO4PGdThjrYs382iYgGBfbyPRspqZ+ErUnF6hvp7WGDZ2MtGcMNjiYjsG3NpE941s6GW Z1rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=51c4IfPYBT+5J+agOJgYO3bIQC8MzKtwLDft7qMF0DM=; b=I7aWRu4mfjF0qxX7kW6CExcypRnDoa/A8h6b5bH8mpO6HEZgmIE79xhWqFZk5M9l23 E3eWTpc1mSAizqEq9LViw795gu3PnaLZbnlC1rxqA5OoSExonX7SC0zcvdQMRo7DbltN 6gceKpHB0JRRA2pT1CnG5vMu9kFwS5tFWfJyxtjyiGr/QqiSyeTiuGxJTw493Bc/57HA jnUO2P4pvy4tuwX+lgA6svWhBhvzciFYkCp88aytVRb6EaC2hPyOSZGf9oYFJRokkZ5K qTHMFzBb54lF3XzhmRaZAo+5vq02grTn6fh1gyKff/6ZxSuwB0AuXwKMy/cQaA4e28Rc ZUWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=O9jlUqZ+; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d21si730669pjw.18.2019.07.08.15.54.04; Mon, 08 Jul 2019 15:54:18 -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=@gmail.com header.s=20161025 header.b=O9jlUqZ+; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405381AbfGHV7p (ORCPT + 99 others); Mon, 8 Jul 2019 17:59:45 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:45346 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732609AbfGHV7o (ORCPT ); Mon, 8 Jul 2019 17:59:44 -0400 Received: by mail-qt1-f194.google.com with SMTP id j19so19578113qtr.12 for ; Mon, 08 Jul 2019 14:59:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=51c4IfPYBT+5J+agOJgYO3bIQC8MzKtwLDft7qMF0DM=; b=O9jlUqZ+4vCS085d+1YCzB9Oe//LLSFNctsqO/FWkvVqu0cICOCK3+5Og/Gd3FRZpl mV3awcmWfOuNhRPP/lCuILtVx8UbDEJ2qOX/VtYiwwtyFJdkmCLbHEcqqAcYKdgIKSav qc0nqdFHR69Ea4Sg/la9n1A1hOZ0nAodQMTLQiT6ioeQ0GW7VkBVI6+OnExylfrHLHF4 miEGB497gyTXtBF8dth9RlOThOkO2GbLeFdWkDnpZg8LyyUCfiquRYlshDYOgyqenbcx HOnVxrH74884d3XwG3Nlo0LDDHGoQVTj9cUhckHNgWipR2FlEp86rdMYCw+Z1fw/NjNd HE6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=51c4IfPYBT+5J+agOJgYO3bIQC8MzKtwLDft7qMF0DM=; b=R5oJxVVJOEnII83SPn2/ty2J96IASwtClFvf9aqPPoGjvOVAtBX9wDNMJSf425OjRg Cl+LcCfX2zDNBByjAn32Ok0T0F1cCb2aNaKj9DduwJuGLA32q0ig7TwHHFMBsxCkjEui XyLN1OSdCp7nUn+t0O4JWQB8Zukt5rF/i0wmea+oCvds2d7o8Eymyd9Y5Lk7ZGEGupS3 wAsuoVj/0tSgHlYVhYFY0K44hvhBUITyphW1ZTd5ff/YGcI3hY8g1WRLJNe1ZAKgoUmO cP0icG5lIR/muJvoTtui4/Uu25lM9ffLkxRXKbOERHTh/q0gEahNLCh4mp27n7ZrH7EL psCA== X-Gm-Message-State: APjAAAXtNXfbhmm3ep86iiFoVP7aZw24ckvgAxjUeeaSka4Vzb6iNCc2 p0+2xFf+3zlCLMpuTKzg02A= X-Received: by 2002:ac8:303c:: with SMTP id f57mr15768350qte.294.1562623183271; Mon, 08 Jul 2019 14:59:43 -0700 (PDT) Received: from quaco.ghostprotocols.net ([179.97.35.11]) by smtp.gmail.com with ESMTPSA id m44sm9406125qtm.54.2019.07.08.14.59.42 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 08 Jul 2019 14:59:42 -0700 (PDT) From: Arnaldo Carvalho de Melo X-Google-Original-From: Arnaldo Carvalho de Melo Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 9857340340; Mon, 8 Jul 2019 18:59:40 -0300 (-03) Date: Mon, 8 Jul 2019 18:59:40 -0300 To: Leo Yan Cc: 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 Subject: Re: [PATCH v2 3/4] perf intel-pt: Smatch: Fix potential NULL pointer dereference Message-ID: <20190708215940.GD7455@kernel.org> References: <20190708143937.7722-1-leo.yan@linaro.org> <20190708143937.7722-4-leo.yan@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190708143937.7722-4-leo.yan@linaro.org> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Mon, Jul 08, 2019 at 10:39:36PM +0800, Leo Yan escreveu: > Based on the following report from Smatch, fix the potential > NULL pointer dereference check. Adrian, are you ok now with these two for pt and bts? Can I have your acked-by? - Arnaldo > 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(-) > > 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 | > -- > 2.17.1 -- - Arnaldo