Skip to contentSkip to conversation

perf/test: perf test case Daemon operations dumps core

PATCH In review Thomas Richter 2 participants 3 messages Jun 27, 2023 – Jun 28, 2023 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf/test: perf test case Daemon operations dumps core

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")
---
 tools/perf/builtin-daemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-daemon.c +1 -1
index f5674d824a40..83954af36753 100644
@@ -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);
Signature · 1 line
2.41.0
#1 lore raw

Hello,

Quoted 3 lines · Thomas Richter

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/[email protected]/

Thanks,
Namhyung

Quoted 113 lines

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*
(quoted diff) +0 -9
-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")
---
 tools/perf/builtin-daemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-daemon.c +1 -2
index f5674d824a40..83954af36753 100644
@@ -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

#2 lore raw
Quoted 7 lines · Namhyung Kim

Hello,

Quoted 3 lines · Thomas Richter

The perf test case Daemon operations dumps core all the time. I narrowed it down to this invocation:

Quoted 7 lines

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

https://lore.kernel.org/all/[email protected]/

Thanks,
Namhyung

sure, fine with me.

Signature · 5 lines
Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany
--
Vorsitzender des Aufsichtsrats: Gregor Pillen
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294