From patchwork Tue Jul 2 10:34:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168312 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4073232ilk; Tue, 2 Jul 2019 03:36:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYPSAzPtRIkFe4+YgI58DPqSutW1N2I/EFzbmrArebAU6v5wFnjO9Qm/u4EOh2hZ/vXBFZ X-Received: by 2002:a17:902:204:: with SMTP id 4mr1192746plc.178.1562063775241; Tue, 02 Jul 2019 03:36:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063775; cv=none; d=google.com; s=arc-20160816; b=MLcuuIlrb7/lZ4d8J7izGWJ/68NleZcfqe6WxWc56q7KbcUlq9PGibbVjvd7DzWJkh 9DUwfVrslo4g191qSivJxlWJNV8ld+P4rg5W4MwQfjzBWI0rBoGvPTbjnCv6EEEc7U9y tZPndeZQSoImDeF06SotvrpQjYkfFYfz/uOiiAh0UG/+CgxC4OyiKzEteLpg5uuhomZe B5Tki6SBwUd1RqlcFYZU6pbn0peIaDn/c/3VE76OGOPAD6nu4xSObeEBTC82+ja9CfI6 5qKJh0IdAVoOj+9JX6iM/YzGvbAnPD4XDHn23Rtuj/zWBP5ZjCwMBbfQVWXvIFxDXfC6 8Yfw== 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=dQcQ7p8oORqYUmw8MhMOFx6e3+qYvK2rxF9oxDoZM7o=; b=FlFQvHwT8Zorex6Y47Wi+cJkEa9d0tyjsij5Z6VW2GsZqym3NQ9IDGODSxV3JudiU7 xZcU/fRkDlSTohhFlLLjs2YS6usj65iaQ+DoEwBf020LWjdmt8KIKN5XFxypG/vvxefv Vpg1hfSdKvLNUy9GoMWGHzako/hrxiaoweYB+WTbJcytLElcgwm9hQlg1foDKjYh/qUY SVbQ9EdK+UFnZh8RfvOriN5CLff5N6WpiuikY2rNUKCEYMR8cH0vtkLZEf6YOVnG1c8S r5XoBB27YmI6cAsZfWXHrnweflQ1/0vRdub5QHqMZR2FcMKgfRmVmAY9F7rNEUS+bPL/ l+nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JjPXkNjN; 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 v15si13459496pfm.238.2019.07.02.03.36.14; Tue, 02 Jul 2019 03:36:15 -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=JjPXkNjN; 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 S1727365AbfGBKgN (ORCPT + 30 others); Tue, 2 Jul 2019 06:36:13 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:43983 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKgN (ORCPT ); Tue, 2 Jul 2019 06:36:13 -0400 Received: by mail-oi1-f195.google.com with SMTP id w79so12633872oif.10 for ; Tue, 02 Jul 2019 03:36: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=dQcQ7p8oORqYUmw8MhMOFx6e3+qYvK2rxF9oxDoZM7o=; b=JjPXkNjNwzvim2+CUz73ozuGlX5deuQwPQXRLkI9Fyk/R2nArA59R51YaLMo8npnVO oDx52w/nnl82obHSJkgpF8mTIFXGgbsPgPRY0VhOjMmYjUfylrDBve/OsYv5SO5HwI/t fJtTAVO+HkS47kqFPjOMzwwEZDDJvwgP7lEbyF1Voea5leDzo8xMvT97Wip/cBsMj5HC qb+vN0sL1ae3v1Lp2+ZMoD6/7mRVeEM/HozhAt6Nchk7yTPvTc9H31mPH+gFGlRyx5hx n8EIseeSRFabSWYYZvbYMFwVKE8LJaUpguIJXOkH/Nu/sENoYoO49Zw4nIctWDhGf81L pkfg== 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=dQcQ7p8oORqYUmw8MhMOFx6e3+qYvK2rxF9oxDoZM7o=; b=kGb8lw7mS5IjbZqt8L9sSsQGrKwhK30M6RQJ/+ZncbSPj6LobBCCJ3jkDlbU/n0Z86 g3tsANgagV5eAmXnZxn6JXPzNz6DOtym2wyDAKGSXLo3ZTOlv2564LbmXdatDgK7IenN foSv93QVB3urJW3uDJH71kupAMLGrO79gV1uUCk+vgqEGIyqx0ipBoH0Q6nGHbvqZUM6 nM4v+3vVJls2uuO15Gf/m7BVmzVoQQXU9+tV+z6vHCszEcFYGVoSXUZJhHnKZH4JNqMq +QFwXzhwb140xCPh/7LAjkfZcDR+7KDNR2Tavy+mBG6klLJKGAdsuHZY4op5dAbWwIVQ CxKg== X-Gm-Message-State: APjAAAVVSC58k9p5VDUGpo0gyA/dB94Yw5FPFn8xXUHtkaqjJgaTCrWA Fb/kyO5CpzbBsrg/+okITD+8Aw== X-Received: by 2002:aca:be88:: with SMTP id o130mr2506821oif.122.1562063772431; Tue, 02 Jul 2019 03:36:12 -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.36.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:36:11 -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 11/11] perf cs-etm: Smatch: Fix potential NULL pointer dereference Date: Tue, 2 Jul 2019 18:34:20 +0800 Message-Id: <20190702103420.27540-12-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/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(-) -- 2.17.1 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) { itrace_synth_opts__set_default(&etm->synth_opts, session->itrace_synth_opts->default_no_sample); etm->synth_opts.callchain = false;