Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3815914ybi; Mon, 29 Jul 2019 13:10:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwIigKJOAVvXtw/owKzaWpwSui8A35+AHCLJ3kXDmtf+uEZkO9kfY5CjxWEmteWbW0gKm4p X-Received: by 2002:a17:902:1a6:: with SMTP id b35mr15672663plb.190.1564431041036; Mon, 29 Jul 2019 13:10:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564431041; cv=none; d=google.com; s=arc-20160816; b=qwUGM5eBBq2NpFpvoVlGwXoxLaUwq/XY2OxKASd1g1CVN1lphNhMbcI+7/6CwrgQ27 Q4UpDI3D//CPEGZTx184SbaKVssfUm5CmlbExfbp49h2Aj2eyBNtMV3GHed30YwqIuLu o6PgIJ/pKTuQiMQJtGMo3hH5YMVyU88zgX4IZ/qRlIa7thlUtRa1GtDQ9PcuHANJid9N +4lCRfNqJPx+YYqYtqN2EFjDVCfbr4F3q5E5gWcBGSqZyxyYcHc4W5Dz3GD8GANnwf6e j0GQY/pLRqEYiffczuef8FvaaUiYch/DSGsLNtV9wE1PjVXCL1j26Oh3yWyVeseZtRwO +s7A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=grExCxsNn8ujbI9QaenBWYApbsKYg5NrlyH2HP7F6Ng=; b=vISNvBM3wMAxq2uQZtAIxJ81mdvf4yXhuvrxVIDPSSo5Mrl11SnIOu1FiRi9toG4pg Acc5G1vjyxJjR9X71S1fYfBJaAd4xtjcZSzt7tAuMryhKdSLzF2gJ8zk+6a/+ujjpUwZ MWZgsZ2ujocuT5kR0xD7U9zoQSWGBWKp3OaKdY55BKa81ybbNDjPTOVzQPxazVRuuRbO 4nIuUmgMC6o9VM93ZJe/q01VNKwEdAs4Qc4ab5k/FmGn4Po/URUO2/L7/jmfpRP4jp6J S5HjoYV+2iVDnocWfWfPzzox4GiMUUUQodpS425oFs9uK3RHZWrGije6Uf5bizSObXep hHbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=r1JaKua3; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u191si27564025pgd.281.2019.07.29.13.10.25; Mon, 29 Jul 2019 13:10:41 -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=r1JaKua3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730087AbfG2UJM (ORCPT + 99 others); Mon, 29 Jul 2019 16:09:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:51724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388246AbfG2ThK (ORCPT ); Mon, 29 Jul 2019 15:37:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 33FF320C01; Mon, 29 Jul 2019 19:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429029; bh=LCyK2eokxpU5MSXIvt5PbkB4klob3f7E14ACJLAaUuE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r1JaKua3Kf0fsAgBed6/hLcAzXxAuwSNvwFOSu6FZU6wB9iWf4NJ6b+h/Em24dqlp 7AB+LZ3htZBP7GZytdut8mN3VjsJoia4UbTNlETVH7MHEAOWT7Zwf5TkctQmIHbr+A CE+8h/fJNy2r487YbLX+88VumpfiGuWpXdIv8LZU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, 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 4.14 261/293] perf session: Fix potential NULL pointer dereference found by the smatch tool Date: Mon, 29 Jul 2019 21:22:32 +0200 Message-Id: <20190729190844.400943737@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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 da55081aefc6..c49e8ea1a42c 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1145,6 +1145,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