From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCCCBC433E0 for ; Mon, 15 Mar 2021 12:48:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A0FC064E07 for ; Mon, 15 Mar 2021 12:48:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229505AbhCOMsL (ORCPT ); Mon, 15 Mar 2021 08:48:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:60834 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbhCOMr7 (ORCPT ); Mon, 15 Mar 2021 08:47:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615812478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hBSD9TbkBF+MmfQB/up8Gu8cM8NveQ/rUjDfd4kB8sY=; b=PZNxN62t2946/VmnklD1TCYMnDHBrsDEElAgWB7HHtzc0RdyHeLg2aUgI6gq379/Msemft P4QHUiswy19nYwxDmEKE7+/cYcikP0RYnjB8ckvLDvdqZiXqvZWtNP/bTozHgwGVRja+aO r7XhVX4prjXCt+qo/b8nhfxmwmx8FgA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-150-BM__YvbpPjKTDR6CA6GVgw-1; Mon, 15 Mar 2021 08:47:54 -0400 X-MC-Unique: BM__YvbpPjKTDR6CA6GVgw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EC4B81054F91; Mon, 15 Mar 2021 12:47:52 +0000 (UTC) Received: from krava (unknown [10.40.196.50]) by smtp.corp.redhat.com (Postfix) with SMTP id A59E05D9C0; Mon, 15 Mar 2021 12:47:49 +0000 (UTC) Date: Mon, 15 Mar 2021 13:47:48 +0100 From: Jiri Olsa To: Jackie Liu Cc: linux-kernel@vger.kernel.org, Jackie Liu , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim Subject: Re: [PATCH v3] perf tools: perf_event_paranoid and kptr_restrict may crash on 'perf top' Message-ID: References: <20210313060246.37116-1-liuyun01@kylinos.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210313060246.37116-1-liuyun01@kylinos.cn> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 13, 2021 at 02:02:46PM +0800, Jackie Liu wrote: > After install the libelf-dev package and compiling perf, kptr_restrict=2 > and perf_event_paranoid=3 will cause perf top to crash, because the > value of /proc/kallsyms cannot be obtained, which leads to > info->jited_ksyms == NULL. In order to solve this problem, Add a > judgment before use. > > V2->V3: > free info_linear memory and move code above, don't do those extra btf > checks. > > Suggested-by: Jiri Olsa > Cc: Peter Zijlstra > Cc: Ingo Molnar > Cc: Arnaldo Carvalho de Melo > Cc: Mark Rutland > Cc: Alexander Shishkin > Cc: Namhyung Kim > Signed-off-by: Jackie Liu > --- > tools/perf/util/bpf-event.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c > index 57d58c81a5f8..3c03c782bac6 100644 > --- a/tools/perf/util/bpf-event.c > +++ b/tools/perf/util/bpf-event.c > @@ -201,12 +201,18 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session, > } seems like the previous check miss free(info_linear) as well? > info = &info_linear->info; > + if (!info->jited_ksyms) { > + free(info_linear); > + return -1; > + } > > /* number of ksyms, func_lengths, and tags should match */ > sub_prog_cnt = info->nr_jited_ksyms; > if (sub_prog_cnt != info->nr_prog_tags || > - sub_prog_cnt != info->nr_jited_func_lens) > + sub_prog_cnt != info->nr_jited_func_lens) { > + free(info_linear); > return -1; > + } > > /* check BTF func info support */ > if (info->btf_id && info->nr_func_info && info->func_info_rec_size) { > -- > 2.25.1 >