Skip to content

Commit b28e5e4

Browse files
captain5050acmel
authored andcommitted
perf daemon: Avoid msan warnings on send_cmd
As a full union is always sent, ensure all bytes of the union are initialized with memset to avoid msan warnings of use of uninitialized memory. An example warning from the daemon test: Uninitialized bytes in __interceptor_write at offset 71 inside [0x7ffd98da6280, 72) ==11602==WARNING: MemorySanitizer: use-of-uninitialized-value #0 0x5597edccdbe4 in ion tools/lib/perf/lib.c:18:6 #1 0x5597edccdbe4 in writen tools/lib/perf/lib.c:47:9 #2 0x5597ed221d30 in send_cmd tools/perf/builtin-daemon.c:1376:22 #3 0x5597ed21b48c in cmd_daemon tools/perf/builtin-daemon.c #4 0x5597ed1d6b67 in run_builtin tools/perf/perf.c:313:11 #5 0x5597ed1d6036 in handle_internal_command tools/perf/perf.c:365:8 #6 0x5597ed1d6036 in run_argv tools/perf/perf.c:409:2 #7 0x5597ed1d6036 in main tools/perf/perf.c:539:3 SUMMARY: MemorySanitizer: use-of-uninitialized-value tools/lib/perf/lib.c:18:6 in ion Exiting Signed-off-by: Ian Rogers <irogers@google.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/20210617055554.1917997-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 4122c9c commit b28e5e4

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

tools/perf/builtin-daemon.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,8 +1403,10 @@ static int send_cmd(struct daemon *daemon, union cmd *cmd)
14031403

14041404
static int send_cmd_list(struct daemon *daemon)
14051405
{
1406-
union cmd cmd = { .cmd = CMD_LIST, };
1406+
union cmd cmd;
14071407

1408+
memset(&cmd, 0, sizeof(cmd));
1409+
cmd.list.cmd = CMD_LIST;
14081410
cmd.list.verbose = verbose;
14091411
cmd.list.csv_sep = daemon->csv_sep ? *daemon->csv_sep : 0;
14101412

@@ -1432,6 +1434,7 @@ static int __cmd_signal(struct daemon *daemon, struct option parent_options[],
14321434
return -1;
14331435
}
14341436

1437+
memset(&cmd, 0, sizeof(cmd));
14351438
cmd.signal.cmd = CMD_SIGNAL,
14361439
cmd.signal.sig = SIGUSR2;
14371440
strncpy(cmd.signal.name, name, sizeof(cmd.signal.name) - 1);
@@ -1446,7 +1449,7 @@ static int __cmd_stop(struct daemon *daemon, struct option parent_options[],
14461449
OPT_PARENT(parent_options),
14471450
OPT_END()
14481451
};
1449-
union cmd cmd = { .cmd = CMD_STOP, };
1452+
union cmd cmd;
14501453

14511454
argc = parse_options(argc, argv, start_options, daemon_usage, 0);
14521455
if (argc)
@@ -1457,6 +1460,8 @@ static int __cmd_stop(struct daemon *daemon, struct option parent_options[],
14571460
return -1;
14581461
}
14591462

1463+
memset(&cmd, 0, sizeof(cmd));
1464+
cmd.cmd = CMD_STOP;
14601465
return send_cmd(daemon, &cmd);
14611466
}
14621467

@@ -1470,7 +1475,7 @@ static int __cmd_ping(struct daemon *daemon, struct option parent_options[],
14701475
OPT_PARENT(parent_options),
14711476
OPT_END()
14721477
};
1473-
union cmd cmd = { .cmd = CMD_PING, };
1478+
union cmd cmd;
14741479

14751480
argc = parse_options(argc, argv, ping_options, daemon_usage, 0);
14761481
if (argc)
@@ -1481,6 +1486,8 @@ static int __cmd_ping(struct daemon *daemon, struct option parent_options[],
14811486
return -1;
14821487
}
14831488

1489+
memset(&cmd, 0, sizeof(cmd));
1490+
cmd.cmd = CMD_PING;
14841491
scnprintf(cmd.ping.name, sizeof(cmd.ping.name), "%s", name);
14851492
return send_cmd(daemon, &cmd);
14861493
}

0 commit comments

Comments
 (0)