Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp1290451pxb; Fri, 18 Feb 2022 04:53:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHzWVdQxJ8fEfZB39NXA/SfVIVw4FUhDs4jB9T37IbUfd4C7qsqFuHk6CG1hqmI9iUmAsT X-Received: by 2002:a63:2223:0:b0:373:3d5d:1163 with SMTP id i35-20020a632223000000b003733d5d1163mr6348310pgi.443.1645188815045; Fri, 18 Feb 2022 04:53:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645188815; cv=none; d=google.com; s=arc-20160816; b=w2zm4hQfHRXVX0nWuz9BRAbW6F181KnaWd4QIN3IKltT57AHHXJyNItCki41cRLkIK wuC31PkVmJ00GkNBgW11jtLqlNujBUJ2wk83txcsfcmKYzVgWkOLT+PKMDXUzgb55KrW f9bMKpOaRIAoX/6yjQmPwtqrG0QQeYi2f1n6eoP7WjFypaQaetNB7VnxfdUKSRhWQbBs 83lfaxoWJnKriSSn3W6N88nq7USf3EbSGmTUM6YMyFR4yOKQuJIj6WP2RGXG///iRZnB TLtP5zkZeEwBXwbHz847tSVIyC2DdSYq63EL9BJjuLjKhlujNhMrqTCpNR2VAgIjo5Bv 0A8g== 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=fcAya2gyuJ3XJlwidfnnqZvl8PDNadsREBQHXLfiR9E=; b=cO44dKcL62uq11yRQ08AVbRn4pj6PxURUrQZDNmWZWZ9v39Zx646DA/bWL3anlEdcn uVq+FcrCO1c9H/BV45poLMUwRe1i/mt0sakadSrsAT1XeR2hDBY9X0o3OT3egFcIFQFN ybywCFO55Tfa+C3/oU1hDak3mnSGoSlQUXxaXPCXbuE0X5yLixsqBmKpY7yBQ41/pWbL 9Pi5dGBaKwgEedD+VsGL/9z3+kcFW/+8pir1Z9hjANIE5SoRFn92S87M2cau7CwUC/CE Rmq1e16NVDC+zHcCv/jDnvm+NrX96GpioVh9cRSSaElfT7iQzmgn7pZuXuTwKTRRt5v2 ev3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cyWp+KBX; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g10si11697730pgb.483.2022.02.18.04.53.20; Fri, 18 Feb 2022 04:53:35 -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=@kernel.org header.s=k20201202 header.b=cyWp+KBX; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233400AbiBRMjg (ORCPT + 99 others); Fri, 18 Feb 2022 07:39:36 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:58504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231348AbiBRMje (ORCPT ); Fri, 18 Feb 2022 07:39:34 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCE0129A545 for ; Fri, 18 Feb 2022 04:39:17 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5191361F7C for ; Fri, 18 Feb 2022 12:39:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95E30C340E9; Fri, 18 Feb 2022 12:39:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645187956; bh=qHo65HwDG+mU8Tt9U4kRIsnLeY0N9I8w58mBY4WGkv8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=cyWp+KBXIpnavPKW7B5sricRFuxXTZGKK8esBbwSIv7atqD9bv18uIqSc/hYr4cHa TT2v1yBOgfvC9CHCPY136XKC6DuytmaOeEVEo2DwTgiu7onlHdcF6XSIw2aEr+4CzW aJHkKNRZkqPyXrobyFCfiTQ2TVbCNuHGMqEnK/zqqwjIS7i0AtOkT3Fw7+ynPhtVzs lBwWfpMsIMAP7NnWkqb9992rC3YHzQNITr02Jypi/DpEEDOT0ARcZwJkWpHkOpHu3Y y4WDTTLai392zI3ykP9s3DwdLcWFLPe8qMcU7kMeuL1lZsHb+9W6AVe3a7NqlFwOco p3FSpWLpnqffg== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id CF4B8400FE; Fri, 18 Feb 2022 09:39:13 -0300 (-03) Date: Fri, 18 Feb 2022 09:39:13 -0300 From: Arnaldo Carvalho de Melo To: Alexey Bayduraev Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Adrian Hunter , Alexander Antonov , Alexei Budankov Subject: Re: [PATCH] perf data: Fix double free in perf_session__delete Message-ID: References: <20220218113008.24416-1-alexey.v.bayduraev@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220218113008.24416-1-alexey.v.bayduraev@linux.intel.com> X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 Em Fri, Feb 18, 2022 at 02:30:08PM +0300, Alexey Bayduraev escreveu: > 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. The patch > also adds a missing error message in case data directory creation fails. Is this for perf/urgent or for perf/core? Probably perf/core as that record__threads_enabled(rec) call hints. Please state for which branch the patch should be applied, something like; [PATCH next] perf data: Fix double free in perf_session__delete() Or: [PATCH urgent] perf data: Fix double free in perf_session__delete() - Arnaldo > Signed-off-by: Alexey Bayduraev > --- > tools/perf/builtin-record.c | 4 +++- > tools/perf/util/data.c | 7 +++---- > 2 files changed, 6 insertions(+), 5 deletions(-) > > diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c > index 0bc6529814b2..0306d5911de2 100644 > --- a/tools/perf/builtin-record.c > +++ b/tools/perf/builtin-record.c > @@ -1186,8 +1186,10 @@ static int record__mmap_evlist(struct record *rec, > > if (record__threads_enabled(rec)) { > ret = perf_data__create_dir(&rec->data, evlist->core.nr_mmaps); > - if (ret) > + if (ret) { > + pr_err("Failed to create data directory: %s\n", strerror(errno)); > return ret; > + } > for (i = 0; i < evlist->core.nr_mmaps; i++) { > if (evlist->mmap) > evlist->mmap[i].file = &rec->data.dir.files[i]; > 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 -- - Arnaldo