Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp764825rdb; Thu, 18 Jan 2024 20:08:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IF85iZc/ZeoCCVsJfQNv39XvGUKOx1GR7umFUTWMlzaAQinq9rHt0qo0tZaDL3NNjEbo8hM X-Received: by 2002:aa7:9302:0:b0:6da:b936:b312 with SMTP id cz2-20020aa79302000000b006dab936b312mr2064114pfb.36.1705637280182; Thu, 18 Jan 2024 20:08:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705637280; cv=pass; d=google.com; s=arc-20160816; b=O+tWSFCNMI549dg/YikU/fMuFNcY6JchN1PeC8S1X17nfZWhWf8FLTrPQ2B8DtyRPP N7fDR6dz70V/43czJGhttraCbA8nspai1/hO8Ip3UXpZllRya2AsYgjanwBzzykIiUEY szHWPXnJPvK+ZVmWTwMsH9TXTga2hcrDg8R7TGigMFXzzUTDwlVY0cSI5UUODq5K7v6Y wwg2UMJc3HbAZYYXjeC4kaka31QxjblE2BzkJIdedDfGzA072txBCDXi+to4rfGAhECN Ho9ATDq6azBoRMik3xAN2XTMR8w/N+cHWT8J0qRuHa0+/iu72jzyWmn1C0uQ05UVOuyW BPmQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=fJuoFbqpB3BxyKkLUIREOq/1ERSw0t31h7h1T9xvSBg=; fh=Bniw+6GSTGRfFyC55GB3Thz1GNqaKHZWIdADbDjMDXE=; b=ebSqCY/quiLppWFpXA95bVw6+dsLQOOgf02fOnOfSUGbHq4p9p9u4LJaoP5rtzEABy owGZLvL3Vmz+RS556PuBqKgYapjp1qdLRNmE8YkQKRAP7JCe7JKseJD5vN4YLIkoxbDf AdmnXkWf1toiWE3vkL6m9zeV767R4akUhhO6plmCC0Dw47fxcL6NDL8wh6v5s4L+Nzwe W75cZewrct5QkGDedZ4loZpybhSfFhw2wEW+UdPhycNTESrPdVKhNWNSM/W1flgq68mc 55/mETAq8SBGd9dy6raez18oJN/WpRKFLSeqt64XCCo7IuL9XfVv/4ffd2ZRlAJe/cqr vT7g== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-30757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30757-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u8-20020a631408000000b005cecb08c45asi2449674pgl.431.2024.01.18.20.07.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 20:08:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-30757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30757-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B0761B22A51 for ; Fri, 19 Jan 2024 04:07:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B04F346AD; Fri, 19 Jan 2024 04:07:37 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 664091870; Fri, 19 Jan 2024 04:07:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705637257; cv=none; b=YdB9b3yZYgzaksNytYxWU7eQUuaDm3Sw09MVTy6XYgyC0d+i10UNSknFQQKVbVk28zsB27pazJTrvPVCHVlPLfj8Rwic+cq4s7JEEGo2sAgHCak9/gvWQhohwNRUBX08lutRmFX/uA+U0NmHuIDEizVp49F1ssuUaWCHElZz9Hs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705637257; c=relaxed/simple; bh=EMVJzS2xUAq0Tked9+lQE9avM8FS5zcClqksRKRtOb8=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=N6T4x1KiWpXLPo0Rjl38ASuUpkby3JQfJvhwYG+S9G3chKHN/25rYrWd0jdJ8XhQuHclyAFhhcDuCvyrXlcm6d6YmZKnWoOElKnjw7Kp/spExp63b2GlWRmvNd73YRYbE+ncwujKzYg7wWy6U23c4t+aZL8qj9uf53m4O+AIAHk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4TGQzz43gzzGpq4; Fri, 19 Jan 2024 12:07:11 +0800 (CST) Received: from kwepemm600003.china.huawei.com (unknown [7.193.23.202]) by mail.maildlp.com (Postfix) with ESMTPS id 2E37218005D; Fri, 19 Jan 2024 12:07:32 +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.35; Fri, 19 Jan 2024 12:07:31 +0800 From: Yang Jihong To: , , , , , , , , , , CC: Subject: [PATCH 0/3] perf record: Fix segfault with '--timestamp-filename' option and pipe mode Date: Fri, 19 Jan 2024 04:03:01 +0000 Message-ID: <20240119040304.3708522-1-yangjihong1@huawei.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600003.china.huawei.com (7.193.23.202) When perf record uses '--timestamp-filename' option and pipe mode, will occur segfault: # perf record --timestamp-filename -o- true 1>/dev/null [ perf record: Woken up 1 times to write data ] [ perf record: Dump -.2024011813361681 ] perf: Segmentation fault Segmentation fault (core dumped) Debug the core file by using the gdb: # gdb perf core.3706841 [New LWP 3706841] [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Core was generated by `perf record --timestamp-filename -o- true'. Program terminated with signal SIGSEGV, Segmentation fault. #0 evsel__free_stat_priv (evsel=0x555ea56197af) at util/stat.c:145 145 struct perf_stat_evsel *ps = evsel->stats; (gdb) bt #0 evsel__free_stat_priv (evsel=0x555ea56197af) at util/stat.c:145 #1 evlist__free_stats (evlist=evlist@entry=0x555bf0dad1b0) at util/stat.c:215 #2 0x0000555befd425e8 in evlist__delete (evlist=0x555bf0dad1b0) at util/evlist.c:175 #3 0x0000555befd42785 in evlist__delete (evlist=) at util/evlist.c:181 #4 0x0000555befc7f547 in cmd_record (argc=, argv=) at builtin-record.c:4252 #5 0x0000555befd27700 in run_builtin (p=p@entry=0x555bf05acf88 , argc=argc@entry=4, argv=argv@entry=0x7ffc2696a920) at perf.c:349 #6 0x0000555befc68751 in handle_internal_command (argv=0x7ffc2696a920, argc=4) at perf.c:402 #7 run_argv (argv=, argcp=) at perf.c:446 #8 main (argc=4, argv=0x7ffc2696a920) at perf.c:562 It is found that the memory of the evsel is modified. The reason is that perf_data__switch() not initialized 'new_filename', as a result, it uses the on-stack variable. It happens that the evsel address is stored here. 'new_filename' is freed later when uses '--timestamp-filename' option. Therefore, segfault occurs in the evsel_delete(). 1. patch1 fixes this problem. 2. patch2 to optimize the process, check conflict between '--timestamp-filename' option and the pipe mode before recording to avoid switch perf data. 3. patch3 fixes the code style problem by the way. Yang Jihong (3): perf record: Fix possible incorrect free in record__switch_output() perf record: Check conflict between '--timestamp-filename' option and pipe mode before recording perf data: Minor code style alignment cleanup tools/perf/builtin-record.c | 14 ++++++++++---- tools/perf/util/data.c | 10 ++++------ tools/perf/util/data.h | 6 +++--- 3 files changed, 17 insertions(+), 13 deletions(-) -- 2.34.1