Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3101453ybi; Thu, 18 Jul 2019 21:03:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwhEIaAzD07c/rkoYI6H85khYDVVDpHd6080fGHuUOsi8MYFh1e0r5xCxPKZU5LJOqmsJT X-Received: by 2002:a17:902:7d86:: with SMTP id a6mr54360382plm.199.1563509017640; Thu, 18 Jul 2019 21:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563509017; cv=none; d=google.com; s=arc-20160816; b=TKC/o9UWnDK9kWcjc+JsnF2m+f9PI3w8zYFMnCBiGnC82YkJSVppz4swvDXYHI/K+O gbhAwSm7Yc25D2hfFgl46X0WHx9CLT5/jEDSGbtpvU41jTEqe6/aR9610NvYQnjZK21t hpa+GmHEcIHnDkqUInULq0F6dmMR7vtkoa8jQ16wWJ5ucNhpTmiRXPR7scA0gOKTydpP 80fhXniD0oegKnDL2UMcmzkQ6nEKuiyxH8v/k8JVxgnR9SDETaEOunmRfP3YPrOmdLeW Uk+kELnAcfxq3aQ+IqmHuPQDwdECvT/egnrSVNTVaXv7zfnb/bPScCSXl4fqymGxoeNf 4xww== 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=7FxFksnZ4spLflISKNm8DIWJszi2/fUbFh09xIemzGI=; b=R3rqr4G2P25j3TkyMaaPm58wXwnaRlbipwL6r83s67mp6EF0zpQHs8tDY3mJhmSzbN J1WV1ltYWoCCiPxCLL33HH8ZKcFaoNfh/pG5h+3rRca2pM873Ol7X53mNbbCb74xLiNR naCdNxI+0CtLobtg+0aXHBhUjcQ1Z3ah2kKWy+1Qzv7XU5RnCZKTBCuZvQj4Xn1UHkVx zbo2Qug8g2pr5k+etqBPEl10Im3nDbKIPSSZTYnuUuqPgkbSVvfcGdraeh6M0VNKxXCB xsK1S2mj3F8L/8SCZuk0zS8Qa2yGA8IcM1L9Un7dhJA/6pe+QU+dn4EB8HFy2HUHC4rS pMBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="0/ZDM53L"; 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 j190si2314755pge.92.2019.07.18.21.03.22; Thu, 18 Jul 2019 21:03:37 -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="0/ZDM53L"; 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 S1728503AbfGSEBK (ORCPT + 99 others); Fri, 19 Jul 2019 00:01:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:60952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729301AbfGSEBD (ORCPT ); Fri, 19 Jul 2019 00:01:03 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8D80421850; Fri, 19 Jul 2019 04:00:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508861; bh=VZYhGO+wZgOgOOzXf5CsdNH7PZ6O3JbGnuCqN9yB02I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0/ZDM53LLB52WVgdmEBiXHGDNc4YiNa1BWQ4K+BHQz0SESePHKTgybVOIflOTGhi7 PoeQFOw4BI+StAsUbxJtA8FIaqj1v2USRRqm3J3UvhhA+Tcu1dcmNi51absy+IFPmE WnaMApvBHDt8vY1GHUVSCe5NVtgiz5hqAbowcR6A= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Leo Yan , Jiri Olsa , Adrian Hunter , Alexander Shishkin , Alexey Budankov , Alexios Zavras , Andi Kleen , Changbin Du , "David S . Miller" , Davidlohr Bueso , Eric Saint-Etienne , Jin Yao , Konstantin Khlebnikov , Mathieu Poirier , Namhyung Kim , Peter Zijlstra , Rasmus Villemoes , Song Liu , Suzuki Poulouse , Thomas Gleixner , Thomas Richter , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL 5.2 127/171] perf session: Fix potential NULL pointer dereference found by the smatch tool Date: Thu, 18 Jul 2019 23:55:58 -0400 Message-Id: <20190719035643.14300-127-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719035643.14300-1-sashal@kernel.org> References: <20190719035643.14300-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan [ Upstream commit f3c8d90757724982e5f07cd77d315eb64ca145ac ] Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/util/session.c:1252 dump_read() error: we previously assumed 'evsel' could be null (see line 1249) tools/perf/util/session.c 1240 static void dump_read(struct perf_evsel *evsel, union perf_event *event) 1241 { 1242 struct read_event *read_event = &event->read; 1243 u64 read_format; 1244 1245 if (!dump_trace) 1246 return; 1247 1248 printf(": %d %d %s %" PRIu64 "\n", event->read.pid, event->read.tid, 1249 evsel ? perf_evsel__name(evsel) : "FAIL", 1250 event->read.value); 1251 1252 read_format = evsel->attr.read_format; ^^^^^^^ 'evsel' could be NULL pointer, for this case this patch directly bails out without dumping read_event. Signed-off-by: Leo Yan Acked-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Alexey Budankov Cc: Alexios Zavras Cc: Andi Kleen Cc: Changbin Du Cc: David S. Miller Cc: Davidlohr Bueso Cc: Eric Saint-Etienne Cc: Jin Yao Cc: Konstantin Khlebnikov Cc: Mathieu Poirier Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Rasmus Villemoes Cc: Song Liu Cc: Suzuki Poulouse Cc: Thomas Gleixner Cc: Thomas Richter Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190702103420.27540-9-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/session.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 54cf163347f7..2e61dd6a3574 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1249,6 +1249,9 @@ static void dump_read(struct perf_evsel *evsel, union perf_event *event) evsel ? perf_evsel__name(evsel) : "FAIL", event->read.value); + if (!evsel) + return; + read_format = evsel->attr.read_format; if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) -- 2.20.1