From patchwork Tue Jul 9 18:31:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 168764 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8897680ilk; Tue, 9 Jul 2019 11:33:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJOrZ6FxDqmmlP4E1BdYHFdUFgh9DChEQ+IGVRXCwBpbThlzyH33s61dpLlSWiCq1Fy2Ga X-Received: by 2002:a63:e62:: with SMTP id 34mr29816792pgo.331.1562697211375; Tue, 09 Jul 2019 11:33:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562697211; cv=none; d=google.com; s=arc-20160816; b=u86abRgXeamUPkGn1QuQIqLLKorFgTQ5okaqaYVvDfqQeFA7NW7E7xgIp4+hvOshDL GAxLubsbmbSCqCI5T8hq7Jt7uPGrLscApMRhJHNypgGo2vr75kcF1wggGs/Slc8HdWf3 cGoKbAooxPvKgntZtEXBi0ZNJUl2S/wRS1P1K1BNVbaMDsNd3uqo3MpYHknzMm2xDEXf 8GvXB4k0l/qVbuhUvQ37zAEg6YoYVZJLTJs0Isqgld8PDDCKdHPyFOxg3LLaXF8hEetT DpEu9WZiy6S41MajZ1antJnEJDuNO3nvRiKEsIi06IFh5ul0Tefv4Vcbpl5dOFJSWhUl hYIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bzhnTvp8j/QqUEvjbbPtxZb1Tui70yPg4LPGUwU65hM=; b=qVIVlfJ00ufjM0KlU5m6V3apI6yKphcBvS7CMxPxbmfbsVq+WAZLIuwftxOwna79pZ 80IvtOe+X6zMXyKDe+DvI4VaLcP/6SudbI6z2GzFeZfinkuwTiMam5CKi+TsO0vLW/2c mKbK1OiJ5TLYz49TmJ3hJ08ZZljGqBgBXM1WH1/MQmuCzrEZatl48iFUPJNEmaZi1hKQ QD0jDCCYkFbEqkUZxfNKUaXnmUwKQqnnhctFRUVrNXb/ILkhDeCI2mg/Lkn41USzxQbk cels/dGromQ5exnvc1wKBawrH9j9itjhomgzuvl7tdsnslAHFWfsA0Q5pj1pHBPhvQDX aj5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wKFilR8Z; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i32si3349989pje.44.2019.07.09.11.33.31; Tue, 09 Jul 2019 11:33:31 -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=@kernel.org header.s=default header.b=wKFilR8Z; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729348AbfGISd3 (ORCPT + 30 others); Tue, 9 Jul 2019 14:33:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:55246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727027AbfGISd1 (ORCPT ); Tue, 9 Jul 2019 14:33:27 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.35.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 65E3D20656; Tue, 9 Jul 2019 18:33:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562697207; bh=yAP7lLk8scvs8z72JtKyaa3K2i32Wc49Nr1SyOz2l3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wKFilR8ZSDMQ1SkWeWA3Li198T/E6FamZeMgPqVQ6ToJ38qlAhi99VtfYYPROyasb pjvJQfxgjUiT2IbDYEICDj3cffL3tGgoY13Cm6D2Nypc9DXTkwOlFTwt3t6x5WgO56 9L37svk73hrJY1BnddgDill4IWSC8nS4stvKIm8U= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan , Adrian Hunter , Alexander Shishkin , Andi Kleen , Jiri Olsa , Mathieu Poirier , Suzuki Poulouse , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 25/25] perf intel-pt: Fix potential NULL pointer dereference found by the smatch tool Date: Tue, 9 Jul 2019 15:31:26 -0300 Message-Id: <20190709183126.30257-26-acme@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709183126.30257-1-acme@kernel.org> References: <20190709183126.30257-1-acme@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan 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 Acked-by: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: Jiri Olsa Cc: Mathieu Poirier Cc: Namhyung Kim Cc: Suzuki Poulouse Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190708143937.7722-4-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/intel-pt.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) -- 2.21.0 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 |