Message ID | 20230918030304.24832-1-yangjihong1@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2405110vqi; Sun, 17 Sep 2023 20:06:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGFXMgwzl7/BOjjuPTnNwlk5v1qdAzguDzhIvTEE6DRAwRE1g8j70gTDx2hE5CNz//SaMP8 X-Received: by 2002:a05:6a20:974d:b0:148:82d6:aa16 with SMTP id hs13-20020a056a20974d00b0014882d6aa16mr8156664pzc.25.1695006378749; Sun, 17 Sep 2023 20:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695006378; cv=none; d=google.com; s=arc-20160816; b=UYqgsLGTjXh+NNtSnsgfaT7LG60R5U+Lx34I9v2vSWF5vOE16Nemx4oMCNP80HQeF2 Ndnu7g3WPQTd//U3qYoS/soi+y8DGK5C02A24xITggWO7/G2j1HcTMVVflUzbc5jvsik ZTD+GZWmjQI7G29r8DV7Ls77gKvXwHK1ldI+2ymBzKZJawr/+gvLfa2kGOQ5A4z6sbSc TjNMk6rnvmYz4qbFXnoSqJgrmc/Zz7PX4oA9rwU1X4FiikGOslVdsGKnwjo/TgzI2M2U ClYiyr8VyIjaFwUCkbzmCXVKi8+I6aVRo6p7YblbzpIj2lNNZkHLX1Ay8+u58Fqqq7HB BpMQ== 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 Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id e66-20020a636945000000b005774c90073asi7074539pgc.320.2023.09.17.20.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 20:06:18 -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 80AEC80E7137; 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 S238352AbjIRDFZ (ORCPT <rfc822;kernel.ruili@gmail.com> + 28 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <yangjihong1@huawei.com> To: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>, <mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>, <jolsa@kernel.org>, <namhyung@kernel.org>, <irogers@google.com>, <adrian.hunter@intel.com>, <linux-perf-users@vger.kernel.org>, <linux-kernel@vger.kernel.org> CC: <yangjihong1@huawei.com> 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: <linux-kernel.vger.kernel.org> 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) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777343008601724182 X-GMAIL-MSGID: 1777343008601724182 |
Series |
perf jevents: Fix segfault in perf_pmu__find_events_table
|
|
Commit Message
Yang Jihong
Sept. 18, 2023, 3:03 a.m. UTC
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
<SNIP>
[ 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 <yangjihong1@huawei.com>
---
tools/perf/pmu-events/jevents.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Hello, On Sun, Sep 17, 2023 at 8:05 PM Yang Jihong <yangjihong1@huawei.com> wrote: > > 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 > <SNIP> > [ 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 <yangjihong1@huawei.com> Thanks for the fix but please see https://lore.kernel.org/all/20230913125157.2790375-1-tmricht@linux.ibm.com/ Thanks, Namhyung > --- > 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 >
Hello, On 2023/9/19 7:55, Namhyung Kim wrote: > Hello, > > On Sun, Sep 17, 2023 at 8:05 PM Yang Jihong <yangjihong1@huawei.com> wrote: >> >> 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 >> <SNIP> >> [ 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 <yangjihong1@huawei.com> > > Thanks for the fix but please see > > https://lore.kernel.org/all/20230913125157.2790375-1-tmricht@linux.ibm.com/ > Uh.. no notice that there is already a fix, please ignore it. Thanks, Yang
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++) {