Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp5468446rwe; Tue, 18 Apr 2023 07:16:54 -0700 (PDT) X-Google-Smtp-Source: AKy350bPrxfjX6CAYkD0dY6kTVErACCsjmKhlOK0APotSOnbNd77iToyraIbYfTZvVdOSxcgsPDH X-Received: by 2002:a05:6a20:3d03:b0:ef:4321:a8a4 with SMTP id y3-20020a056a203d0300b000ef4321a8a4mr11615990pzi.44.1681827414231; Tue, 18 Apr 2023 07:16:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681827414; cv=none; d=google.com; s=arc-20160816; b=T7ndns/HgNiDHhUIZWAMRSxVrAzgafy6Km1RCoJZza7cf/Qt+R4FpwCoB8uUwl9Xo9 GmegNCLkk3Pr9KigZHWpcLSxzYJGHMM5q0cmJ6OTag1hVfW3nR+p528Jv40JaSvv6AZf VeLEgJqx2qP2qaQkfwvo7fgl0LOZhVNmtDOvHouReObWEcRU7HSpe381dBcDvo681ugg wTAxU2VvIzuCq6N9Q1XFB4slqRqFGyCC7XzBvIqkv/PqlphUdGGP/y/34EyKkUEh5S0B Wl74LNKjkMDMIQ8nkG4pUXkdGrKncBsa02li2yFtSD+kf791qKFntwRsPAd9rvIapXUR xevA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=R46KoWDvQzHUehXcEPBc5BmKNJoTcMECyLaE/p4vWTI=; b=Lua7D2gkXKGDmdRdXBQGJ7ruwqPV+gAYBTelmfv/LI0nvUUt52vkL26DKYe4eA8Vai p8Ocvy7ripegky37s+A9xIAOgfISCCNTIwUhTzdHTDVQi637ZMR1CcjnXNsy5ojG8pYz UnLetNHmjqjfUDgae4S1s3QYOHIMPRKFV3XxPGF3NpIB4vF6J11kbVcCpw2E7coAXMM3 Y+T7ijviYNUk3BUhb5sJ6rSvF4mP35Avl9Z0oNHhV3KCh+jlPWhnwAvEt7DXd3713qM8 hb9PtNhumkwVAxYE647Nh50tArUp8w0UV9hz7csubAIor2DWt92YgGqlsTOs8QIX56WH a/lg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 4-20020a630704000000b0051f349be47bsi1576477pgh.75.2023.04.18.07.16.41; Tue, 18 Apr 2023 07:16:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232286AbjDROMf (ORCPT + 99 others); Tue, 18 Apr 2023 10:12:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232254AbjDROMa (ORCPT ); Tue, 18 Apr 2023 10:12:30 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 372BD146E7; Tue, 18 Apr 2023 07:12:19 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 468C12F4; Tue, 18 Apr 2023 07:13:02 -0700 (PDT) Received: from e127643.broadband (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E7B9B3F587; Tue, 18 Apr 2023 07:12:15 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, acme@kernel.org Cc: James Clark , 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 , Ian Rogers , Adrian Hunter , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] perf: cs-etm: Fix segfault in dso lookup Date: Tue, 18 Apr 2023 15:12:03 +0100 Message-Id: <20230418141203.673465-1-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org map__dso() is called before thread__find_map() which always results in a null pointer dereference. Fix it by finding first, then checking if it exists. Fixes: 63df0e4bc368 ("perf map: Add accessor for dso") Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 103865968700..8dd81ddd9e4e 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -885,9 +885,11 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u8 trace_chan_id, thread = etmq->etm->unknown_thread; } - dso = map__dso(al.map); + if (!thread__find_map(thread, cpumode, address, &al)) + return 0; - if (!thread__find_map(thread, cpumode, address, &al) || !dso) + dso = map__dso(al.map); + if (!dso) return 0; if (dso->data.status == DSO_DATA_STATUS_ERROR && -- 2.34.1