From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D507CD37B4 for ; Mon, 18 Sep 2023 03:05:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238377AbjIRDFZ (ORCPT ); Sun, 17 Sep 2023 23:05:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238169AbjIRDFD (ORCPT ); Sun, 17 Sep 2023 23:05:03 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49F10127; Sun, 17 Sep 2023 20:04:56 -0700 (PDT) Received: from kwepemm600003.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RpqKf1S4cztSWF; Mon, 18 Sep 2023 11:00:22 +0800 (CST) Received: from ubuntu2204.huawei.com (10.67.174.22) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 18 Sep 2023 11:04:33 +0800 From: Yang Jihong To: , , , , , , , , , , CC: Subject: [PATCH] perf jevents: Fix segfault in perf_pmu__find_events_table Date: Mon, 18 Sep 2023 03:03:04 +0000 Message-ID: <20230918030304.24832-1-yangjihong1@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.22] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before caching the JSON events table, perf_pmu__find_events_table() need to check whether table is empty. For example, AuthenticAMD-15-6B-1 is used. The matching events table cannot be found. As a result, a null pointer is accessed when caching JSON events table, causing segfault. Before: # perf record -vv true DEBUGINFOD_URLS= Using CPUID AuthenticAMD-15-6B-1 Segmentation fault (core dumped) After: # perf record -vv true DEBUGINFOD_URLS= Using CPUID AuthenticAMD-15-6B-1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.005 MB perf.data ] Fixes: 7c52f10c0d4d ("perf pmu: Cache JSON events table") Signed-off-by: Yang Jihong --- tools/perf/pmu-events/jevents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index a7e88332276d..72ba4a9239c6 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -991,7 +991,7 @@ const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) } } free(cpuid); - if (!pmu) + if (!pmu || !table) return table; for (i = 0; i < table->num_pmus; i++) { -- 2.34.1