Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5925124rdb; Sun, 17 Sep 2023 20:06:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGChQ50LXB4kc8zKzaFOsCJDkQjgJRTHP9ns6W97dy1lX3NWVQYHGxHZQNrhMs+3wi0A1k9 X-Received: by 2002:a17:90b:193:b0:26b:4a9e:3c7e with SMTP id t19-20020a17090b019300b0026b4a9e3c7emr7212562pjs.4.1695006388241; Sun, 17 Sep 2023 20:06:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695006388; cv=none; d=google.com; s=arc-20160816; b=Yw5k7dN7DdqFvDJYGAijZyE3CS7rPX/dfpFi0vDVDYMlbIgKJRgaPr6Z/peHPOeBHt odlS3JdtMBRm9qcEn2GreBAdXxAUpMBEkjRAegSawiXeVbgTixKVvfoRBGyK5GVs9+sW HxalI3L8tOFEa498EIaurSdolILYYqMQyx85wnbGxK80gpSViHbV+W2BF89EhMPvmcgf h3hnSBf70BxywI2jcgPFRNVoxiNaCbd0ZcG3Fb0VqeJ1hP69pJna0GIz/Ef20PWz0thT oixqxYeyKmuo9wy3QmbZxMqAgdZwwfH+d9PQ3hmiMsCeWkXVYXN1NToVKcNmzNvOWWy0 Z5Ww== 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=MGyPRekiivA7+qjx0UQDO6+qC8+/40uRHWR/mOOYJK8=; fh=JXx1mv1fB650HoTkc5GIgpDQ5Ey550GcDyaNZ/s6bYc=; b=WkSECsipX4fiSbYGPZ2YmsBvCaGtYca8LzZKhlrSy1ZwzLKrxR237oSjHIFvzO/jc6 /ZorOH17kk1BZUucQKDt8nZiO3eGAfS+B09pZJXMUCPmiCGaKGCo0BLLtmArgZSuOYUQ YnejOhLX444p6O5C/XVFiF+KAKk3aXv1S3yzw7J+YB/zkEDIx1GJaiZjjHbgxgOoA8qk PgQEjBOXiJgwxgkbyhkWs1vgSWhmJ+7MAizXZDW/K6WkuMvEkYCSSytQxrNDconaXs9c NvbHsQyLrimmBT1A++5vXR2HSLhM8fTnoWAiGoIcbRUN1Zrwf4TT/+FYYMPUvBWZEtA0 0PSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id d18-20020a17090ab31200b0027660aac61asi1255204pjr.114.2023.09.17.20.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 20:06:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 817DE80E73D2; Sun, 17 Sep 2023 20:05:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238324AbjIRDFZ (ORCPT + 99 others); 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 17 Sep 2023 20:05:56 -0700 (PDT) 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