Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3800038ybi; Mon, 29 Jul 2019 12:52:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqy+hp3rrLpWnZ6yIW9EAUhvkW5tFINEygBSzcd/JqJPW6fyP8oML/zL6wbhiln1ECIAweQz X-Received: by 2002:a63:3147:: with SMTP id x68mr42518375pgx.212.1564429966596; Mon, 29 Jul 2019 12:52:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429966; cv=none; d=google.com; s=arc-20160816; b=H+MRZprBOVDK5y8tNwNix5jxUkHBCcB7qOcCHTDZyouik64ALvecK8mC1NZedDikhd acnmhpdy1p/svLmOkZsq2lov+U/BCMHqJyJPg1hNVI/7ZIH4ntH20SHJsUHER0igkfGS +R+YOFCtMl0g93qL5hL4cJV9Bl/qDVish/+F+wzz3eEt+m5dFW20JObJeWAFDRhouizb fsFMWHlOwLAIrV93EhNEmtuM4Jt9e7y5q3kjwwN80yMHDev4smSq29L5upU/n1PkIN+c IVuHlENaulWkEQ014HJTimHPe2Kek98GzO+ivkLi+sElOwJWdU3/nP3FL1zLc71vFy7p zdpQ== 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=ixzg+Sie9ZB33zApOr24JYZuEdoWObJ8xR6S+UDW5NI=; b=pHMbuhgwCedQoJhw889PNw+RdhbY27KQ4RdwCH+8FetSgSjzit8oQqxdrI4XWcF4Yp CX1R2RwW+Qj1m69FKOUsSTDnFr9x9uQIYfvrMlyTJFBUHGR0sG69ESTNzbi7hjFMEZlx ICQTIiSblgmIMnilg37IaDrcbOnjvrEakahRhQUIbdsUOAK0t8zedMfUX+tXfDbhVmfx L0iMgwdHIHSxokQvJAz4JfBAx7CZMWrRlFV2EGyl3iqVqbzrrTzhHg9wo0akKRQ7uVHT kOd8O7eFanhwxGhx7hvxHeCxgKYykN5IuqaxwPkL7Nh/7WEMl8hkZXV1fUe02v4PyBo6 Zl3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P0m1Giky; 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 j69si25437374pgd.589.2019.07.29.12.52.32; Mon, 29 Jul 2019 12:52:46 -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=P0m1Giky; 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 S2403851AbfG2TvW (ORCPT + 99 others); Mon, 29 Jul 2019 15:51:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:42586 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403846AbfG2TvT (ORCPT ); Mon, 29 Jul 2019 15:51:19 -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 8E6BF21773; Mon, 29 Jul 2019 19:51:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429878; bh=WC/j/sIjThtlobfzS6nVKzO7mZHYA9bZW6rokSFNWWI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P0m1GikyM10M2aFm7plIQWVIjAqqWOestowzb4NVULm5EjLajk4EyznbR6/FW6Odr OuPcU0kFaYbZaQtWFRpPHhhUhBG6dMkFIWYZfKXxtW5RPv2z7Alr744rX5wflYJukz +xvbr/6S7KvxE5Z0392m/Jg8DiY4zU7FlK77wg7E= 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 125/215] perf map: Fix potential NULL pointer dereference found by smatch tool Date: Mon, 29 Jul 2019 21:22:01 +0200 Message-Id: <20190729190800.952187231@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 363bbaef63ffebcc745239fe80a953ebb5ac9ec9 ] Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/util/map.c:479 map__fprintf_srccode() error: we previously assumed 'state' could be null (see line 466) tools/perf/util/map.c 465 /* Avoid redundant printing */ 466 if (state && 467 state->srcfile && 468 !strcmp(state->srcfile, srcfile) && 469 state->line == line) { 470 free(srcfile); 471 return 0; 472 } 473 474 srccode = find_sourceline(srcfile, line, &len); 475 if (!srccode) 476 goto out_free_line; 477 478 ret = fprintf(fp, "|%-8d %.*s", line, len, srccode); 479 state->srcfile = srcfile; ^^^^^^^ 480 state->line = line; ^^^^^^^ This patch validates 'state' pointer before access its elements. 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 Fixes: dd2e18e9ac20 ("perf tools: Support 'srccode' output") Link: http://lkml.kernel.org/r/20190702103420.27540-8-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/map.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index ee71efb9db62..9c81ee092784 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -470,8 +470,11 @@ int map__fprintf_srccode(struct map *map, u64 addr, goto out_free_line; ret = fprintf(fp, "|%-8d %.*s", line, len, srccode); - state->srcfile = srcfile; - state->line = line; + + if (state) { + state->srcfile = srcfile; + state->line = line; + } return ret; out_free_line: -- 2.20.1