Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3115337pxm; Mon, 28 Feb 2022 12:20:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJx+nIuoURcXw3sDpWVAGjb8ezPI0+LwDGrHAgR8GhV+kfZLmal99hqVlv4gbiQQfFNAsmeR X-Received: by 2002:a17:902:b183:b0:14f:c266:20d5 with SMTP id s3-20020a170902b18300b0014fc26620d5mr22496427plr.136.1646079614504; Mon, 28 Feb 2022 12:20:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646079614; cv=none; d=google.com; s=arc-20160816; b=YBUgvP5w6weW8GIXQQxWCPdzNjunY8Aorl67GuUtALAxeTSOOCrYF7I4fDRwFHWZcl /c6pGo/zf5VfVFKbRuGW4XWcEVZPwCJnyfAtGP7PUCoa9dLgFn0MVpoL5ttnkE97DcQb M2dFACge8FpVBFqOvqMywTCCz7p7Qy6TYYjW7Y5o/6nkaG2Bd5Yld93nm+uMqNavXTsD lVfPqvC3ghGMwklCPMxvWDhdNkfUAPoOymU7EK+7ARTyxRNKbg+9aDjNIBDYFuF8SjXH 7+xt3pV0KKkdRCsG492e+GzRBmbhoB2VvXV8YYkhoq9ou8UW6OdO06p6uxvIsSzCUJtF 912A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3uNd7vnYX7BQgeTVXzrUx1Bwf9bmzkEFPoDWWDJoEOA=; b=x1MW1T194LDl4My4Qf5t5xpVjiWc9jx2Evm9BoCDb7paR2Js1AsCyBhaccON4dVgLt VZ1pOJHFX9elc8V/JW83Y8hxRKEV1s0ICc35tmMxksqTm2fUD1a+g4OJPari1YHLUAA0 j7LSZxOObYnaVJglOab2rvOXosP3kYJUQfRqqAZ76xadNuzseMwAY1kKgLMLVLoajDof SNvs+2sp9/92DYP2l6LPeR4ynV2wfUlWwPLGwIWoOqTnpkqUoUhkyXVprf/KsLlxdUNX 1t29ZRYS6Avdru3oj6Qk5MOxXYtuoE0FcVGgWjsS20YbLyN1W/Ku87U3ifLvJeiSuQTH BJDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JJRGdrPh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id br11-20020a17090b0f0b00b001bc232da882si368116pjb.100.2022.02.28.12.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:20:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JJRGdrPh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BB2D41B65D6; Mon, 28 Feb 2022 11:40:49 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232526AbiB1SCJ (ORCPT + 99 others); Mon, 28 Feb 2022 13:02:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235015AbiB1Ryq (ORCPT ); Mon, 28 Feb 2022 12:54:46 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51BC653737; Mon, 28 Feb 2022 09:44:01 -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 DECA060909; Mon, 28 Feb 2022 17:44:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C740BC340F0; Mon, 28 Feb 2022 17:43:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646070240; bh=P9+8LyoE7wfKYtVa8BQKxcGYP08SrbQhU1GkxwKfPiQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JJRGdrPhRoFS8GEpztxEKrs4n34xkC6lHf7dxJITfOcfKuVvBligwA+2WITt+Gk/1 zlw5TWaDQgV5L7r376dHfkUEHYUSbl8IoLyKF1UlIwnNT8k6Na+4LY8PkocV78Vmaq 457PwjX3SY1lKgtIZm9MEheHhIE1BMXcznC7wO1I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Bayduraev , Jiri Olsa , Adrian Hunter , Alexander Antonov , Alexander Shishkin , Alexei Budankov , Andi Kleen , Ingo Molnar , Namhyung Kim , Peter Zijlstra , Arnaldo Carvalho de Melo Subject: [PATCH 5.16 037/164] perf data: Fix double free in perf_session__delete() Date: Mon, 28 Feb 2022 18:23:19 +0100 Message-Id: <20220228172403.639757603@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220228172359.567256961@linuxfoundation.org> References: <20220228172359.567256961@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Alexey Bayduraev commit 69560e366fc4d5fca7bebb0e44edbfafc8bcaf05 upstream. 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 were 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 Cc: Adrian Hunter Cc: Alexander Antonov Cc: Alexander Shishkin Cc: Alexei Budankov Cc: Andi Kleen Cc: Ingo Molnar Cc: Namhyung Kim Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20220218152341.5197-2-alexey.v.bayduraev@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/data.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/tools/perf/util/data.c +++ b/tools/perf/util/data.c @@ -44,10 +44,6 @@ int perf_data__create_dir(struct perf_da 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_da file->fd = ret; } + data->dir.version = PERF_DIR_VERSION; + data->dir.files = files; + data->dir.nr = nr; return 0; out_err: