Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp550762ybg; Fri, 12 Jun 2020 08:23:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznj5wtHTKfuZZhRqmBdWxF2YYS62lI7WEHbzBRlVBYj5qf3fM3LtiXy68RjHCrmSQ3jom4 X-Received: by 2002:a17:906:e257:: with SMTP id gq23mr12885418ejb.398.1591975434794; Fri, 12 Jun 2020 08:23:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591975434; cv=none; d=google.com; s=arc-20160816; b=DXmtKTupPXEHZXPFurxh9QAfC34rZk9/4qUMteGvecnS+7Bpx/Alx31CSiGCXiUjVX wf7zqPY9eqJhqAq6Seu0Ly3Qh0NCMx35hHJOHniwaKACAIUtBUCPYbrxghm5MZlCcudC 0tISgMSE9jjpD4K0uPtfhi0P8DTZ+SN0H+hG25iEFo+PwnsSvwx3bHG8ifUHJJv+uT/O +yrRoO/khfyaRErLuI2Duka5msh8NbNaxZgOpkmr35AmyCWT71sYBG5Nsbiz8lNaaCXx ZykNUxUdPlCvgKDUxwyA03Mi0hKq/zJ/cbTdSglBFWZjKqgfk12xFmTbCSjSGdTY3f6F N6cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=cajqpKXE8yQj5rlg6u/javkCEuVr1o97RawpHhA99Xk=; b=nCZr+k0csYxFZjLyojqb9JWC/gpsA5xkZYS7GVxPa5T/4LE5MWumpnwd8tGn1r31Mp nXCrRQKRBFSEFJPLCpS6xZfab62BhrbKu8ioZ5e3pVutLfTfL4tiiP6i/ol4IoaiwVLE 79aM1qI7SNylT4NSKFij3IR83uBMB9XLGn9QcxDjMHGxJO86CLbaZlC1K+M2DCZZ5UD4 h5wkuzIZqx7WxP3nTVgHj0ImgXKs2/s/QLg8+kCe/JxDNmYKbA/7Us6WAVLj44NbBpB3 0P56uxT8ASk6y2113EXTKwKa5vMoe+V/6G5O9cHfJUZzkjzsLHnmoBrjm9t0fn8YGEhr Vz1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q19si3681629edr.139.2020.06.12.08.23.31; Fri, 12 Jun 2020 08:23:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726551AbgFLPTZ (ORCPT + 99 others); Fri, 12 Jun 2020 11:19:25 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35400 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726535AbgFLPTX (ORCPT ); Fri, 12 Jun 2020 11:19:23 -0400 Received: by mail-wm1-f66.google.com with SMTP id q25so8674440wmj.0 for ; Fri, 12 Jun 2020 08:19:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cajqpKXE8yQj5rlg6u/javkCEuVr1o97RawpHhA99Xk=; b=IyCREDWTGGLE9QbGkAyyN5vdIRNT54ev/59UGBUKgwuwGVNhe7NNFL8ej9AANFBr1q utJ+dW3TysHSJ2R2b5rLw7QexEzul8GNmGrNpLh1DxvvjipI+C2ADs70ZpVB8b0pNG70 mpA5F/2Icr9Wg2M2gzzaJR7ZUVFDgJ7zVKFGPgY/cBh2jxsK3iScwfdzALX4nj3bU6Jl LsXegN8CdQnIycz9DhoEYScWxEhH7JyUxc9bUpVPw95iZEoNMZ1IuYOXgAoSRD7lB3JD 0Tn9oHa7AO6FZO0JS/ufyEP7u/fTsj7iB7B7LlPeXqs2pdilPolu3yR9EXRvGvZTMZ4B 14PQ== X-Gm-Message-State: AOAM531dP0tRV9v9HpOWCgYbCuQ6io3Q3Em7U3InNBvUX/nXO96Z2QlS aTt4+t6p1hko3C6kmLtjY9e7gzPsxpvbPKJgyB0= X-Received: by 2002:a7b:cf2c:: with SMTP id m12mr13870562wmg.70.1591975161316; Fri, 12 Jun 2020 08:19:21 -0700 (PDT) MIME-Version: 1.0 References: <20200612094322.39565-1-liwei391@huawei.com> In-Reply-To: <20200612094322.39565-1-liwei391@huawei.com> From: Namhyung Kim Date: Sat, 13 Jun 2020 00:19:10 +0900 Message-ID: Subject: Re: [PATCH] perf report TUI: Fix segmentation fault in perf_evsel__hists_browse() To: Wei Li Cc: Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , linux-kernel , Jin Yao , Andi Kleen , guohanjun@huawei.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Fri, Jun 12, 2020 at 6:58 PM Wei Li wrote: > > The segmentation fault can be reproduced as following steps: > 1) Executing perf report in tui. > 2) Typing '/xxxxx' to filter the symbol to get nothing matched. > 3) Pressing enter with no entry selected. > Then it will report a segmentation fault. > > It is caused by the lack of check of browser->he_selection when > accessing it's member res_samples in perf_evsel__hists_browse(). > > These processes are meaningful for specified samples, so we can > skip these when nothing is selected. > > Fixes: 4968ac8fb7c3 ("perf report: Implement browsing of individual samples") > Signed-off-by: Wei Li Acked-by: Namhyung Kim Thanks Namhyung > --- > tools/perf/ui/browsers/hists.c | 17 +++++++++++------ > 1 file changed, 11 insertions(+), 6 deletions(-) > > diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c > index 487e54ef56a9..2101b6b770d8 100644 > --- a/tools/perf/ui/browsers/hists.c > +++ b/tools/perf/ui/browsers/hists.c > @@ -2288,6 +2288,11 @@ static struct thread *hist_browser__selected_thread(struct hist_browser *browser > return browser->he_selection->thread; > } > > +static struct res_sample *hist_browser__selected_res_sample(struct hist_browser *browser) > +{ > + return browser->he_selection ? browser->he_selection->res_samples : NULL; > +} > + > /* Check whether the browser is for 'top' or 'report' */ > static inline bool is_report_browser(void *timer) > { > @@ -3357,16 +3362,16 @@ static int perf_evsel__hists_browse(struct evsel *evsel, int nr_events, > &options[nr_options], NULL, NULL, evsel); > nr_options += add_res_sample_opt(browser, &actions[nr_options], > &options[nr_options], > - hist_browser__selected_entry(browser)->res_samples, > - evsel, A_NORMAL); > + hist_browser__selected_res_sample(browser), > + evsel, A_NORMAL); > nr_options += add_res_sample_opt(browser, &actions[nr_options], > &options[nr_options], > - hist_browser__selected_entry(browser)->res_samples, > - evsel, A_ASM); > + hist_browser__selected_res_sample(browser), > + evsel, A_ASM); > nr_options += add_res_sample_opt(browser, &actions[nr_options], > &options[nr_options], > - hist_browser__selected_entry(browser)->res_samples, > - evsel, A_SOURCE); > + hist_browser__selected_res_sample(browser), > + evsel, A_SOURCE); > nr_options += add_switch_opt(browser, &actions[nr_options], > &options[nr_options]); > skip_scripting: > -- > 2.17.1 >