perf inject: Fix segfaults relating to in-place update
Adrian Hunter
reviewercover perf inject: Fix segfaults relating to in-place update
Hi
Here are 2 fixes to perf inject relating to in-place update.
Adrian Hunter (2):
perf inject: Fix segfault due to close without open perf inject: Fix segfault due to perf_data__fd() without open
tools/perf/builtin-inject.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
Regards
Adrian
Adrian Hunter
reviewerPATCH 1/2 perf inject: Fix segfault due to close without open
The fixed commit attempts to close inject.output even if it was never opened e.g.
$ perf record uname Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.002 MB perf.data (7 samples) ] $ perf inject -i perf.data --vm-time-correlation=dry-run Segmentation fault (core dumped) $ gdb --quiet perf Reading symbols from perf... (gdb) r inject -i perf.data --vm-time-correlation=dry-run Starting program: /home/ahunter/bin/perf inject -i perf.data --vm-time-correlation=dry-run [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault. 0x00007eff8afeef5b in _IO_new_fclose (fp=0x0) at iofclose.c:48
48 iofclose.c: No such file or directory.
(gdb) bt
#0 0x00007eff8afeef5b in _IO_new_fclose (fp=0x0) at iofclose.c:48 #1 0x0000557fc7b74f92 in perf_data__close (data=data@entry=0x7ffcdafa6578) at util/data.c:376 #2 0x0000557fc7a6b807 in cmd_inject (argc=<optimized out>, argv=<optimized out>) at builtin-inject.c:1085 #3 0x0000557fc7ac4783 in run_builtin (p=0x557fc8074878 <commands+600>, argc=4, argv=0x7ffcdafb6a60) at perf.c:313 #4 0x0000557fc7a25d5c in handle_internal_command (argv=<optimized out>, argc=<optimized out>) at perf.c:365 #5 run_argv (argcp=<optimized out>, argv=<optimized out>) at perf.c:409 #6 main (argc=4, argv=0x7ffcdafb6a60) at perf.c:539
(gdb)
--- tools/perf/builtin-inject.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/builtin-inject.c +2 -1
@@ -1078,7 +1078,8 @@ int cmd_inject(int argc, const char **argv)zstd_fini (&(inject.session->zstd_data));perf_session__delete (inject.session); out_close_output: -perf_data__close (&inject.output); +if (!inject.in_place_update) +perf_data__close (&inject.output);free (inject.itrace_synth_opts.vm_tm_corr_args);return ret; }
Signature · 1 line
2.25.1
Adrian Hunter
reviewerPATCH 2/2 perf inject: Fix segfault due to perf_data__fd() without open
In reply to Adrian HunterThe fixed commit attempts to get the output file descriptor even if the file was never opened e.g.
$ perf record uname Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.002 MB perf.data (7 samples) ] $ perf inject -i perf.data --vm-time-correlation=dry-run Segmentation fault (core dumped) $ gdb --quiet perf Reading symbols from perf... (gdb) r inject -i perf.data --vm-time-correlation=dry-run Starting program: /home/ahunter/bin/perf inject -i perf.data --vm-time-correlation=dry-run [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault. __GI___fileno (fp=0x0) at fileno.c:35
35 fileno.c: No such file or directory.
(gdb) bt
#0 __GI___fileno (fp=0x0) at fileno.c:35 #1 0x00005621e48dd987 in perf_data__fd (data=0x7fff4c68bd08) at util/data.h:72 #2 perf_data__fd (data=0x7fff4c68bd08) at util/data.h:69 #3 cmd_inject (argc=<optimized out>, argv=0x7fff4c69c1f0) at builtin-inject.c:1017 #4 0x00005621e4936783 in run_builtin (p=0x5621e4ee6878 <commands+600>, argc=4, argv=0x7fff4c69c1f0) at perf.c:313 #5 0x00005621e4897d5c in handle_internal_command (argv=<optimized out>, argc=<optimized out>) at perf.c:365 #6 run_argv (argcp=<optimized out>, argv=<optimized out>) at perf.c:409 #7 main (argc=4, argv=0x7fff4c69c1f0) at perf.c:539
(gdb)
--- tools/perf/builtin-inject.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
tools/perf/builtin-inject.c +7 -3
@@ -755,12 +755,16 @@ static int parse_vm_time_correlation(const struct option *opt, const char *str,return inject->itrace_synth_opts.vm_tm_corr_args ?0 : -ENOMEM ; } +static int output_fd (struct perf_inject *inject) +{ +return inject->in_place_update ?-1 :perf_data__fd (&inject->output); +} +static int __cmd_inject (struct perf_inject *inject) {int ret = -EINVAL ;struct perf_session *session = inject->session; -struct perf_data *data_out = &inject->output; -int fd = inject->in_place_update ?-1 :perf_data__fd (data_out); +int fd =output_fd (inject);u64 output_data_offset;signal (SIGINT , sig_handler);
@@ -1015,7 +1019,7 @@ int cmd_inject(int argc, const char **argv) } inject.session =__perf_session__new (&data, repipe, -perf_data__fd (&inject.output), +output_fd (&inject), &inject.tool);if (IS_ERR (inject.session)) { ret =PTR_ERR (inject.session);
Signature · 1 line
2.25.1
Re: [PATCH 1/2] perf inject: Fix segfault due to close without open
In reply to Adrian HunterEm Mon, Dec 13, 2021 at 10:48:28AM +0200, Adrian Hunter escreveu:
Quoted 15 lines
The fixed commit attempts to close inject.output even if it was never opened e.g.
$ perf record uname Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.002 MB perf.data (7 samples) ] $ perf inject -i perf.data --vm-time-correlation=dry-run Segmentation fault (core dumped) $ gdb --quiet perf Reading symbols from perf... (gdb) r inject -i perf.data --vm-time-correlation=dry-run Starting program: /home/ahunter/bin/perf inject -i perf.data --vm-time-correlation=dry-run [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Thanks, applied.
- Arnaldo
Quoted 36 lines
Program received signal SIGSEGV, Segmentation fault.
0x00007eff8afeef5bin_IO_new_fclose(fp=0x0) at iofclose.c:48
48iofclose.c: No such file or directory.
(gdb) bt#0 0x00007eff8afeef5b in _IO_new_fclose (fp=0x0) at iofclose.c:48 #1 0x0000557fc7b74f92 in perf_data__close (data=data@entry=0x7ffcdafa6578) at util/data.c:376 #2 0x0000557fc7a6b807 in cmd_inject (argc=<optimized out>, argv=<optimized out>) at builtin-inject.c:1085 #3 0x0000557fc7ac4783 in run_builtin (p=0x557fc8074878 <commands+600>, argc=4, argv=0x7ffcdafb6a60) at perf.c:313 #4 0x0000557fc7a25d5c in handle_internal_command (argv=<optimized out>, argc=<optimized out>) at perf.c:365 #5 run_argv (argcp=<optimized out>, argv=<optimized out>) at perf.c:409 #6 main (argc=4, argv=0x7ffcdafb6a60) at perf.c:539(gdb)
Fixes 02e6246f5364d ("perf inject: Close inject.output on exit")Signed-off-by Adrian Hunter <[email protected]>--- tools/perf/builtin-inject.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/perf/builtin-inject.c +2
-1@@ -1078,7 +1078,8 @@ int cmd_inject(int argc, const char **argv)zstd_fini (&(inject.session->zstd_data));perf_session__delete (inject.session); out_close_output: -perf_data__close (&inject.output); +if (!inject.in_place_update) +perf_data__close (&inject.output);free (inject.itrace_synth_opts.vm_tm_corr_args);return ret; }Signature · 1 line
2.25.1
Signature · 1 line
- Arnaldo
Re: [PATCH 2/2] perf inject: Fix segfault due to perf_data__fd() without open
In reply to Adrian HunterEm Mon, Dec 13, 2021 at 10:48:29AM +0200, Adrian Hunter escreveu:
Quoted 28 lines
The fixed commit attempts to get the output file descriptor even if the file was never opened e.g.
$ perf record uname Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.002 MB perf.data (7 samples) ] $ perf inject -i perf.data --vm-time-correlation=dry-run Segmentation fault (core dumped) $ gdb --quiet perf Reading symbols from perf... (gdb) r inject -i perf.data --vm-time-correlation=dry-run Starting program: /home/ahunter/bin/perf inject -i perf.data --vm-time-correlation=dry-run [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".Program received signal SIGSEGV, Segmentation fault.
__GI___fileno(fp=0x0) at fileno.c:35
35fileno.c: No such file or directory.
(gdb) bt#0 __GI___fileno (fp=0x0) at fileno.c:35 #1 0x00005621e48dd987 in perf_data__fd (data=0x7fff4c68bd08) at util/data.h:72 #2 perf_data__fd (data=0x7fff4c68bd08) at util/data.h:69 #3 cmd_inject (argc=<optimized out>, argv=0x7fff4c69c1f0) at builtin-inject.c:1017 #4 0x00005621e4936783 in run_builtin (p=0x5621e4ee6878 <commands+600>, argc=4, argv=0x7fff4c69c1f0) at perf.c:313 #5 0x00005621e4897d5c in handle_internal_command (argv=<optimized out>, argc=<optimized out>) at perf.c:365 #6 run_argv (argcp=<optimized out>, argv=<optimized out>) at perf.c:409 #7 main (argc=4, argv=0x7fff4c69c1f0) at perf.c:539
Quoted 1 line
(gdb)
Thanks, applied.
- Arnaldo
Quoted 41 lines
Fixes 0ae03893623d ("perf tools: Pass a fd to perf_file_header__read_pipe()")Signed-off-by Adrian Hunter <[email protected]>--- tools/perf/builtin-inject.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)tools/perf/builtin-inject.c +7
-3@@ -755,12 +755,16 @@ static int parse_vm_time_correlation(const struct option *opt, const char *str,return inject->itrace_synth_opts.vm_tm_corr_args ?0 : -ENOMEM ; } +static int output_fd (struct perf_inject *inject) +{ +return inject->in_place_update ?-1 :perf_data__fd (&inject->output); +} +static int __cmd_inject (struct perf_inject *inject) {int ret = -EINVAL ;struct perf_session *session = inject->session; -struct perf_data *data_out = &inject->output; -int fd = inject->in_place_update ?-1 :perf_data__fd (data_out); +int fd =output_fd (inject);u64 output_data_offset;signal (SIGINT , sig_handler);@@ -1015,7 +1019,7 @@ int cmd_inject(int argc, const char **argv) } inject.session =__perf_session__new (&data, repipe, -perf_data__fd (&inject.output), +output_fd (&inject), &inject.tool);if (IS_ERR (inject.session)) { ret =PTR_ERR (inject.session);Signature · 1 line
2.25.1
Signature · 1 line
- Arnaldo
Re: [PATCH 2/2] perf inject: Fix segfault due to perf_data__fd() without open
Quoted 32 lines · Arnaldo Carvalho de Melo
Em Mon, Dec 13, 2021 at 10:48:29AM +0200, Adrian Hunter escreveu:
Quoted 28 lines
The fixed commit attempts to get the output file descriptor even if the file was never opened e.g.
$ perf record uname Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.002 MB perf.data (7 samples) ] $ perf inject -i perf.data --vm-time-correlation=dry-run Segmentation fault (core dumped) $ gdb --quiet perf Reading symbols from perf... (gdb) r inject -i perf.data --vm-time-correlation=dry-run Starting program: /home/ahunter/bin/perf inject -i perf.data --vm-time-correlation=dry-run [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".Program received signal SIGSEGV, Segmentation fault.
__GI___fileno(fp=0x0) at fileno.c:35
35fileno.c: No such file or directory.
(gdb) bt#0 __GI___fileno (fp=0x0) at fileno.c:35 #1 0x00005621e48dd987 in perf_data__fd (data=0x7fff4c68bd08) at util/data.h:72 #2 perf_data__fd (data=0x7fff4c68bd08) at util/data.h:69 #3 cmd_inject (argc=<optimized out>, argv=0x7fff4c69c1f0) at builtin-inject.c:1017 #4 0x00005621e4936783 in run_builtin (p=0x5621e4ee6878 <commands+600>, argc=4, argv=0x7fff4c69c1f0) at perf.c:313 #5 0x00005621e4897d5c in handle_internal_command (argv=<optimized out>, argc=<optimized out>) at perf.c:365 #6 run_argv (argcp=<optimized out>, argv=<optimized out>) at perf.c:409 #7 main (argc=4, argv=0x7fff4c69c1f0) at perf.c:539Quoted 1 line
(gdb)
Quoted 8 lines
Thanks, applied.
- Arnaldo
Quoted 3 lines
Fixes 0ae03893623d ("perf tools: Pass a fd to perf_file_header__read_pipe()")Signed-off-by Adrian Hunter <[email protected]>
Thanks,
Namhyung
Quoted 42 lines
Quoted 37 lines
--- tools/perf/builtin-inject.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)tools/perf/builtin-inject.c +7
-4@@ -755,12 +755,16 @@ static int parse_vm_time_correlation(const struct option *opt, const char *str,return inject->itrace_synth_opts.vm_tm_corr_args ?0 : -ENOMEM ; } +static int output_fd (struct perf_inject *inject) +{ +return inject->in_place_update ?-1 :perf_data__fd (&inject->output); +} +static int __cmd_inject (struct perf_inject *inject) {int ret = -EINVAL ;struct perf_session *session = inject->session; -struct perf_data *data_out = &inject->output; -int fd = inject->in_place_update ?-1 :perf_data__fd (data_out); +int fd =output_fd (inject);u64 output_data_offset;signal (SIGINT , sig_handler);@@ -1015,7 +1019,7 @@ int cmd_inject(int argc, const char **argv) } inject.session =__perf_session__new (&data, repipe, -perf_data__fd (&inject.output), +output_fd (&inject), &inject.tool);if (IS_ERR (inject.session)) { ret =PTR_ERR (inject.session); --Quoted 1 line
2.25.1
--
- Arnaldo