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 8FD3225D54A; Tue, 11 Mar 2025 15:04:20 +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=1741705460; cv=none; b=CnhkQ66t9ZoDr+XW+kUHCZz+jMGKZhKrPFbxtLMP6FqEzAZEpjPwmcQk3eTDmBedd8liqp4KOjZlqETFA1z9XQmk969pfvvdEjxf7nZMyLrZ9jVTLrChgjpA5PukcimjzvBzIObwvD4bmnMiCiLaRqEjMDfrjsUShw7YBIIKnjk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741705460; c=relaxed/simple; bh=Vs3fpiYlZ/uXNOZ7BKmM0fFmuZSMkKeCB5ELxusx878=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jCS08d5hgzZhtNnm6u5Q9R5Cyb8kVd/H9TCwhfltrwoHvZnHWgOyJRcails6TTpHSCOtGpL8GgmI6ywPou6mhLxOfwmu/XEOSMqGPoc5IQOSKPg79d2OQVYPtfUovaJhE2+NmXye3Tq+0G0sRwWQSsnJa+UzgmFDN7a2YAAHu3g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=QWn4a7uu; 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="QWn4a7uu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0C20C4CEE9; Tue, 11 Mar 2025 15:04:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741705460; bh=Vs3fpiYlZ/uXNOZ7BKmM0fFmuZSMkKeCB5ELxusx878=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QWn4a7uunpZEOMRtJbC4NAXJ0avkStpzjp/n/N4mCNhF8DVT1zvVfZi5SakU3wvrj nzdN8qD1qKc8yyDK/Xsp+Az3tmU1S1XRVcBFc6GabmF9/0V4hQIu+2i0PGeCDnBTZk RABBjyl3KIBe1cysUYhFelcW67TK0VfUc/tIhQkY= 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 5.4 035/328] perf header: Fix one memory leakage in process_bpf_btf() Date: Tue, 11 Mar 2025 15:56:45 +0100 Message-ID: <20250311145716.290118335@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311145714.865727435@linuxfoundation.org> References: <20250311145714.865727435@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 5.4-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 a68feeb3eb00d..6dc99378b191b 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -2777,7 +2777,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