Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4193528rwb; Mon, 31 Jul 2023 03:06:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlEJyVsUIQQGp0W1BZUQPSUrqdRf4VzDsPyuIMNru1/8ar8IFBJiTTuF8H8vWqjTngCnnPla X-Received: by 2002:a17:902:8207:b0:1b9:ebe9:5f01 with SMTP id x7-20020a170902820700b001b9ebe95f01mr9568920pln.19.1690798006541; Mon, 31 Jul 2023 03:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690798006; cv=none; d=google.com; s=arc-20160816; b=m7UU3VW0sEVhb5WIs3z4joP2dvhY9HouqC1RAzYiC1Kw2ZFi4T0ap2jNTeYN8Wd6Es 7J3jI4YBcAsqFq3Gyu/IMMyRXrv8jZu/7CObjeDplhlbkuh/qBhqd+v6oMK87KacTJIj l0OHhi2eWA8tRvg8sauKLdc9ZYyD+JAPw/oYeeLI2dkj+dM37ihb5B905EKHCsy0RYDV kGBclanRr6u5xapK/KV0V+PqrRPqh9E0TIEaTmA+C+rJXa5dXySZCCHKYHXvYS735f8S nNzo09ikUkZzXI0fzOq91RGMRR3ZnKk7+RWzM4/oNwBe9UiiiWNjdcMHWG5fcg3CT1Df jbmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:content-language:references:cc:to:from:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=CCkRz5OZ51GyTL1PxySkiFEKL2hFYQDElks+rtPr8Sk=; fh=WCvXGXao3YeQI0xfneHxOF1IstS52/O0Lt7DQXD4Qhg=; b=RDlKYYkxQMlqXY7zlRKq28NbKrkF2rfYo0RQ8lUE2sMxtNz91emwVH45WTQfRupaUH pbf7LZEF96b5xPMKy3Obf7iujgP75EVartiX84zBOL+F2T7w4uSuy1gBn9LqEka0/zas kEGWu5FGaaP4Ab4lsVHxprdsi31nl+hitOMwlqWC2fW9YtCxyjz2f0H7BREJF2/CpNdm h5xpoyqeZvq/JsOa4Xcr4oINTQfCxdkOaamDuiW+yBJ9er4s8FC1KZSGSsdiO221LhxY +VD1WpsJmyeGsYcF/v05UcG4Fbu7Kv9hDRHLJ2nwuewwo2qZyS7hQyYWnuKo6BUoqjYF uwQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V3w7BvsW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020a17090340c200b001b8419bd0f5si7184407pld.254.2023.07.31.03.06.33; Mon, 31 Jul 2023 03:06:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V3w7BvsW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231806AbjGaJ07 (ORCPT + 99 others); Mon, 31 Jul 2023 05:26:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231795AbjGaJ0d (ORCPT ); Mon, 31 Jul 2023 05:26:33 -0400 Received: from mgamail.intel.com (unknown [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49340E7A for ; Mon, 31 Jul 2023 02:26:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690795570; x=1722331570; h=message-id:date:mime-version:subject:from:to:cc: references:in-reply-to:content-transfer-encoding; bh=5DroKSxtJt7ROa5ru6XtTRU2BpA/NiTBkY1GaPFsUQI=; b=V3w7BvsWb6ULAIPLc4IumkP+1s9IPHFmmAwV6XI4r+nHLmP+Fn9sMXUr 4kk6neE3Nss+dz7QCdT4+65D5ktYr9hY9WfZs4uXuiEYH8oI5FG7tUau9 euUKDl1Y0/XDp38ApuSTUqUtTeyOU95Dhtd/KiaC1e0NKOCfO8gaGRiAn ODo5GAz6WrG/cx4yBLh8gpQEX3BVSMfIWXZPyDM4F7wDHqpYawIxDpwRq z7/kYHrKC/r5NXRQB+RkStiLHjmX4HETlX2s3qDYMqMC9Er6qZbzCKLS9 n+bAekdeOVWRzo/v5WNN4JA267WbGz6xmfDAxzpySh8njA+gcikT+CWK7 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10787"; a="372600334" X-IronPort-AV: E=Sophos;i="6.01,244,1684825200"; d="scan'208";a="372600334" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jul 2023 02:26:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10787"; a="731535642" X-IronPort-AV: E=Sophos;i="6.01,244,1684825200"; d="scan'208";a="731535642" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.251.208.223]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jul 2023 02:26:04 -0700 Message-ID: <1d10fab5-d375-79b8-122d-f3cb66f2d94a@intel.com> Date: Mon, 31 Jul 2023 12:26:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.13.1 Subject: Re: [PATCH 1/1] perf dlfilter: Initialize addr_location before passing it to thread__find_symbol_fb() From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Ian Rogers , "Aneesh Kumar K.V" , Athira Rajeev , Disha Goel , Jiri Olsa , Kajol Jain , Madhavan Srinivasan , Namhyung Kim , Linux Kernel Mailing List References: <95590e6a-0747-a365-4de1-0ccd8fdfc257@intel.com> Content-Language: en-US Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki In-Reply-To: <95590e6a-0747-a365-4de1-0ccd8fdfc257@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 28/07/23 22:18, Adrian Hunter wrote: > On 27/07/23 17:13, Arnaldo Carvalho de Melo wrote: >> Em Tue, Jul 25, 2023 at 02:51:58PM +0300, Adrian Hunter escreveu: >>> On 25/07/23 00:31, Arnaldo Carvalho de Melo wrote: >>>> Em Mon, Jul 24, 2023 at 02:16:05PM -0700, Ian Rogers escreveu: >>>>> On Mon, Jul 24, 2023 at 2:09 PM Arnaldo Carvalho de Melo >>>>> wrote: >>>>>> >>>>>> As thread__find_symbol_fb() will end up calling thread__find_map() and >>>>>> it in turn will call these on uninitialized memory: >>>>>> >>>>>> maps__zput(al->maps); >>>>>> map__zput(al->map); >>>>>> thread__zput(al->thread); >>>>> >>>>> Normally there would be a addr_location__exit. It looks here like most >>>>> values are copied in al_to_d_al, which copies reference counted values >>>>> without doing appropriate gets. Perhaps add the gets in al_to_d_al and >>>>> add the exit to make it clear there can't be addr_location related >>>>> leaks here. >> >> Or just make al_to_d_al use strdups for the strings it gets from >> reference counter structs. >> >> That or make the caller of ->resolve_address() provide a initialized >> addr_location that it then exits. > > OK, I will send a patch. 2 patches plus yours: https://lore.kernel.org/linux-perf-users/20230731091857.10681-1-adrian.hunter@intel.com/T/#t > >> >> - Arnaldo >> >>>> I'll do that as well and add the addr_location__exit() then send a V2. >>> >>> The data is not valid outside the context of ->filter_event() or >>> ->filter_event_early(), so the reference counts should not be changed. >>> That probably needs to be made clearer in the documentation. >> >> >> >>>> >>>> - Arnaldo >>>> >>>>> Thanks, >>>>> Ian >>>>> >>>>>> Fixes: 0dd5041c9a0eaf8c ("perf addr_location: Add init/exit/copy functions") >>>>>> Cc: Adrian Hunter >>>>>> Cc: Aneesh Kumar K.V >>>>>> Cc: Athira Rajeev >>>>>> Cc: Disha Goel >>>>>> Cc: Ian Rogers >>>>>> Cc: Jiri Olsa >>>>>> Cc: Kajol Jain >>>>>> Cc: Madhavan Srinivasan >>>>>> Cc: Namhyung Kim >>>>>> Link: https://lore.kernel.org/lkml/ >>>>>> Signed-off-by: Arnaldo Carvalho de Melo >>>>>> --- >>>>>> tools/perf/util/dlfilter.c | 1 + >>>>>> 1 file changed, 1 insertion(+) >>>>>> >>>>>> diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c >>>>>> index 46f74b2344dbb34c..798a53d7e6c9dfc5 100644 >>>>>> --- a/tools/perf/util/dlfilter.c >>>>>> +++ b/tools/perf/util/dlfilter.c >>>>>> @@ -166,6 +166,7 @@ static __s32 dlfilter__resolve_address(void *ctx, __u64 address, struct perf_dlf >>>>>> if (!thread) >>>>>> return -1; >>>>>> >>>>>> + addr_location__init(&al); >>>>>> thread__find_symbol_fb(thread, d->sample->cpumode, address, &al); >>>>>> >>>>>> al_to_d_al(&al, &d_al); >>>>>> -- >>>>>> 2.37.1 >>>>>> >>>> >>> >> >