Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3612053pxb; Mon, 21 Feb 2022 01:48:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVpoKgoASQdGm0FpzytCiJNjMioR+0fAEoReG7PoMIcUoineQ4OBIikJ2Rvd8YHEnS2zRa X-Received: by 2002:a17:90a:7e16:b0:1b8:2c11:73da with SMTP id i22-20020a17090a7e1600b001b82c1173damr20725720pjl.156.1645436910289; Mon, 21 Feb 2022 01:48:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645436910; cv=none; d=google.com; s=arc-20160816; b=Q3nrxzh57zhM3xNQQ/zunpZU8eYyEcXYMYJ2BEzT7Wxohw7PeZrxfTn2O2A9hiBl8Q xs6j/PLUsFdyCYBIna+3AaLKkT8Zliol96bouHxGB6Mw+rw4kh+BNpt43uhxYbW8ps/u cYqCIgAiyYBXVLBnZkYUvItfYnwEFeQqKn1jCpMrjWEXg3x4tFaPVxRbxwmHekb+Qgf4 vL5+RcKU70KGceIdEoFSbyFgARzW9P+FZOS9nYavWAVpNXR56jHIt5S/f7LhLlsqpPHU uYYOx5w3eti1F2bZGX7YvCWNZNoLo80ki61lhkfiQUjuo6EjC19jLOXZelba00aXjd0Z O3ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=quD5U0AaB7dwoV+0MYVxL3iSYkmAfbQXI74kd2LRgxs=; b=vAVnk8x/ti4x9YVUAWSzleQ35KSOmudjHoaDaie5Zp34ecmDdY6lpe1zQnlBrEbtqb ppNV5QEqFVNXF2SGVEDzs3Xbzb3tVz7rvuYXwPXU3GPUS23Zbw5wbYyGy1opTMgYqsh5 5l/aey2E0XMChYVu+K5d+ZVn1efh7/E66vlBHOEAx2JN4yy9jZS83W2t0f6MR6pWgzNR HZ+76/RWZbk3KkvgrM4Q8fODsR8i++G6Lq1vfc+GttmPlgVpXxZkPdn2derxDd6OAqqI AFJcr/OcJ11NfdqEe3MK7EB4IA3MFm7Bhyn8stR45d350PfFULxGc/eCMBfX47ZINZ4n WvPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FJh2EnQb; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z2-20020a17090a468200b001bba4104bccsi5990537pjf.87.2022.02.21.01.48.11; Mon, 21 Feb 2022 01:48:30 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FJh2EnQb; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245213AbiBTWqn (ORCPT + 99 others); Sun, 20 Feb 2022 17:46:43 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245209AbiBTWqm (ORCPT ); Sun, 20 Feb 2022 17:46:42 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D23031DF2 for ; Sun, 20 Feb 2022 14:46:20 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id p14so28310195ejf.11 for ; Sun, 20 Feb 2022 14:46:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=quD5U0AaB7dwoV+0MYVxL3iSYkmAfbQXI74kd2LRgxs=; b=FJh2EnQb6wIBt+GjM+HhsEm/C3WIeRZPNBslUNVSFk4JszVoR7o5PmtLVr6wXgUGZc KlKLAX1aYkH7zSMxAva6h6rHy3Hms28iAftln6wGI+iH/snTZCWROADWkW3F+THSo9/B zsteKt30WbSI2IJpMVjVFY0KdYvsO0hKL3XdsfxUhROQS7NPZa86mBETWzoPUO2rkiNI ps4IFfO1c98UNuuWiknNP7oxXVL8IbP6NIFuX9gpPoduvQvxg9WYFUPvsI3fpBpnR4py R6jt44G5X/esdU1X+Mx6sTEphesFPgcQCv1N1DKZbYP7LeIVrLmzSq/RklTiGHxhX2Im LOQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=quD5U0AaB7dwoV+0MYVxL3iSYkmAfbQXI74kd2LRgxs=; b=Q170F1+EsS5hRfrLNwyUmHAXefXzqVCtWunSELLgt7TH8bwv38xhKI8ZAqHqUlnefc vURZf9aGhfIIBz6pYj4TUDEUDg4BUPBmLpDh71/PgOt2tSm47n/QeInmbuAej8bk8LoS dPsICPWAzYbJ8ClepBqSxhU6cOs5hSLe2T8YAMeb9XUbToG0Lwwr50U3eGE4AHD/oGDd vBZV2i0QAASxAQQJ6f3D4s+vdTJoOuUm1nt6TeDvWYl0o/JmBQF1Ql9EoOV9cIDISsp8 D8b8YsPCyYUzmoac+8fKfGapvrINaBApvMyGzZVhO4PoLMUsRFMFXVprjb9CmHzivrPG 32kg== X-Gm-Message-State: AOAM531exmX47t4r5Gu/rikPuNiBHUdn46TMyEd651SugAcxE1xcvlOZ G/JkzWMvDX823Mv68mprPe6cO+OHWEDBwQ== X-Received: by 2002:a17:906:6b87:b0:6ce:537b:53bb with SMTP id l7-20020a1709066b8700b006ce537b53bbmr13487662ejr.51.1645397178683; Sun, 20 Feb 2022 14:46:18 -0800 (PST) Received: from krava ([83.240.63.12]) by smtp.gmail.com with ESMTPSA id f22sm8027349edf.95.2022.02.20.14.46.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Feb 2022 14:46:18 -0800 (PST) Date: Sun, 20 Feb 2022 23:46:15 +0100 From: Jiri Olsa To: Alexey Bayduraev Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov Subject: Re: [PATCH urgent] perf data: Fix double free in perf_session__delete Message-ID: References: <20220218152341.5197-1-alexey.v.bayduraev@linux.intel.com> <20220218152341.5197-2-alexey.v.bayduraev@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220218152341.5197-2-alexey.v.bayduraev@linux.intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 On Fri, Feb 18, 2022 at 06:23:41PM +0300, Alexey Bayduraev wrote: > When perf_data__create_dir fails, it calls close_dir, but > perf_session__delete also calls close_dir and since dir.version and > dir.nr was initialized by perf_data__create_dir, a double free occurs. > This patch moves the initialization of dir.version and dir.nr after > successful initialization of dir.files, that prevents double freeing. > This behavior is already implemented in perf_data__open_dir. > > Fixes: 145520631130bd64 ("perf data: Add perf_data__(create_dir|close_dir) functions") > Signed-off-by: Alexey Bayduraev Acked-by: Jiri Olsa thanks, jirka > --- > tools/perf/util/data.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c > index f5d260b1df4d..15a4547d608e 100644 > --- a/tools/perf/util/data.c > +++ b/tools/perf/util/data.c > @@ -44,10 +44,6 @@ int perf_data__create_dir(struct perf_data *data, int nr) > if (!files) > return -ENOMEM; > > - data->dir.version = PERF_DIR_VERSION; > - data->dir.files = files; > - data->dir.nr = nr; > - > for (i = 0; i < nr; i++) { > struct perf_data_file *file = &files[i]; > > @@ -62,6 +58,9 @@ int perf_data__create_dir(struct perf_data *data, int nr) > file->fd = ret; > } > > + data->dir.version = PERF_DIR_VERSION; > + data->dir.files = files; > + data->dir.nr = nr; > return 0; > > out_err: > -- > 2.19.0 >