Patch "perf script: Fix allocation of evsel->priv related to per-event dump files" has been added to the 5.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    perf script: Fix allocation of evsel->priv related to per-event dump files

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     perf-script-fix-allocation-of-evsel-priv-related-to-.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit f50d14617f42085af74c4bf2ec8c0040a60641ce
Author: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Date:   Tue Jun 6 16:11:10 2023 -0300

    perf script: Fix allocation of evsel->priv related to per-event dump files
    
    [ Upstream commit 36d3e4138e1b6cc9ab179f3f397b5548f8b1eaae ]
    
    When printing output we may want to generate per event files, where the
    --per-event-dump option should be used, creating perf.data.EVENT.dump
    files instead of printing to stdout.
    
    The callback thar processes event thus expects that evsel->priv->fp
    should point to either the per-event FILE descriptor or to stdout.
    
    The a3af66f51bd0bca7 ("perf script: Fix crash because of missing
    evsel->priv") changeset fixed a case where evsel->priv wasn't setup,
    thus set to NULL, causing a segfault when trying to access
    evsel->priv->fp.
    
    But it did it for the non --per-event-dump case by allocating a 'struct
    perf_evsel_script' just to set its ->fp to stdout.
    
    Since evsel->priv is only freed when --per-event-dump is used, we ended
    up with a memory leak, detected using ASAN.
    
    Fix it by using the same method as perf_script__setup_per_event_dump(),
    and reuse that static 'struct perf_evsel_script'.
    
    Also check if evsel_script__new() failed.
    
    Fixes: a3af66f51bd0bca7 ("perf script: Fix crash because of missing evsel->priv")
    Reported-by: Ian Rogers <irogers@xxxxxxxxxx>
    Tested-by: Ian Rogers <irogers@xxxxxxxxxx>
    Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
    Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
    Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
    Cc: Ravi Bangoria <ravi.bangoria@xxxxxxxxxxxxx>
    Link: https://lore.kernel.org/lkml/ZH+F0wGAWV14zvMP@xxxxxxxxxx
    Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 5651714e527c5..85befbacb2a44 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2146,6 +2146,9 @@ static int process_sample_event(struct perf_tool *tool,
 	return 0;
 }
 
+// Used when scr->per_event_dump is not set
+static struct evsel_script es_stdout;
+
 static int process_attr(struct perf_tool *tool, union perf_event *event,
 			struct evlist **pevlist)
 {
@@ -2154,7 +2157,6 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,
 	struct evsel *evsel, *pos;
 	u64 sample_type;
 	int err;
-	static struct evsel_script *es;
 
 	err = perf_event__process_attr(tool, event, pevlist);
 	if (err)
@@ -2164,14 +2166,13 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,
 	evsel = evlist__last(*pevlist);
 
 	if (!evsel->priv) {
-		if (scr->per_event_dump) {
+		if (scr->per_event_dump) { 
 			evsel->priv = evsel_script__new(evsel, scr->session->data);
-		} else {
-			es = zalloc(sizeof(*es));
-			if (!es)
+			if (!evsel->priv)
 				return -ENOMEM;
-			es->fp = stdout;
-			evsel->priv = es;
+		} else { // Replicate what is done in perf_script__setup_per_event_dump()
+			es_stdout.fp = stdout;
+			evsel->priv = &es_stdout;
 		}
 	}
 
@@ -2455,7 +2456,6 @@ static int perf_script__fopen_per_event_dump(struct perf_script *script)
 static int perf_script__setup_per_event_dump(struct perf_script *script)
 {
 	struct evsel *evsel;
-	static struct evsel_script es_stdout;
 
 	if (script->per_event_dump)
 		return perf_script__fopen_per_event_dump(script);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux