Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp583042ybi; Wed, 3 Jul 2019 01:23:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzL86GAYFshhL+TUBZXOUS4SJ9vWqSL5dL9oMNOtj+/5yImOeVQaph1ZzAJe50aR4lmObR X-Received: by 2002:a65:5888:: with SMTP id d8mr35038894pgu.124.1562142231074; Wed, 03 Jul 2019 01:23:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562142231; cv=none; d=google.com; s=arc-20160816; b=khdhY/5JzVKNbgnQmLs4JnfXcKDrKtRSY4t/rEqPBSyJ1fso2WTeegZvcWz2CCl+jr bRxw+tfkbeV6/48H//grKyjGbmlRhLYgHd8e83mHdw9+tqyLqkDAhNLWfxTrjVs1AwNz 4nCkC8asRMKOoISa4NEgJijALUQKEuS/NDn3UiIvjvnaLULb4aGXcsNHIqVogCikRCBB Xxdpo9bjguR0Dkp8t4Sb6Ftx1Yk8lrfJaxXQWlmSXNLrkdgwrFf4lkU026Z/RDjtppd7 RVpDi6D2YG8GgAv+YidgHreCCwU40lOU/tTQIZF94nGw/yamgw84jfodtEx0jqDps7ee vBQQ== 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:from:date:dkim-signature; bh=59xd1lKzTm7Rgf6PBY/uVBKcWbMFs5zQzD0EjdvmWzk=; b=G7H++h9MOGs3XfGOzUE+RBVt4Q4nk7jBbY2RKHgWMnWWwQ0FWrbA8aqe4OpA1ZrNEu Fiqux6dp9bt+nB7fWGKXGVa9zh5UhNqo6C2NXpy18mSMHg56yd50ac2cjaRQ9GMofahP poavbLPOquHizTsenOFm7jTw9ELRMpt4lIqEP1WucRAuT3JuK6vM1BlTrUwWXjsX3MLi cjfnrFn8VuTHd1aK8IW0KE8996GDVdHiz2JFgmV4HLOP3M2qmSVnv28uJ78fH/GsyIwm gkhE5rOBetfB4t+SivKGu9cQ7eIqEPPQ9vQ1OMPVBd3UjugYhwSrRszq7xwn4OhPK/Kh ZV6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bindf1ZA; 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 8si1607150pgk.539.2019.07.03.01.23.35; Wed, 03 Jul 2019 01:23:51 -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=bindf1ZA; 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 S1727241AbfGCIXJ (ORCPT + 99 others); Wed, 3 Jul 2019 04:23:09 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:39996 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727052AbfGCIXI (ORCPT ); Wed, 3 Jul 2019 04:23:08 -0400 Received: by mail-oi1-f193.google.com with SMTP id w196so1353293oie.7 for ; Wed, 03 Jul 2019 01:23:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=59xd1lKzTm7Rgf6PBY/uVBKcWbMFs5zQzD0EjdvmWzk=; b=bindf1ZA6lXjnWIAj6gU/mMOzjIeC34kEuzIN9HG9ndu6frBFLAne/lS6eFkZbM7RN oodY/TdXzdO8LD0FjWlbcGnsS2KfNutRD2pOwpwjmBkX25Sx9UkBvlL4UWbr/NNxZUY/ WGyNMAxaC4J1pyq+VWiEjgUPY420FoGnr9ORkAFCOumbUy2NMOubNWuz7J+/LnfZSdaX Af4ektvIX7IQuCI6o0Vz0WHCqPKz1g7wg1DWTekBIELTjU0laIk0qBU1iPI+pIn2PHXR EDtkj7J4YO2rBCiGy1R0hdOwKGfKDZ16pyL+9I3viqjM7T3YPVukWvH+W0cX58Gu6H+B c6iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=59xd1lKzTm7Rgf6PBY/uVBKcWbMFs5zQzD0EjdvmWzk=; b=d8gKL6jvkcLbyDlP3AeBNoBJc2iYFZj5qd/YAo4pZ4gK6v8sIBRBKLNUMK+NivUF3u QXeHJqCGylnukGivSQtPedeQA1oHMO9OPfJuVKP/NQ7mpBBEiX6ju4nRDfZXPWtqq18q wFuBLDrz9D+VZpDvkbM4RFJUpoto8K6uMKC1kNY/3WI2RyqRONF5nBz9DVHJE2IeUDa6 Ljn+29GWeYnGkEL5EyIRtVivPBGLcddxsv/wYAsG3uVrlMux3bYGLphRgY3k4BGmUmHF 0PoMk5htNCYg+To0qYdEVTKoVYuUEGJNcRhU6XCgVi+oRegiwZUBUwL3HfbTTwdeSj8m k1nw== X-Gm-Message-State: APjAAAWBjVCOUfQg9Dy8tDgoE51VlAQ3CEDcjzRNPwtFsEXIujyo1CFQ NsOj1qznVwQLhAGUBymrJDG1cw== X-Received: by 2002:aca:d7d5:: with SMTP id o204mr6353477oig.16.1562142188072; Wed, 03 Jul 2019 01:23:08 -0700 (PDT) Received: from leoy-ThinkPad-X240s (li964-79.members.linode.com. [45.33.10.79]) by smtp.gmail.com with ESMTPSA id h60sm636627otb.29.2019.07.03.01.22.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 Jul 2019 01:23:07 -0700 (PDT) Date: Wed, 3 Jul 2019 16:22:55 +0800 From: Leo Yan To: Mathieu Poirier Cc: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , 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 Subject: Re: [PATCH v1 11/11] perf cs-etm: Smatch: Fix potential NULL pointer dereference Message-ID: <20190703082255.GE6852@leoy-ThinkPad-X240s> References: <20190702103420.27540-1-leo.yan@linaro.org> <20190702103420.27540-12-leo.yan@linaro.org> <20190702170306.GA17808@xps15> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190702170306.GA17808@xps15> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mathieu, On Tue, Jul 02, 2019 at 11:03:06AM -0600, Mathieu Poirier wrote: > Hi Leo, > > On Tue, Jul 02, 2019 at 06:34:20PM +0800, Leo Yan wrote: > > 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 } > > > > 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/cs-etm.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c > > index 0c7776b51045..b79df56eb9df 100644 > > --- a/tools/perf/util/cs-etm.c > > +++ b/tools/perf/util/cs-etm.c > > @@ -2540,7 +2540,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event, > > > > if (session->itrace_synth_opts && session->itrace_synth_opts->set) { > > etm->synth_opts = *session->itrace_synth_opts; > > - } else { > > + } else if (session->itrace_synth_opts) { > > This will work but we end up checking session->itrace_synth_opts twice. I > suggest to check it once and then process with the if/else if valid: > > if (session->itrace_synth_opts) { > if (session->itrace_synth_opts->set) { > ... > } else { > ... > } > } Thanks for reviewing. As discussed with Adrian in another email for intel-pt, it's safe to remove NULL checking for session->itrace_synth_opts after I reviewed the code for report/script/inject. So I'm planning to apply the same change for cs-etm code. If you have concern for this, please let me know. Thanks, Leo Yan > > itrace_synth_opts__set_default(&etm->synth_opts, > > session->itrace_synth_opts->default_no_sample); > > etm->synth_opts.callchain = false; > > -- > > 2.17.1 > >