lkml.org 
[lkml]   [2021]   [Nov]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.4 51/51] perf script: Check session->header.env.arch before using it
    Date
    From: Song Liu <songliubraving@fb.com>

    commit 29c77550eef31b0d72a45b49eeab03b8963264e8 upstream.

    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.

    Committer notes:

    If it is a pipe, we already assume is a native arch, so no need to check
    session->header.env.arch.

    Signed-off-by: Song Liu <songliubraving@fb.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: kernel-team@fb.com
    Cc: stable@vger.kernel.org
    Link: http://lore.kernel.org/lkml/20211004053238.514936-1-songliubraving@fb.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    ---
    tools/perf/builtin-script.c | 12 ++++++++----
    1 file changed, 8 insertions(+), 4 deletions(-)

    --- a/tools/perf/builtin-script.c
    +++ b/tools/perf/builtin-script.c
    @@ -3779,11 +3779,15 @@ int cmd_script(int argc, const char **ar
    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;
    + } else if (session->header.env.arch) {
    + 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);

    \
     
     \ /
      Last update: 2021-11-01 10:33    [W:5.297 / U:0.732 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site