Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1361390rwd; Thu, 8 Jun 2023 17:09:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7RgAbQc6P65xRAp+CNV+u6ViideWn4PuFmeH0g5PXAsl62GGfhdsXm3PVOsOK4oUI6qcvi X-Received: by 2002:a05:6a00:3a26:b0:659:3031:5037 with SMTP id fj38-20020a056a003a2600b0065930315037mr12249900pfb.3.1686269372631; Thu, 08 Jun 2023 17:09:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686269372; cv=none; d=google.com; s=arc-20160816; b=zipyfDMkJ/0aJydoglPC1zOyqBc/5+jDvUVpBklFAj+sjY09cfcerqB8ekGMobgW4b IMFmkdpZv24sMKRVluE3mQSkPmDukD9xG9bbuekblgP57grR9h0O3Q0lycyo4MllVQ0J N4EbErYaqw6mo888iogqhpe5PQmt1EwhbuqePEB89UFNQqNrTnD+UHafpz4smDRszRKE RynWB/2aX/TqHgVUniGctUK2MBFna/uhCO32m7SYMjI6NsbEvyLVF3phGzPAfPt550PU IXMZMIh11DDGNAvbuZB4FZVB5N0VVoBuu7SPFxoevOV8rQsN0XT74CI5j/LRQU7iMpdN bitQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=yGUf69TvsdEnNaIsR3ddGXV6UHIPZliOJXiSi9AkMd8=; b=GYBMKCEtYuefdxDaoLoGS5z+r0u9S80DeUZhNvCRgrrcFr7Qe28elid2tp+ClOanR3 y+cKXb63zeEjJrWPi7/lYnGxZnDeNrjkjYgmgR4PjdolLoU8uqEWRlXArR3VtBdWWt+7 I2EVaZzvJbinEY6B7qmxZGukxbNoSg55DPmk1tTenIEHx9+D42urR3a0MLi9qMF2QtF6 +u+PSWTGfSPd7uTorCbvw7IeoeKQBxial8Wjb2sS2/fPP4yzRU6AuLXIJSot2NJQcqTI SNgVWcv7VvbKT4mXmzkQNbe9DcUCkfC+pewBn07id8TY6A11TGOfCkjzQQxJc7GiaEMb 0UHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=pj+cfLWh; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv7-20020a632e07000000b00530b70aac4asi1751922pgb.91.2023.06.08.17.09.21; Thu, 08 Jun 2023 17:09:32 -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=@google.com header.s=20221208 header.b=pj+cfLWh; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237480AbjFHXbL (ORCPT + 99 others); Thu, 8 Jun 2023 19:31:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237476AbjFHXaW (ORCPT ); Thu, 8 Jun 2023 19:30:22 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3E3B3A8B for ; Thu, 8 Jun 2023 16:29:57 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-565a66a5d84so15734087b3.0 for ; Thu, 08 Jun 2023 16:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686266996; x=1688858996; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=yGUf69TvsdEnNaIsR3ddGXV6UHIPZliOJXiSi9AkMd8=; b=pj+cfLWhmvN+fFVnoiQM42+qIryqDUimhVDEqfmtvHnlEMal5DUHbUXirbPSFWbrXl TVxKULuQgeyTD8ezUOpRIuKywDDAPZ8xE0fFiawIFwduHPH9FORZrnn6WUXqVFweowYF ehf8+d1JTUDjZgUFYCGWN2yKCSFLiLgosTtMM/ZBrrlBbSh1AesSWwqpYkBaNx5UgBEl bf3jN2Y+kOmSQ0gOGeCvq6cHlWjE2fKo5bzeUGhJU5DZy9UNpmCWwcYxZ1p2q9PHq1dx SEDb6U4MeNf7OqW2QvuRJ262VrHkjKsRUyHli3nBlXxIkbyqp99m569COtsbWx0pwBIQ thMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686266996; x=1688858996; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yGUf69TvsdEnNaIsR3ddGXV6UHIPZliOJXiSi9AkMd8=; b=P64KFamc8u2Clkp5liu9WZaoaQo9VHyDCB+qhEUeGqC23UUqKdjfKEB76xQCNXSX1Q 0iaU7fFNMWbagOIQKS+hdtI3X+bnNiaExpxBzHr9XXtjLhIPuAZUY6hDOVF82GIqrEer j5oWhKJzf8JgciAFxJ0MVKUcSLY/GzcZuiBRKNg5uC/X4vO6KwzoH467KzQde/FntYhR NryTpDvGnxmOH6GAjbqWbOrq7oJ2CZVY65THgY55sjd4QoaVxt2MAWjhxe5hVJCexFIT D/k1twAH8fSKaXaUIKzXZoZ/vkBVfTPYXOReFixe/jFSoiKTOfHpkoS13n3r9Q6iRIG/ N5GQ== X-Gm-Message-State: AC+VfDxg7Bbls8DfalDUZrvOLmUKLl3brIwRdjL6NFjM3xtiguHZ4VkO Vn2cJVN4PBiTacpTmlnc0PqOUltvVoMs X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:c3e5:ebc6:61e5:c73f]) (user=irogers job=sendgmr) by 2002:a81:cf02:0:b0:555:cd45:bc3a with SMTP id u2-20020a81cf02000000b00555cd45bc3amr656760ywi.9.1686266996318; Thu, 08 Jun 2023 16:29:56 -0700 (PDT) Date: Thu, 8 Jun 2023 16:28:15 -0700 In-Reply-To: <20230608232823.4027869-1-irogers@google.com> Message-Id: <20230608232823.4027869-19-irogers@google.com> Mime-Version: 1.0 References: <20230608232823.4027869-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Subject: [PATCH v2 18/26] perf machine: Fix leak of kernel dso From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , "Naveen N. Rao" , Kan Liang , German Gomez , Ali Saidi , Jing Zhang , Athira Rajeev , Miguel Ojeda , ye xingchen , Liam Howlett , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , K Prateek Nayak , Changbin Du , Ravi Bangoria , Sean Christopherson , Andi Kleen , "Steinar H. Gunderson" , Yuan Can , Brian Robbins , liuwenyu , Ivan Babrou , Fangrui Song , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, coresight@lists.linaro.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 The kernel dso may be found by searching dsos or allocating if not found. The allocation returns with a reference count of 2, once for the dsos list and once for the returned value. The list search has a reference count of 1, once for the dsos list. To make the reference counts consistent, increase the dsos list search reference count to 2 with a dso__get, and do a put when the scope ends for either the allocated or found dso. This issue was found with leak sanitizer and reference count checking. Signed-off-by: Ian Rogers --- tools/perf/util/machine.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 46af5e9748c9..f8e6c07f0048 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -1868,7 +1868,7 @@ static int machine__process_kernel_mmap_event(struct machine *machine, continue; - kernel = dso; + kernel = dso__get(dso); break; } @@ -1913,6 +1913,7 @@ static int machine__process_kernel_mmap_event(struct machine *machine, */ dso__load(kernel, machine__kernel_map(machine)); } + dso__put(kernel); } else if (perf_event__is_extra_kernel_mmap(machine, xm)) { return machine__process_extra_kernel_map(machine, xm); } -- 2.41.0.162.gfafddb0af9-goog