perf/test: perf test case Daemon operations dumps core

Message ID 20230627092633.2135105-1-tmricht@linux.ibm.com
State New
Headers
Series perf/test: perf test case Daemon operations dumps core |

Commit Message

Thomas Richter June 27, 2023, 9:26 a.m. UTC
  The perf test case Daemon operations dumps core all the time.
I narrowed it down to this invocation:

Segmentation fault (core dumped)
....
(gdb) where
    at builtin-daemon.c:1527
    argv=0x3ffe66f9630) at perf.c:323
    at perf.c:377
    at perf.c:421
(gdb)

Normally this goes unnoticed, the core dumps are only shown in
verbose mode and when core dump generation is enabled on fedora 38:

 # ./perf test daemon
 80: daemon operations                   : Ok
 # ll core*
-rw------- 1 root root 3551232 Jun 27 10:08 core.4586
-rw------- 1 root root 3551232 Jun 27 10:08 core.4688
-rw------- 1 root root 3551232 Jun 27 10:08 core.4812
-rw------- 1 root root 3551232 Jun 27 10:08 core.4857
-rw------- 1 root root 3551232 Jun 27 10:08 core.4893
-rw------- 1 root root 3551232 Jun 27 10:08 core.4933
-rw------- 1 root root 3551232 Jun 27 10:08 core.4947
-rw------- 1 root root 3551232 Jun 27 10:08 core.4949
 # ./perf test -v daemon
 80: daemon operations                  :
--- start ---
test child forked, pid 4974
test daemon list
./tests/shell/daemon.sh: line 133:  4980 Segmentation fault \
		(core dumped) perf daemon start --config ${config}
test daemon reconfig
./tests/shell/daemon.sh: line 133:  5082 Segmentation fault \
		(core dumped) perf daemon start --config ${config}
test daemon stop
./tests/shell/daemon.sh: line 133:  5206 Segmentation fault \
		(core dumped) perf daemon start --config ${config}
test daemon signal
./tests/shell/daemon.sh: line 133:  5250 Segmentation fault \
		(core dumped) perf daemon start --config ${config}
signal 12 sent to session 'test [5252]'
signal 12 sent to session 'test [5252]'
test daemon ping
./tests/shell/daemon.sh: line 133:  5286 Segmentation fault \
		(core dumped) perf daemon start --config ${config}
test daemon lock
./tests/shell/daemon.sh: line 133:  5326 Segmentation fault \
		(core dumped) perf daemon start --config ${config}
test child finished with 0
---- end ----
daemon operations: Ok
 # ll core*|wc -l
16
 #

