File perf-inject-Fix-segfault-due-to-close-without-open.patch of Package perf
66
1
From: Adrian Hunter <adrian.hunter@intel.com>
2
Date: Mon, 13 Dec 2021 10:48:28 +0200
3
Subject: perf inject: Fix segfault due to close without open
4
Git-commit: 0c8e32fe48f549eef27c8c6b0a63530f83c3a643
5
Patch-mainline: v5.16-rc6
6
References: git-fixes
7
8
The fixed commit attempts to close inject.output even if it was never
9
opened e.g.
10
11
$ perf record uname
12
Linux
13
[ perf record: Woken up 1 times to write data ]
14
[ perf record: Captured and wrote 0.002 MB perf.data (7 samples) ]
15
$ perf inject -i perf.data --vm-time-correlation=dry-run
16
Segmentation fault (core dumped)
17
$ gdb --quiet perf
18
Reading symbols from perf...
19
(gdb) r inject -i perf.data --vm-time-correlation=dry-run
20
Starting program: /home/ahunter/bin/perf inject -i perf.data --vm-time-correlation=dry-run
21
[Thread debugging using libthread_db enabled]
22
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
23
24
Program received signal SIGSEGV, Segmentation fault.
25
0x00007eff8afeef5b in _IO_new_fclose (fp=0x0) at iofclose.c:48
26
48 iofclose.c: No such file or directory.
27
(gdb) bt
28
#0 0x00007eff8afeef5b in _IO_new_fclose (fp=0x0) at iofclose.c:48
29
#1 0x0000557fc7b74f92 in perf_data__close (data=data@entry=0x7ffcdafa6578) at util/data.c:376
30
#2 0x0000557fc7a6b807 in cmd_inject (argc=<optimized out>, argv=<optimized out>) at builtin-inject.c:1085
31
#3 0x0000557fc7ac4783 in run_builtin (p=0x557fc8074878 <commands+600>, argc=4, argv=0x7ffcdafb6a60) at perf.c:313
32
#4 0x0000557fc7a25d5c in handle_internal_command (argv=<optimized out>, argc=<optimized out>) at perf.c:365
33
#5 run_argv (argcp=<optimized out>, argv=<optimized out>) at perf.c:409
34
#6 main (argc=4, argv=0x7ffcdafb6a60) at perf.c:539
35
(gdb)
36
37
Fixes: 02e6246f5364d526 ("perf inject: Close inject.output on exit")
38
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
39
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
40
Cc: Jiri Olsa <jolsa@redhat.com>
41
Cc: Namhyung Kim <namhyung@kernel.org>
42
Cc: Riccardo Mancini <rickyman7@gmail.com>
43
Cc: stable@vger.kernel.org
44
Link: http://lore.kernel.org/lkml/20211213084829.114772-2-adrian.hunter@intel.com
45
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
46
Signed-off-by: Tony Jones <tonyj@suse.de>
47
---
48
tools/perf/builtin-inject.c | 3 ++-
49
1 file changed, 2 insertions(+), 1 deletion(-)
50
51
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
52
index b9d6306cc14e..af70f1c72052 100644
53
--- a/tools/perf/builtin-inject.c
54
+++ b/tools/perf/builtin-inject.c
55
56
zstd_fini(&(inject.session->zstd_data));
57
perf_session__delete(inject.session);
58
out_close_output:
59
- perf_data__close(&inject.output);
60
+ if (!inject.in_place_update)
61
+ perf_data__close(&inject.output);
62
free(inject.itrace_synth_opts.vm_tm_corr_args);
63
return ret;
64
}
65
66