Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3799996ybi; Mon, 29 Jul 2019 12:52:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4xI0CAaU65dwojttLQvz8WLBMmc8eIQ/vD6d9zrdh/XW5HExJhfB5fqhVEFUo0+VZ/OBB X-Received: by 2002:a63:ec03:: with SMTP id j3mr3649988pgh.325.1564429963235; Mon, 29 Jul 2019 12:52:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429963; cv=none; d=google.com; s=arc-20160816; b=QlPQ/ELutsqsfHRGpGLCkobJkYpzC7gf/VMCxzd5t27p6C6Yl0w9VkDgLkRYsmQ0lA jOcEBQXcPjquheCMocvgPrNkpn+yJhDOdgrNKta8+0ej8aQpEPuUgdyx4HdnWXNr2yM9 NKp3rq8c42VtJGomRP+GzCt/DT0UwZ4BXfxfMRnMnrkEvLbV7R5a85DWmRdEh+5PU0pK HH/6mcIZik4bOWYNJ1u+hWHWzXjdglVxZw/PZyNExVucO+XYdzgnB/Aat0+6iQVVc1pT 5U8sQSj4pxGiTBryEb/AZ+1CzVJFiclohC85QmCG7f+wTYKW1zLUSh5BzxBXYJ0cpMsE 3a2g== 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=fQqvZtGKT6dz6UPlTuYhiZE47VIHFL4T5o2LowdSbE8=; b=Bsz83c5SdO9yukZyf7igbMLWu0QuhY5qwR1bXI7VbSIX5UF8UyRRIfEg5YG5QUdb/j XbqFymcmh8FkNINNY2sujG+TYyVGQerF8B1H56qzxBMy4l0M2gZWtoal/7BzYoxGhNeq pY44m8uOiXBjf9falqPtcQCnghOaEdRspukAjMLHKGKKUjE0g1TS3BJGHoRJ4mR6xAsM O2sToh93Knlp50/RLgwvBbAy+AMJxqPXeyXdrseg5FWFsw303Jo2B8GriyVml5Xs3Nn1 73buDnDVDXBO08vL/URIZzZcs8vu4s6LhJ6B4BnclCkKHvLyQW3fnX2HuMBD7XmN7LzZ R5WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ki67qqRe; 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 u128si22530633pgu.389.2019.07.29.12.52.28; Mon, 29 Jul 2019 12:52:43 -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=ki67qqRe; 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 S2390519AbfG2TvR (ORCPT + 99 others); Mon, 29 Jul 2019 15:51:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:42488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390430AbfG2TvQ (ORCPT ); Mon, 29 Jul 2019 15:51:16 -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 04F32205F4; Mon, 29 Jul 2019 19:51:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429875; bh=PDKRh3yLK17oXfBPui/lkXXZPI+YwZkLMHVsggm9pio=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ki67qqRe2WKDPD0ZG6UskLmM4UXr6AgsHu4tvqbJuUGrt/6vCkmUDcZRIKGCjupLb VYELJ8ybHE4pxMxQVQRD04qHyOj8ibU2K1zqVnqfC05W/fukxEZ/NeJUL263EdIEay ISx9Uf76OwQwyy11zmS1DY3ah/+MkUIA8d3tFHAI= 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 5.2 124/215] perf session: Fix potential NULL pointer dereference found by the smatch tool Date: Mon, 29 Jul 2019 21:22:00 +0200 Message-Id: <20190729190800.716035519@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@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 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