The root cause is in function cmd_daemon():

    argc = parse_options(argc, argv, daemon_options, daemon_usage,
		         PARSE_OPT_STOP_AT_NON_OPTION);

    if (argc) {
	if (!strcmp(argv[0], "start"))
		ret = __cmd_start(&__daemon, daemon_options, argc,
				  argv);
	if (!strcmp(argv[0], "signal"))
		    ^^^^^^^
Parameter argv[0] is set to NULL in function __cmd_start() and the
next strcmp() accesses a NULL pointer.

Output after:

 # ./perf daemon start --config /tmp/perf-daemon-config
 #
 # ./perf test -v daemon
 80: daemon operations                                               :
--- start ---
test child forked, pid 6517
test daemon list
test daemon reconfig
test daemon stop
test daemon signal
signal 12 sent to session 'test [6780]'
signal 12 sent to session 'test [6780]'
test daemon ping
test daemon lock
test child finished with 0
---- end ----
daemon operations: Ok
 #

Fixes: 92294b906e6c ("perf daemon: Dynamically allocate path to perf")

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
---
 tools/perf/builtin-daemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Namhyung Kim June 27, 2023, 3:35 p.m. UTC | #1
Hello,

On Tue, Jun 27, 2023 at 2:39 AM Thomas Richter <tmricht@linux.ibm.com> wrote:
>
> The perf test case Daemon operations dumps core all the time.
> I narrowed it down to this invocation:

Jiri sent the same fix already.  I'll add your Reported-by, ok?

https://lore.kernel.org/all/20230626201606.2514679-1-jolsa@kernel.org/

Thanks,
Namhyung


>
> Segmentation fault (core dumped)
> ....
> (gdb) where
>     at builtin-daemon.c:1527
>     argv=0x3ffe66f9630) at perf.c:323
>     at perf.c:377
>     at perf.c:421
> (gdb)
>
> Normally this goes unnoticed, the core dumps are only shown in
> verbose mode and when core dump generation is enabled on fedora 38:
>
>  # ./perf test daemon
>  80: daemon operations                   : Ok
>  # ll core*
> -rw------- 1 root root 3551232 Jun 27 10:08 core.4586
> -rw------- 1 root root 3551232 Jun 27 10:08 core.4688
> -rw------- 1 root root 3551232 Jun 27 10:08 core.4812
> -rw------- 1 root root 3551232 Jun 27 10:08 core.4857
> -rw------- 1 root root 3551232 Jun 27 10:08 core.4893
> -rw------- 1 root root 3551232 Jun 27 10:08 core.4933
> -rw------- 1 root root 3551232 Jun 27 10:08 core.4947
> -rw------- 1 root root 3551232 Jun 27 10:08 core.4949
>  # ./perf test -v daemon
>  80: daemon operations                  :
> --- start ---
> test child forked, pid 4974
> test daemon list
> ./tests/shell/daemon.sh: line 133:  4980 Segmentation fault \
>                 (core dumped) perf daemon start --config ${config}
> test daemon reconfig
> ./tests/shell/daemon.sh: line 133:  5082 Segmentation fault \
>                 (core dumped) perf daemon start --config ${config}
> test daemon stop
> ./tests/shell/daemon.sh: line 133:  5206 Segmentation fault \
>                 (core dumped) perf daemon start --config ${config}
> test daemon signal
> ./tests/shell/daemon.sh: line 133:  5250 Segmentation fault \
>                 (core dumped) perf daemon start --config ${config}
> signal 12 sent to session 'test [5252]'
> signal 12 sent to session 'test [5252]'
> test daemon ping
> ./tests/shell/daemon.sh: line 133:  5286 Segmentation fault \
>                 (core dumped) perf daemon start --config ${config}
> test daemon lock
> ./tests/shell/daemon.sh: line 133:  5326 Segmentation fault \
>                 (core dumped) perf daemon start --config ${config}
> test child finished with 0
> ---- end ----
> daemon operations: Ok
>  # ll core*|wc -l
> 16
>  #
>
> The root cause is in function cmd_daemon():
>
>     argc = parse_options(argc, argv, daemon_options, daemon_usage,
>                          PARSE_OPT_STOP_AT_NON_OPTION);
>
>     if (argc) {
>         if (!strcmp(argv[0], "start"))
>                 ret = __cmd_start(&__daemon, daemon_options, argc,
>                                   argv);
>         if (!strcmp(argv[0], "signal"))
>                     ^^^^^^^
> Parameter argv[0] is set to NULL in function __cmd_start() and the
> next strcmp() accesses a NULL pointer.
>
> Output after:
>
>  # ./perf daemon start --config /tmp/perf-daemon-config
>  #
>  # ./perf test -v daemon
>  80: daemon operations                                               :
> --- start ---
> test child forked, pid 6517
> test daemon list
> test daemon reconfig
> test daemon stop
> test daemon signal
> signal 12 sent to session 'test [6780]'
> signal 12 sent to session 'test [6780]'
> test daemon ping
> test daemon lock
> test child finished with 0
> ---- end ----
> daemon operations: Ok
>  #
>
> Fixes: 92294b906e6c ("perf daemon: Dynamically allocate path to perf")
>
> Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
> ---
>  tools/perf/builtin-daemon.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c
> index f5674d824a40..83954af36753 100644
> --- a/tools/perf/builtin-daemon.c
> +++ b/tools/perf/builtin-daemon.c
> @@ -1524,7 +1524,7 @@ int cmd_daemon(int argc, const char **argv)
>         if (argc) {
>                 if (!strcmp(argv[0], "start"))
>                         ret = __cmd_start(&__daemon, daemon_options, argc, argv);
> -               if (!strcmp(argv[0], "signal"))
> +               else if (!strcmp(argv[0], "signal"))
>                         ret = __cmd_signal(&__daemon, daemon_options, argc, argv);
>                 else if (!strcmp(argv[0], "stop"))
>                         ret = __cmd_stop(&__daemon, daemon_options, argc, argv);
> --
> 2.41.0
>
  
Thomas Richter June 28, 2023, 6:04 a.m. UTC | #2
On 6/27/23 17:35, Namhyung Kim wrote:
> Hello,
> 
> On Tue, Jun 27, 2023 at 2:39 AM Thomas Richter <tmricht@linux.ibm.com> wrote:
>>
>> The perf test case Daemon operations dumps core all the time.
>> I narrowed it down to this invocation:
> 
> Jiri sent the same fix already.  I'll add your Reported-by, ok?
> 
> https://lore.kernel.org/all/20230626201606.2514679-1-jolsa@kernel.org/
> 
> Thanks,
> Namhyung
> 

sure, fine with me.
  

Patch

diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c
index f5674d824a40..83954af36753 100644
--- a/tools/perf/builtin-daemon.c
+++ b/tools/perf/builtin-daemon.c
@@ -1524,7 +1524,7 @@  int cmd_daemon(int argc, const char **argv)
 	if (argc) {
 		if (!strcmp(argv[0], "start"))
 			ret = __cmd_start(&__daemon, daemon_options, argc, argv);
-		if (!strcmp(argv[0], "signal"))
+		else if (!strcmp(argv[0], "signal"))
 			ret = __cmd_signal(&__daemon, daemon_options, argc, argv);
 		else if (!strcmp(argv[0], "stop"))
 			ret = __cmd_stop(&__daemon, daemon_options, argc, argv);