[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <806C5000-3A49-42B0-B0AE-7ED001CB11EE@fb.com>
Date: Wed, 27 Oct 2021 16:41:50 +0000
From: Song Liu <songliubraving@...com>
To: Arnaldo Carvalho de Melo <acme@...nel.org>
CC: LKML <linux-kernel@...r.kernel.org>,
Kernel Team <Kernel-team@...com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>, stable <stable@...r.kernel.org>
Subject: Re: [PATCH] perf-script: check session->header.env.arch before using
it
> On Oct 27, 2021, at 5:39 AM, Arnaldo Carvalho de Melo <acme@...nel.org> wrote:
>
> Em Sun, Oct 03, 2021 at 10:32:38PM -0700, Song Liu escreveu:
>> When perf.data is not written cleanly, we would like to process existing
>> data as much as possible (please see f_header.data.size == 0 condition
>> in perf_session__read_header). However, perf.data with partial data may
>> crash perf. Specifically, we see crash in perf-script for NULL
>> session->header.env.arch.
>>
>> Fix this by checking session->header.env.arch before using it to determine
>> native_arch. Also split the if condition so it is easier to read.
>>
>> Cc: stable@...r.kernel.org
>> Signed-off-by: Song Liu <songliubraving@...com>
>> ---
>> tools/perf/builtin-script.c | 13 +++++++++----
>> 1 file changed, 9 insertions(+), 4 deletions(-)
>>
>> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
>> index 6211d0b84b7a6..7821f6740ac1d 100644
>> --- a/tools/perf/builtin-script.c
>> +++ b/tools/perf/builtin-script.c
>> @@ -4039,12 +4039,17 @@ int cmd_script(int argc, const char **argv)
>> goto out_delete;
>>
>> uname(&uts);
>> - if (data.is_pipe || /* assume pipe_mode indicates native_arch */
>> - !strcmp(uts.machine, session->header.env.arch) ||
>> - (!strcmp(uts.machine, "x86_64") &&
>> - !strcmp(session->header.env.arch, "i386")))
>> + if (data.is_pipe) /* assume pipe_mode indicates native_arch */
>> native_arch = true;
>>
>> + if (session->header.env.arch) {
>
> Shouldn't the above be:
>
> else if (session->header.env.arch) {
>
> ?
Yes! That's better.
Do you want me to send v2 with the change?
Thanks,
Song
>
>> + if (!strcmp(uts.machine, session->header.env.arch))
>> + native_arch = true;
>> + else if (!strcmp(uts.machine, "x86_64") &&
>> + !strcmp(session->header.env.arch, "i386"))
>> + native_arch = true;
>> + }
>> +
>> script.session = session;
>> script__setup_sample_type(&script);
>>
>> --
>> 2.30.2
>
> --
>
> - Arnaldo
Powered by blists - more mailing lists