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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6ADCAC7EE23 for ; Thu, 8 Jun 2023 23:30:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EhLJBsHMS/VIErWMnvFlSAs2fn0UdSSu5YHzxHMwiw8=; b=LumlADActixLb1 ozAsI84gh8Y1SzgGLIwwR/uaJ2GJPl9wMSYg6moV5raez/kyBPVB/Fs+I4joKQE+ZUyodT8bds702 /S60dGN7OVxK/YaQzCIY+E31IUfYPhifqGeX0gKnfvoSElZIzkNaG1nTibEdXuDwrMCYEH2e7FToL xoZ7lJg4jYbG+msc5SVulM18fLJpjDsVcIEcnjg/hir0w93G2J4T9mvrU6oLs/1opS68zkejubZbk 4Iyd8wqjIo8o//lYhxFWIqT0/236MWvm51ondiaXJQp7TnTdgrfRNOOW2kUqCfWB9ZEKGnjLhx17t MG9lJ6Z96N1zBu+cVrMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7P4u-00AvK5-1v; Thu, 08 Jun 2023 23:30:04 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q7P4n-00AvEp-1J for linux-arm-kernel@lists.infradead.org; Thu, 08 Jun 2023 23:29:58 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-565de4b5be5so15598007b3.1 for ; Thu, 08 Jun 2023 16:29:56 -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=RuLsLDl1yXfQ4ULz5J4BHxGry94FD52tpVnX+aOnPF5SzUecIYE29AZxO2R1BhX78l wy/WjfK3Ev+83hTCX8cO0c0CKMEcf06txGJ03iN+i1oN1uj2I6IPEmViWU+rIUHd9MHG QHjiK9mQxLDjYMOBmW8mZy6BRWNHVeOyBV/7p0IUiFJNsCdbt9/I/qJ2mQyxkxsPk52U fIbxk8u0hQttD1HE9VLIXkv6+PUw9XtAB/v2L3J+uKv+AcY5atiz/f42UoZzeQFlsHZE ku2K87rk3Rqs3RIrnkFFEbqVpYZ+SARZkLWEFH0VmQGKstIbAfJWfujYkaFER2UKtn2p zfKg== X-Gm-Message-State: AC+VfDzBmqYzJzS8ATjD+c5jQGrh+sXwW7hsqTqV/9bM53QdtLRzK6jr XfH2mxcrVHevpgX+E6wsCmQqFkjVk5m0 X-Google-Smtp-Source: ACHHUZ7M+koLA/Ia+fdnv+WBR7V4mfq9IowZ5DMaWuIoGfb9NIMwoa5UssIGW7+f/lEvCFDdeBHQIZHNM5Mp 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_162957_444011_5A6F6C70 X-CRM114-Status: GOOD ( 15.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel