From bdff070cf3faf196ce20cec10e662bd846aea337 Mon Sep 17 00:00:00 2001 From: Kuan-Wei Chiu Date: Thu, 7 Dec 2023 19:56:23 +0800 Subject: [PATCH 1/3] perf hisi-ptt: Fix memory leak in lseek failure handling mainline inclusion from mainline-v6.7-rc1 commit be7a4caa7c45bd4b0a39cdb260905b52a87c8688 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I8MEWF CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=be7a4caa7c45bd4b0a39cdb260905b52a87c8688 ------------------------------------------- In the previous code, there was a memory leak issue where the previously allocated memory was not freed upon a failed lseek operation. This patch addresses the problem by releasing the old memory before returning -errno in case of a lseek failure. This ensures that memory is properly managed and avoids potential memory leaks. Signed-off-by: Kuan-Wei Chiu Acked-by: Namhyung Kim Cc: yangyicong@hisilicon.com Cc: jonathan.cameron@huawei.com Link: https://lore.kernel.org/r/20230930072719.1267784-1-visitorckw@gmail.com Signed-off-by: Namhyung Kim Signed-off-by: Junhao He --- tools/perf/util/hisi-ptt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/hisi-ptt.c b/tools/perf/util/hisi-ptt.c index 45b614bb73bf..43bd1ca62d58 100644 --- a/tools/perf/util/hisi-ptt.c +++ b/tools/perf/util/hisi-ptt.c @@ -108,8 +108,10 @@ static int hisi_ptt_process_auxtrace_event(struct perf_session *session, data_offset = 0; } else { data_offset = lseek(fd, 0, SEEK_CUR); - if (data_offset == -1) + if (data_offset == -1) { + free(data); return -errno; + } } err = readn(fd, data, size); -- Gitee From 3f1c7091b0c044d46c6fcbd43f2469f7652c90a8 Mon Sep 17 00:00:00 2001 From: Yicong Yang Date: Thu, 7 Dec 2023 19:56:24 +0800 Subject: [PATCH 2/3] perf hisi-ptt: Fix one memory leakage in hisi_ptt_process_auxtrace_event() driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I8MEWF CVE: NA -------------------------------- ASan complains a memory leakage in hisi_ptt_process_auxtrace_event() that the data buffer is not freed. Since currently we only support the raw dump trace mode, the data buffer is used only within this function. So fix this by freeing the data buffer before going out. Fixes: 5e91e57e6809 ("perf auxtrace arm64: Add support for parsing HiSilicon PCIe Trace packet") Signed-off-by: Yicong Yang Signed-off-by: Junhao He --- tools/perf/util/hisi-ptt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/perf/util/hisi-ptt.c b/tools/perf/util/hisi-ptt.c index 43bd1ca62d58..52d0ce302ca0 100644 --- a/tools/perf/util/hisi-ptt.c +++ b/tools/perf/util/hisi-ptt.c @@ -123,6 +123,7 @@ static int hisi_ptt_process_auxtrace_event(struct perf_session *session, if (dump_trace) hisi_ptt_dump_event(ptt, data, size); + free(data); return 0; } -- Gitee From 67e9e7e188469f832c7cdb9deceae41ab58f8898 Mon Sep 17 00:00:00 2001 From: Yicong Yang Date: Thu, 7 Dec 2023 19:56:25 +0800 Subject: [PATCH 3/3] perf header: Fix one memory leakage in perf_event__fprintf_event_update() driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I8MEWF CVE: NA -------------------------------- When dump the raw trace by `perf report -D` ASan reports a memory leakage in perf_event__fprintf_event_update(). It shows that we allocated a temporary cpumap for dumping the CPUs but doesn't release it and it's not used elsewhere. Fix this by free the cpumap after the dumping. Fixes: c853f9394b7b ("perf tools: Add perf_event__fprintf_event_update function") Signed-off-by: Yicong Yang Signed-off-by: Junhao He --- tools/perf/util/header.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index be850e9f8852..1c508c1e4aee 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3970,10 +3970,12 @@ size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp) ret += fprintf(fp, "... "); map = cpu_map__new_data(&ev_cpus->cpus); - if (map) + if (map) { ret += cpu_map__fprintf(map, fp); - else + perf_cpu_map__put(map); + } else { ret += fprintf(fp, "failed to get cpus\n"); + } break; default: ret += fprintf(fp, "... unknown type\n"); -- Gitee