Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4112098ybi; Mon, 29 Jul 2019 19:31:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqx2E72YkUKSGWffjqTZmmeZ9XiJCcEkPqJkB86cUDw4whjQZ2CsIvBYWXjnTUj/AwhUGEt6 X-Received: by 2002:a17:902:9a42:: with SMTP id x2mr114208036plv.106.1564453898829; Mon, 29 Jul 2019 19:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564453898; cv=none; d=google.com; s=arc-20160816; b=bPWaxVAfsh3z3wKSbV0zevZaWtJrYJzrW/S6VBQZX0++nKpT4eM01tTjcc0yvQrksy gbujp7/az9+/5DoZyIZg/e5q17vbmzaVL4PluHUZSyYK42wmNHn/5K2InFBx1JwuSZRx vAC89b3Uk8lZw8qlucwUbFdfsYeeAx7H3nRUhhd/70Dp42ZUmTcIYyZ2GHRPHRBl2nqA v5Io6lPOvW+q1blXcneTkxUnVFzLnkgpll7g5NkOYiZI7sI7YzcQhHYx5MaR9u9SwFBb V+PEnFIKHN98mened7B58Urq4ekZDbp+UJspsU3NHoXBiguMtUoU2mKDl20V2oBbHE61 NGtg== 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=qcibXj+iJbeVAcMqlYtGAZd2UumhA00kuyZbCntKEoU=; b=j3onf3k7dWIHhe6wbKz928XDFAn0G86vbBnn+YpbmZNAlf1Ibt+APO9XGx4NwRvOw3 H6LxXyX8XKn9ty74vYt+3Oi1fmijccISYYrhX3j7QcYAcGvVw3GYrO5CBVBDmyIulbhk SzbTRjYhpqmEnEgHJiWiiFzUxABk2+iO3hk8W288SyQgMymZX/kMnVfuwrTf6edPI9Ik GOMWGvS6jQC1Er0VWUmQd+boSFJaNplFqSvds+1ZJ+UiNQDH0rVzCzIfJxRrVVfsNc/t 2Dp76w2YI9N2KlHy1RUmz3s3BlGttrpRfazJWk6CnrGlltS/PTIQCmKUljCCj9IcuOar QyMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Yn6qj5pD; 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 a10si29152847pff.277.2019.07.29.19.31.24; Mon, 29 Jul 2019 19:31:38 -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=Yn6qj5pD; 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 S2389527AbfG2Tmj (ORCPT + 99 others); Mon, 29 Jul 2019 15:42:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:58436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389509AbfG2Tmf (ORCPT ); Mon, 29 Jul 2019 15:42:35 -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 60DAB217D6; Mon, 29 Jul 2019 19:42:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429354; bh=3dBqoLX1MdZnGh9qolzsC9YWNOT/TRcQp7It1oiIhRE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yn6qj5pDUquT+gUYpqAnTvzJELHD4wIk4xzXNeEADcUiLA+lwbUia9vJhIzEPeRRV frAbAajWdLgdHRDObS8TykZy/sUwqxdq0KafMBqb/6DKSGBod/vd6X0FGwqx0BBpTv 2krGZql9B0UrYaCuLp6vH1SOEx1TcR8igkB3ZLmw= 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.19 070/113] perf session: Fix potential NULL pointer dereference found by the smatch tool Date: Mon, 29 Jul 2019 21:22:37 +0200 Message-Id: <20190729190712.209366309@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190655.455345569@linuxfoundation.org> References: <20190729190655.455345569@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 11086097fc9f..f016d1b330e5 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1141,6 +1141,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