linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf daemon: Avoid msan warnings on send_cmd
@ 2021-06-17  5:55 Ian Rogers
       [not found] ` <CAP-5=fUzNak==X63zWDkMTsU8UYBACOtevED3ZR4Thruc0cWWg@mail.gmail.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Ian Rogers @ 2021-06-17  5:55 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	linux-perf-users, linux-kernel
  Cc: Ian Rogers

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>
---
 tools/perf/builtin-daemon.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c
index 61929f63a047..c13201fb09c3 100644
--- a/tools/perf/builtin-daemon.c
+++ b/tools/perf/builtin-daemon.c
@@ -1403,8 +1403,10 @@ static int send_cmd(struct daemon *daemon, union cmd *cmd)
 
 static int send_cmd_list(struct daemon *daemon)
 {
-	union cmd cmd = { .cmd = CMD_LIST, };
+	union cmd cmd;
 
+	memset(&cmd, 0, sizeof(cmd));
+	cmd.list.cmd = CMD_LIST;
 	cmd.list.verbose = verbose;
 	cmd.list.csv_sep = daemon->csv_sep ? *daemon->csv_sep : 0;
 
@@ -1432,6 +1434,7 @@ static int __cmd_signal(struct daemon *daemon, struct option parent_options[],
 		return -1;
 	}
 
+	memset(&cmd, 0, sizeof(cmd));
 	cmd.signal.cmd = CMD_SIGNAL,
 	cmd.signal.sig = SIGUSR2;
 	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[],
 		OPT_PARENT(parent_options),
 		OPT_END()
 	};
-	union cmd cmd = { .cmd = CMD_STOP, };
+	union cmd cmd;
 
 	argc = parse_options(argc, argv, start_options, daemon_usage, 0);
 	if (argc)
@@ -1457,6 +1460,8 @@ static int __cmd_stop(struct daemon *daemon, struct option parent_options[],
 		return -1;
 	}
 
+	memset(&cmd, 0, sizeof(cmd));
+	cmd.cmd = CMD_STOP;
 	return send_cmd(daemon, &cmd);
 }
 
@@ -1470,7 +1475,7 @@ static int __cmd_ping(struct daemon *daemon, struct option parent_options[],
 		OPT_PARENT(parent_options),
 		OPT_END()
 	};
-	union cmd cmd = { .cmd = CMD_PING, };
+	union cmd cmd;
 
 	argc = parse_options(argc, argv, ping_options, daemon_usage, 0);
 	if (argc)
@@ -1481,6 +1486,8 @@ static int __cmd_ping(struct daemon *daemon, struct option parent_options[],
 		return -1;
 	}
 
+	memset(&cmd, 0, sizeof(cmd));
+	cmd.cmd = CMD_PING;
 	scnprintf(cmd.ping.name, sizeof(cmd.ping.name), "%s", name);
 	return send_cmd(daemon, &cmd);
 }
-- 
2.32.0.272.g935e593368-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] perf daemon: Avoid msan warnings on send_cmd
       [not found] ` <CAP-5=fUzNak==X63zWDkMTsU8UYBACOtevED3ZR4Thruc0cWWg@mail.gmail.com>
@ 2021-09-21 19:25   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-09-21 19:25 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, linux-perf-users, linux-kernel

Em Tue, Sep 21, 2021 at 10:45:45AM -0700, Ian Rogers escreveu:
> On Wed, Jun 16, 2021 at 10:55 PM Ian Rogers <irogers@google.com> wrote:
> 
> > 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>
> >
> 
> This one appears to still be outstanding. Ping.

Thanks, applied.

- Arnaldo


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-21 19:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-17  5:55 [PATCH] perf daemon: Avoid msan warnings on send_cmd Ian Rogers
     [not found] ` <CAP-5=fUzNak==X63zWDkMTsU8UYBACOtevED3ZR4Thruc0cWWg@mail.gmail.com>
2021-09-21 19:25   ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).