Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp237634rwb; Fri, 2 Sep 2022 13:16:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR60y29+gC+eUdke43uf+fiU2E/8PqCrdpU2JQY/0usVyqb2HntcByLclqgrheATmMtN+7Wf X-Received: by 2002:a63:83c6:0:b0:42b:bb27:91a4 with SMTP id h189-20020a6383c6000000b0042bbb2791a4mr25280160pge.61.1662149760983; Fri, 02 Sep 2022 13:16:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662149760; cv=none; d=google.com; s=arc-20160816; b=r8d69N7TQ2VXQ0JRNdfz9EK2j9ERxo4f+hl585YVXbsIfNrkXNwIDP+3KDHFTsljGk 2CPbPelpyZ6phW9UkrCYuA60CPpKNCpS0ue0irKpJKgxgyqVYf2tQ/8EDekOJzumizCY A7/OMt1E+kd3ST7T/EXz0XkxUMPHVbQUVYOg6qxBsa+8vUtVyO8U7VakMPm1fs2An3zz +i3vFJQ4fU0kXIG6a7Hl60JtzYuFQABsaitgZAlRqgvcJqwyxlLKb3gYbRE/gPquldcr 0YtwQzTA1+2V5rbiV5uQ/ThTL1VZ7/gxDXYG0BMzdgLWmZYu0txqrEXRDXi6flo+Uy9A +seg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=stGLoRZ0Kn+352eAJTm3/rSmVohHmPpUdZfAxNDRarA=; b=mye4E/nZqNGvW1xeeqXs0Wrgw69RHpN2h4Zh7YsAs7+t7xy4lzqgm1JgSvbbDc5+FO OMtEnlXNltTL+YWsBWhN89fJhBp+NEYlUYZXiUBmkAJJFSyWNCjiddUAg0wq00uTE+l+ A9mBPyX+jKC3alWo4upWWgjKeZsS8M4bpFLbLsKYgKItJ/+XhCTrLWYkcejaJldN7sOa eA5SVIPiO37PSyDTqKevqYKaNpewch79djraGYbOreu8kS0PFC/QCbZFuhXsqZJBjZ3g n968dBmh6EQkbYwnpAOM0s4v8m3RKdpWv4O4C+EQ0ToWz1XMC9casUgu84mJCnRJoY08 UShQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aBZGi0RY; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i62-20020a638741000000b004305c6dec4fsi2823349pge.167.2022.09.02.13.15.48; Fri, 02 Sep 2022 13:16:00 -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=aBZGi0RY; 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 S230006AbiIBTMM (ORCPT + 99 others); Fri, 2 Sep 2022 15:12:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229751AbiIBTMJ (ORCPT ); Fri, 2 Sep 2022 15:12:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2FA6FBA4D; Fri, 2 Sep 2022 12:12:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 50EED6229E; Fri, 2 Sep 2022 19:12:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BDE9C433D6; Fri, 2 Sep 2022 19:12:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662145923; bh=rJDLXs4RxM5/uTreWGTpem458YPycLhkzqUiqONrjDY=; h=From:To:Cc:Subject:Date:From; b=aBZGi0RYXJahnjFCnOvAslff2adgx6/RpvP1D3sAHZhvIh2wnbv8h31jmgElsGIkW oBAGnyCCnF4EOlcsW1lqqVCUwFB7h5NiSJwfU9Dmi7d3wDLEjo2RNpSsXxOIzLGDeg SwD3jk1ueOHubNqwACGDGfCADYqtCIELrC2Ec9h8pr9K0M11otV6lL3Klu5njJ8Gk5 KC4RS86RroeG/sVkFwv1EHBP3Zf1iYX6vcAWp7sBARNc6aq7VFCpTkb4UCxYfMbqDN yOKwMMHl4qM42NW79eShU+czoiEfdsRVXa4VAhP7GAmaV98Ao+sxQAUAUsSeYwAIHE BDTPqYtALPA0Q== From: SeongJae Park To: akpm@linux-foundation.org Cc: sj@kernel.org, gregkh@linuxfoundation.org, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2] mm/damon/dbgfs: fix memory leak when using Date: Fri, 2 Sep 2022 19:11:49 +0000 Message-Id: <20220902191149.112434-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman debugfs_lookup() Date: Fri, 2 Sep 2022 14:56:31 +0200 [thread overview] Message-ID: <20220902125631.128329-1-gregkh@linuxfoundation.org> (raw) When calling debugfs_lookup() the result must have dput() called on it, otherwise the memory will leak over time. Fix this up by properly calling dput(). Fixes: 75c1c2b53c78b ("mm/damon/dbgfs: support multiple contexts") Cc: # 5.15.x Cc: SeongJae Park Cc: Andrew Morton Cc: damon@lists.linux.dev Cc: linux-mm@kvack.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Andrew Morton Signed-off-by: SeongJae Park --- Changes from v1 (https://lore.kernel.org/damon/20220902125631.128329-1-gregkh@linuxfoundation.org/) - Call dput() for failure-return case (Andrew Morton) mm/damon/dbgfs.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index 3b55a1b219b5..652a94deafe3 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -884,6 +884,7 @@ static int dbgfs_rm_context(char *name) struct dentry *root, *dir, **new_dirs; struct damon_ctx **new_ctxs; int i, j; + int ret = 0; if (damon_nr_running_ctxs()) return -EBUSY; @@ -898,14 +899,16 @@ static int dbgfs_rm_context(char *name) new_dirs = kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_dirs), GFP_KERNEL); - if (!new_dirs) - return -ENOMEM; + if (!new_dirs) { + ret = -ENOMEM; + goto out_dput; + } new_ctxs = kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_ctxs), GFP_KERNEL); if (!new_ctxs) { - kfree(new_dirs); - return -ENOMEM; + ret = -ENOMEM; + goto out_new_dirs; } for (i = 0, j = 0; i < dbgfs_nr_ctxs; i++) { @@ -925,7 +928,13 @@ static int dbgfs_rm_context(char *name) dbgfs_ctxs = new_ctxs; dbgfs_nr_ctxs--; - return 0; + goto out_dput; + +out_new_dirs: + kfree(new_dirs); +out_dput: + dput(dir); + return ret; } static ssize_t dbgfs_rm_context_write(struct file *file, -- 2.25.1