[1/1] perf dlfilter: Initialize addr_location before passing it to thread__find_symbol_fb()
Message ID | ZL7ocEWxjRtWR80T@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2061557vqg; Mon, 24 Jul 2023 14:24:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlG2vp58OG0NHnc9PgKBTizoRB3sx3nmSR9tDje718m1s7eEnJTEiwYzLaJ+7oechNXaTWzP X-Received: by 2002:a05:6a21:3299:b0:130:d84b:eb91 with SMTP id yt25-20020a056a21329900b00130d84beb91mr11980977pzb.49.1690233843153; Mon, 24 Jul 2023 14:24:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690233843; cv=none; d=google.com; s=arc-20160816; b=WuGhbgC7eVE1e6Pc1k3JKAEVT9j4lzfd2eTH16cnBQbH7zU2p/bK02qsG5lKZsWHJG noQyFkNCLYS2af4wP/hDreYiSCQXU5mmTzbcaQD4u+wD1BKMhgRiQKUZvl4ZQLv6BOYl ZMinVnum6WpAVhxyytmzIxc6gKQUkHN+rZ/kdE/wNI7+ndQbf98prx0+PWu4y9h8rfPF ynE0QhDQ+cOQ0Q+fxUy9mz0BM9IT/83xSSPOD/yKuSMAJjIqGLahB2spA6Cct+LQE+DA +0DkVhqmGSdgfj/FqZVplezhSopdAeI1DOqDr5PNhL8A/KzZI1o+8d7edNkn9bdqQ/mz oT4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=ecWkKDRIhtBSRO/ocXmTyxgvdc4G7bXvRsEJOT9lwII=; fh=ume6SLGMq0zW9duCxY8mlVqU+NEoaKhQvIUvmebpXpc=; b=iC3hCWEkE+YVeH6oRvLDPZI73Y88bJxJrUiZodC/keD5NVytAz3zUcJaXQIvCAIoqf Pqf3NQpbrzI6JPy6neO0IAkJ0R0+e2VnzipLFnv+Yf7tvm3XCksznxAzIdhe9duDCFwT HBsrmL7rEnIZz7gWmNDG+mlM4wYIwhs5C3884cQqpSYpOmZZ4kvC772rE0BiRzNPZjyL lD+WbHfeBdpPl8mspHW8BCjcHhRGi0Va15SoSrYskeRkmcnZ19KmoPVqEBV3AnGs9Jcc A9Q1Ro2vCktITf4GUQ5aoS2W9dQStkHyRC2Lj/U5FMcak+tYuuMqtATs736ytkuq1dok bujA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lB3gRgm7; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dc14-20020a056a0035ce00b00682c0908d51si9888942pfb.126.2023.07.24.14.23.50; Mon, 24 Jul 2023 14:24:03 -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=@kernel.org header.s=k20201202 header.b=lB3gRgm7; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229954AbjGXVJL (ORCPT <rfc822;kautuk.consul.80@gmail.com> + 99 others); Mon, 24 Jul 2023 17:09:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229532AbjGXVJK (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 24 Jul 2023 17:09:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE04E1BC for <linux-kernel@vger.kernel.org>; Mon, 24 Jul 2023 14:09:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8743961263 for <linux-kernel@vger.kernel.org>; Mon, 24 Jul 2023 21:09:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 898A0C433C8; Mon, 24 Jul 2023 21:09:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690232947; bh=AxIobRBY2/FxVQu3cP3nLe9fjgkFu7v5YoBCsJlOszA=; h=Date:From:To:Cc:Subject:From; b=lB3gRgm7k6xhfX0uIm09ccs+nQ1AtwJpE5kTUsJ6XdDBhD/h5y+Ij/aSdKb3Ca98Z HUa1JfJj3JRmG92ARdqtfiyAe4sXl38KfcmaGmgEono4jbUCxnbqidG3Z7JiMD5JN8 QbsVOmHlgY/ZR8QjWpl0evV0A8Z+tVdZMUrdI5ixD7t/pF/KZePdrF3LtOTX+8EN0W qtdvyEaRgS4JPpTxx1HagP4g53+RguYhwfkl+3xgCzCsA4sVnTL1xJYghg5+uvHbeK 8tplp6dqxc/1LbLCGg4CvnwdFZQcmspG/BUjRbZ7yDwwOUt/1L+BWLn+lv6fxKwGpb kG04dLc142h3w== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id B203140516; Mon, 24 Jul 2023 18:09:04 -0300 (-03) Date: Mon, 24 Jul 2023 18:09:04 -0300 From: Arnaldo Carvalho de Melo <acme@kernel.org> To: Adrian Hunter <adrian.hunter@intel.com> Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>, Athira Rajeev <atrajeev@linux.vnet.ibm.com>, Disha Goel <disgoel@linux.vnet.ibm.com>, Ian Rogers <irogers@google.com>, Jiri Olsa <jolsa@kernel.org>, Kajol Jain <kjain@linux.ibm.com>, Madhavan Srinivasan <maddy@linux.ibm.com>, Namhyung Kim <namhyung@kernel.org>, Linux Kernel Mailing List <linux-kernel@vger.kernel.org> Subject: [PATCH 1/1] perf dlfilter: Initialize addr_location before passing it to thread__find_symbol_fb() Message-ID: <ZL7ocEWxjRtWR80T@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772338641872449131 X-GMAIL-MSGID: 1772338641872449131 |
Series |
[1/1] perf dlfilter: Initialize addr_location before passing it to thread__find_symbol_fb()
|
|
Commit Message
Arnaldo Carvalho de Melo
July 24, 2023, 9:09 p.m. UTC
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);
Fixes: 0dd5041c9a0eaf8c ("perf addr_location: Add init/exit/copy functions")
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/lkml/
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/dlfilter.c | 1 +
1 file changed, 1 insertion(+)
Comments
On Mon, Jul 24, 2023 at 2:09 PM Arnaldo Carvalho de Melo <acme@kernel.org> 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. Thanks, Ian > Fixes: 0dd5041c9a0eaf8c ("perf addr_location: Add init/exit/copy functions") > Cc: Adrian Hunter <adrian.hunter@intel.com> > Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> > Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> > Cc: Disha Goel <disgoel@linux.vnet.ibm.com> > Cc: Ian Rogers <irogers@google.com> > Cc: Jiri Olsa <jolsa@kernel.org> > Cc: Kajol Jain <kjain@linux.ibm.com> > Cc: Madhavan Srinivasan <maddy@linux.ibm.com> > Cc: Namhyung Kim <namhyung@kernel.org> > Link: https://lore.kernel.org/lkml/ > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> > --- > 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 >
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 > <acme@kernel.org> 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. I'll do that as well and add the addr_location__exit() then send a V2. - Arnaldo > Thanks, > Ian > > > Fixes: 0dd5041c9a0eaf8c ("perf addr_location: Add init/exit/copy functions") > > Cc: Adrian Hunter <adrian.hunter@intel.com> > > Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> > > Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> > > Cc: Disha Goel <disgoel@linux.vnet.ibm.com> > > Cc: Ian Rogers <irogers@google.com> > > Cc: Jiri Olsa <jolsa@kernel.org> > > Cc: Kajol Jain <kjain@linux.ibm.com> > > Cc: Madhavan Srinivasan <maddy@linux.ibm.com> > > Cc: Namhyung Kim <namhyung@kernel.org> > > Link: https://lore.kernel.org/lkml/ > > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> > > --- > > 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 > >
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 >> <acme@kernel.org> 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. > > 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 <adrian.hunter@intel.com> >>> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> >>> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> >>> Cc: Disha Goel <disgoel@linux.vnet.ibm.com> >>> Cc: Ian Rogers <irogers@google.com> >>> Cc: Jiri Olsa <jolsa@kernel.org> >>> Cc: Kajol Jain <kjain@linux.ibm.com> >>> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> >>> Cc: Namhyung Kim <namhyung@kernel.org> >>> Link: https://lore.kernel.org/lkml/ >>> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> >>> --- >>> 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 >>> >
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 > >> <acme@kernel.org> 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. - 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 <adrian.hunter@intel.com> > >>> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> > >>> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> > >>> Cc: Disha Goel <disgoel@linux.vnet.ibm.com> > >>> Cc: Ian Rogers <irogers@google.com> > >>> Cc: Jiri Olsa <jolsa@kernel.org> > >>> Cc: Kajol Jain <kjain@linux.ibm.com> > >>> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> > >>> Cc: Namhyung Kim <namhyung@kernel.org> > >>> Link: https://lore.kernel.org/lkml/ > >>> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> > >>> --- > >>> 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 > >>> > > >
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 >>>> <acme@kernel.org> 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. > > - 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 <adrian.hunter@intel.com> >>>>> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> >>>>> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> >>>>> Cc: Disha Goel <disgoel@linux.vnet.ibm.com> >>>>> Cc: Ian Rogers <irogers@google.com> >>>>> Cc: Jiri Olsa <jolsa@kernel.org> >>>>> Cc: Kajol Jain <kjain@linux.ibm.com> >>>>> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> >>>>> Cc: Namhyung Kim <namhyung@kernel.org> >>>>> Link: https://lore.kernel.org/lkml/ >>>>> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> >>>>> --- >>>>> 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 >>>>> >>> >> >
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 >>>>> <acme@kernel.org> 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 <adrian.hunter@intel.com> >>>>>> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> >>>>>> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> >>>>>> Cc: Disha Goel <disgoel@linux.vnet.ibm.com> >>>>>> Cc: Ian Rogers <irogers@google.com> >>>>>> Cc: Jiri Olsa <jolsa@kernel.org> >>>>>> Cc: Kajol Jain <kjain@linux.ibm.com> >>>>>> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> >>>>>> Cc: Namhyung Kim <namhyung@kernel.org> >>>>>> Link: https://lore.kernel.org/lkml/ >>>>>> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> >>>>>> --- >>>>>> 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 >>>>>> >>>> >>> >> >
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);