From patchwork Fri Sep 2 19:11:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12964526 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E26CECAAD5 for ; Fri, 2 Sep 2022 19:12:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97250800E5; Fri, 2 Sep 2022 15:12:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 921FB800DD; Fri, 2 Sep 2022 15:12:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81073800E5; Fri, 2 Sep 2022 15:12:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 737AC800DD for ; Fri, 2 Sep 2022 15:12:06 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4D6D0140866 for ; Fri, 2 Sep 2022 19:12:06 +0000 (UTC) X-FDA: 79868090652.05.C07CE30 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf17.hostedemail.com (Postfix) with ESMTP id 047AF40053 for ; Fri, 2 Sep 2022 19:12:04 +0000 (UTC) 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 44E8962297; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662145925; a=rsa-sha256; cv=none; b=DIMa5y78knEdFH58OUAzdDJ3NTmEIdhuqC5vOc32Ed+pKCTsDp0DH7ur00r4OEqQhQAxYH 0rDB9jChs/e4r53ogZbDOi87RS2boCEYdfwFvCxCDUfThmv96ILMeFYau1eTVJYDRhPFOI BxLgkoV0Y+IJOyDmji91ncuZogznRDg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aBZGi0RY; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf17.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662145925; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=stGLoRZ0Kn+352eAJTm3/rSmVohHmPpUdZfAxNDRarA=; b=3+x2bi091YL0XcHX7q6ruBTibGNyD5wzzf1BtNRgW5Trjmc0j7El/uFSV6oOhi+qRioi5h F90k+BVTWw3b1+TE137SaYFlcgmLVuAv7LKpIzLJh6KEFMl0E1wpd+DtpyKfEuTa5udaOb sswEw+yRpSMFUAf+h0b9x5ZIhQFBoHc= X-Stat-Signature: iyemfuoojjyfwckc4b11r3wqb7o78iq7 X-Rspamd-Queue-Id: 047AF40053 Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aBZGi0RY; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf17.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org X-Rspam-User: X-Rspamd-Server: rspam02 X-HE-Tag: 1662145924-423813 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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,