From patchwork Tue Apr 18 15:50:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 13215927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45834C6FD18 for ; Tue, 18 Apr 2023 16:46:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=3WgRGfDPrVjNCIxnj7MVUWXsZNium7GHgSR+cKWyqzM=; b=0koH2qx4a8vGKu u2A1KXI3xJcY2YNwnMK94e87tPX4Hf301paq56oerAhmcVm+GZrfLjYjhN3MRZS5VCJBF98e9q8hW o8mnqu0wrhKlbvB/P2IXKz5Bc39xxBfwMNxhAQVSVUFVeuSLeBzWS/IaM5yNkUDRZ48I/kxbVIfGm 5PNlYkLYqdDx4wYzG6MIJhrItZUIz79gDwtBpGGzLztHOQXo2jFWEgL1iCep0Zmiet5KsoYvZaV1q Xo87uaXJkvXsyqFIHi4cNJuHdXbh/QOkLZZ1KfmE2qtjzRKU48wVr0367xrttI5Ch8KV/CsmjWvc1 SEygQSRAnqRkv0eFeHBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pooSS-002oVh-0T; Tue, 18 Apr 2023 16:45:32 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pooSQ-002oVV-33 for linux-arm-kernel@bombadil.infradead.org; Tue, 18 Apr 2023 16:45:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:In-Reply-To:References; bh=75Y2asSfVVX0cLT6qh9vkW7tjqpA2YipDwtQ8Nj/qOs=; b=F3mGvq1Khevf9U9X/hT5B/DzMd 0rUQe0Ks5fBnoym3UqAa8heNeEza1narLcbpIKnpKBfdhV3tT4hhGKs82d/uqGYhNwJUop0JUqa43 eIS17d2FDTt0moVZWqCdS7KEJzorMdILyErmWbKwaZTlwdIzi46I35A1zyQRURyVq2ndKYke2mwmk tIrgGwK90jrYtMRjoZ6sBTYKW+56eV8JtVFAY5DGcklzm/3j21fRD6DPc8Z5cJllWQ7aAz5M+GVYA 74daXjgTHLELIut8sncV0iqNr7ZQNvIiR1CYZYcy7CRb7r5w8ktYJxw2VJMWPdRdPDxK4ymvgE7ut 2jxgZWDA==; Received: from [187.19.238.117] (helo=quaco.ghostprotocols.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1ponbF-000VcG-2W; Tue, 18 Apr 2023 15:50:34 +0000 Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 0A84F403B5; Tue, 18 Apr 2023 12:50:29 -0300 (-03) Date: Tue, 18 Apr 2023 12:50:29 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers , James Clark Cc: linux-perf-users@vger.kernel.org, Linux Kernel Mailing List , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] perf tools: Fix use before NULL check introduced by map__dso() introduction Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Url: http://acmel.wordpress.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org James Clark noticed that the recent 63df0e4bc368adbd ("perf map: Add accessor for dso") patch accessed map->dso before the 'map' variable was NULL checked, which is a change in logic that leads to segmentation faults, so comb thru that patch to fix similar cases. Fixes: 63df0e4bc368adbd ("perf map: Add accessor for dso") Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ian Rogers Cc: Ingo Molnar Cc: Jiri Olsa Cc: John Garry Cc: Leo Yan Cc: Mark Rutland Cc: Mathieu Poirier Cc: Mike Leach Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Will Deacon To: James Clark Link: https://lore.kernel.org/lkml/ Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 7 +++---- tools/perf/ui/browsers/hists.c | 4 ++-- tools/perf/util/sort.c | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8fba247b798ca307..006f522d0e7f6a18 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1075,8 +1075,7 @@ static int grab_bb(u8 *buffer, u64 start, u64 end, return 0; } - dso = map__dso(al.map); - if (!thread__find_map(thread, *cpumode, start, &al) || !dso) { + if (!thread__find_map(thread, *cpumode, start, &al) || (dso = map__dso(al.map)) == NULL) { pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end); return 0; } @@ -1106,9 +1105,9 @@ static int map__fprintf_srccode(struct map *map, u64 addr, FILE *fp, struct srcc unsigned line; int len; char *srccode; - struct dso *dso = map__dso(map); + struct dso *dso; - if (!map || !dso) + if (!map || (dso = map__dso(map)) == NULL) return 0; srcfile = get_srcline_split(dso, map__rip_2objdump(map, addr), diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index ab70e5f5fad236e5..69c81759a64f938f 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -2499,9 +2499,9 @@ add_annotate_opt(struct hist_browser *browser __maybe_unused, struct map_symbol *ms, u64 addr) { - struct dso *dso = map__dso(ms->map); + struct dso *dso; - if (!ms->map || !dso || dso->annotate_warned) + if (!ms->map || (dso = map__dso(ms->map)) == NULL || dso->annotate_warned) return 0; if (!ms->sym) diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index f2ffaf90648e469e..31b1cd0935e277ba 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -1568,7 +1568,7 @@ static int hist_entry__dcacheline_snprintf(struct hist_entry *he, char *bf, if (he->mem_info) { struct map *map = he->mem_info->daddr.ms.map; - struct dso *dso = map__dso(map); + struct dso *dso = map ? map__dso(map) : NULL; addr = cl_address(he->mem_info->daddr.al_addr, chk_double_cl); ms = &he->mem_info->daddr.ms;