From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Howard Chu <howardchu95@gmail.com>
Cc: Benjamin Peterson <benjamin@engflow.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
"Liang, Kan" <kan.liang@linux.intel.com>,
"open list:PERFORMANCE EVENTS SUBSYSTEM"
<linux-perf-users@vger.kernel.org>,
"open list:PERFORMANCE EVENTS SUBSYSTEM"
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 2/3] perf trace: avoid garbage when not printing a syscall's arguments
Date: Thu, 14 Nov 2024 18:08:53 -0300 [thread overview]
Message-ID: <ZzZm5XbY4ddalbWr@x1> (raw)
In-Reply-To: <CAH0uvojHH-wmbieqgtVyc7pGWQ0gyrzkWdtUkLpSyreub1uk_Q@mail.gmail.com>
On Fri, Nov 08, 2024 at 08:21:30AM -0800, Howard Chu wrote:
> Hello,
>
> This patch solves the garbage output problem I got, and your test can be run.
I'm taking this as a Tested-by you, ok?
- Arnaldo
> Thanks,
> Howard
>
> On Thu, Nov 7, 2024 at 3:21 PM Benjamin Peterson <benjamin@engflow.com> wrote:
> >
> > syscall__scnprintf_args may not place anything in the output buffer
> > (e.g., because the arguments are all zero). If that happened in
> > trace__fprintf_sys_enter, its fprintf would receive an unitialized
> > buffer leading to garbage output.
> >
> > Fix the problem by passing the (possibly zero) bounds of the argument
> > buffer to the output fprintf.
> >
> > Fixes: a98392bb1e169 ("perf trace: Use beautifiers on syscalls:sys_enter_ handlers")
> > Signed-off-by: Benjamin Peterson <benjamin@engflow.com>
> > ---
> > tools/perf/builtin-trace.c | 5 +++--
> > 1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> > index f6179b13b8b4..28f61d10a2f8 100644
> > --- a/tools/perf/builtin-trace.c
> > +++ b/tools/perf/builtin-trace.c
> > @@ -2702,6 +2702,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel,
> > char msg[1024];
> > void *args, *augmented_args = NULL;
> > int augmented_args_size;
> > + size_t printed = 0;
> >
> > if (sc == NULL)
> > return -1;
> > @@ -2717,8 +2718,8 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel,
> >
> > args = perf_evsel__sc_tp_ptr(evsel, args, sample);
> > augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_syscalls_args_size);
> > - syscall__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread);
> > - fprintf(trace->output, "%s", msg);
> > + printed += syscall__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread);
> > + fprintf(trace->output, "%.*s", (int)printed, msg);
> > err = 0;
> > out_put:
> > thread__put(thread);
> > --
> > 2.39.5
> >
> >
next prev parent reply other threads:[~2024-11-14 21:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-07 23:21 [PATCH v2 1/3] perf trace: do not lose last events in a race Benjamin Peterson
2024-11-07 23:21 ` [PATCH v2 2/3] perf trace: avoid garbage when not printing a syscall's arguments Benjamin Peterson
2024-11-08 16:21 ` Howard Chu
2024-11-14 21:08 ` Arnaldo Carvalho de Melo [this message]
2024-11-07 23:21 ` [PATCH v2 3/3] perf tests: add test for trace output loss Benjamin Peterson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZzZm5XbY4ddalbWr@x1 \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=benjamin@engflow.com \
--cc=howardchu95@gmail.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.