From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 20B541662EF; Wed, 5 Feb 2025 14:29:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738765767; cv=none; b=Ygah0jJTo8ib9pElXa2QOcEoSlBhzqRP3SyVah2Uq8Q8FV+xZcR0hpK9vkECQ41iOY1TcignxQ49VeTUs8d+TdgMrSSw0o6C8ZV+WklTUrqRLJr7GL2bWEsusCby83uNV8TTGwSwoSW2iGWhVn5shAYtlKaPEEKIoYsqy3gDCgk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738765767; c=relaxed/simple; bh=Xod1hZQbttkhpn/jsLu/HwKbkfUuuQG1iftlC+zn0C4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dg/BHGZ4rBXZMsLFEfN+vMmOKmJ4kEbG0DMgfuJUAxQfghp4pP9HMT0TahibdmuxcwAYSsc+DoTQUv6X9ckCJ5526sMRb/Qyr90pPIi/ANFZxJyC8EC89EUI1u1y8Iq9X15krXFAOhWB27S4PTJtBLIKOOd9wqxw8t15Drxrcgk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=GCluFxam; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="GCluFxam" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6482C4CEEC; Wed, 5 Feb 2025 14:29:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1738765766; bh=Xod1hZQbttkhpn/jsLu/HwKbkfUuuQG1iftlC+zn0C4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GCluFxamI8O2VCnY+ykPrsNnNuWbOYcoNGk2nPjmRQaD71HX3uTDrmw2XWFycygIA qCNyXzGGh4NFt5E7c+NwkxSI23XIkFE4nNNIQguSvZr3up8aG7PBH1Ve03gx232MBP i88v3SdPHxLLxbJXyQxADYZUO+eWR4R3LjYR/JaM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Namhyung Kim , Zhongqiu Han , Adrian Hunter , Alexander Shishkin , Ian Rogers , Ingo Molnar , James Clark , Jiri Olsa , Kan Liang , Mark Rutland , Peter Zijlstra , Song Liu , Yicong Yang , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 6.12 250/590] perf header: Fix one memory leakage in process_bpf_btf() Date: Wed, 5 Feb 2025 14:40:05 +0100 Message-ID: <20250205134504.845032071@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250205134455.220373560@linuxfoundation.org> References: <20250205134455.220373560@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhongqiu Han [ Upstream commit 875d22980a062521beed7b5df71fb13a1af15d83 ] If __perf_env__insert_btf() returns false due to a duplicate btf node insertion, the temporary node will leak. Add a check to ensure the memory is freed if the function returns false. Fixes: a70a1123174ab592 ("perf bpf: Save BTF information as headers to perf.data") Reviewed-by: Namhyung Kim Signed-off-by: Zhongqiu Han Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Peter Zijlstra Cc: Song Liu Cc: Yicong Yang Link: https://lore.kernel.org/r/20241205084500.823660-2-quic_zhonhan@quicinc.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/header.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index a6386d12afd72..fd66042ecb030 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3235,7 +3235,8 @@ static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused) if (__do_read(ff, node->data, data_size)) goto out; - __perf_env__insert_btf(env, node); + if (!__perf_env__insert_btf(env, node)) + free(node); node = NULL; } -- 2.39.5